1 /**
2  * Copyright (c) 2006-2016 LOVE Development Team
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty.  In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  *    claim that you wrote the original software. If you use this software
14  *    in a product, an acknowledgment in the product documentation would be
15  *    appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  *    misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  **/
20 
21 #include "common/config.h"
22 
23 #include <algorithm>
24 
25 #include "Sound.h"
26 
27 #include "ModPlugDecoder.h"
28 #include "VorbisDecoder.h"
29 #include "GmeDecoder.h"
30 #include "WaveDecoder.h"
31 //#include "FLACDecoder.h"
32 
33 #ifndef LOVE_NOMPG123
34 #	include "Mpg123Decoder.h"
35 #endif // LOVE_NOMPG123
36 
37 #ifdef LOVE_SUPPORT_COREAUDIO
38 #	include "CoreAudioDecoder.h"
39 #endif
40 
41 namespace love
42 {
43 namespace sound
44 {
45 namespace lullaby
46 {
47 
Sound()48 Sound::Sound()
49 {
50 }
51 
~Sound()52 Sound::~Sound()
53 {
54 #ifndef LOVE_NOMPG123
55 	Mpg123Decoder::quit();
56 #endif // LOVE_NOMPG123
57 }
58 
getName() const59 const char *Sound::getName() const
60 {
61 	return "love.sound.lullaby";
62 }
63 
newDecoder(love::filesystem::FileData * data,int bufferSize)64 sound::Decoder *Sound::newDecoder(love::filesystem::FileData *data, int bufferSize)
65 {
66 	std::string ext = data->getExtension();
67 	std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
68 
69 	sound::Decoder *decoder = nullptr;
70 
71 	// Find a suitable decoder here, and return it.
72 	if (false)
73 		/* nothing */;
74 #ifndef LOVE_NO_MODPLUG
75 	else if (ModPlugDecoder::accepts(ext))
76 		decoder = new ModPlugDecoder(data, ext, bufferSize);
77 #endif // LOVE_NO_MODPLUG
78 #ifndef LOVE_NOMPG123
79 	else if (Mpg123Decoder::accepts(ext))
80 		decoder = new Mpg123Decoder(data, ext, bufferSize);
81 #endif // LOVE_NOMPG123
82 	else if (VorbisDecoder::accepts(ext))
83 		decoder = new VorbisDecoder(data, ext, bufferSize);
84 #ifdef LOVE_SUPPORT_GME
85 	else if (GmeDecoder::accepts(ext))
86 		decoder = new GmeDecoder(data, ext, bufferSize);
87 #endif // LOVE_SUPPORT_GME
88 #ifdef LOVE_SUPPORT_COREAUDIO
89 	else if (CoreAudioDecoder::accepts(ext))
90 		decoder = new CoreAudioDecoder(data, ext, bufferSize);
91 #endif
92 	else if (WaveDecoder::accepts(ext))
93 		decoder = new WaveDecoder(data, ext, bufferSize);
94 	/*else if (FLACDecoder::accepts(ext))
95 		decoder = new FLACDecoder(data, ext, bufferSize);*/
96 
97 	// else if (OtherDecoder::accept(ext))
98 
99 	return decoder;
100 }
101 
102 } // lullaby
103 } // sound
104 } // love
105