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