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 #ifndef LOVE_SOUND_SOUND_H
22 #define LOVE_SOUND_SOUND_H
23 
24 // LOVE
25 #include "common/Module.h"
26 #include "filesystem/File.h"
27 
28 #include "SoundData.h"
29 #include "Decoder.h"
30 
31 namespace love
32 {
33 namespace sound
34 {
35 
36 /**
37  * The Sound module is responsible for decoding sound data. It is
38  * not responsible for playing it.
39  **/
40 class Sound : public Module
41 {
42 
43 public:
44 
45 	virtual ~Sound();
46 
47 	// Implements Module.
getModuleType()48 	virtual ModuleType getModuleType() const { return M_SOUND; }
49 
50 	/**
51 	 * Creates new SoundData from a decoder. Fully expands the
52 	 * encoded sound data into raw sound data. Not recommended
53 	 * on large (long-duration) files.
54 	 * @param decoder The file to decode the data from.
55 	 * @return A SoundData object, or zero if the file type couldn't be handled.
56 	 **/
57 	SoundData *newSoundData(Decoder *decoder);
58 
59 	/**
60 	 * Creates a new SoundData with the specified number of samples and format.
61 	 * @param samples The number of samples.
62 	 * @param sampleRate Number of samples per second.
63 	 * @param bitDepth Bits per sample (8 or 16).
64 	 * @param channels Either 1 for mono, or 2 for stereo.
65 	 * @return A new SoundData object, or zero in case of errors.
66 	 **/
67 	SoundData *newSoundData(int samples, int sampleRate, int bitDepth, int channels);
68 
69 	/**
70 	 * Attempts to find a decoder for the encoded sound data in the
71 	 * specified file.
72 	 * @param file The file with encoded sound data.
73 	 * @param bufferSize The size of each decoded chunk.
74 	 * @return A Decoder object on success, or zero if no decoder could be found.
75 	 **/
76 	virtual Decoder *newDecoder(filesystem::FileData *file, int bufferSize) = 0;
77 
78 }; // Sound
79 
80 } // sound
81 } // love
82 
83 #endif // LOVE_SOUND_SOUND_H
84