38
|
1
|
|
2 /*
|
|
3 * This is a wrapper interface that tries to provide a similar
|
|
4 * front-end interface to SDL_sound.
|
|
5 */
|
|
6
|
|
7 #ifndef SOUNDDECODER_H
|
|
8 #define SOUNDDECODER_H
|
|
9
|
|
10 #ifdef __cplusplus
|
|
11 extern "C" {
|
|
12 #endif
|
|
13
|
|
14
|
|
15 #include <stdint.h>
|
|
16 #include <stddef.h>
|
|
17
|
|
18 #include "al.h" /* OpenAL */
|
|
19
|
|
20 /* Compatibility defines for SDL */
|
|
21 #define AUDIO_U8 0x0008
|
|
22 #define AUDIO_S8 0x8008
|
|
23 #define AUDIO_U16LSB 0x0010
|
|
24 #define AUDIO_S16LSB 0x8010
|
|
25 #define AUDIO_U16MSB 0x1010
|
|
26 #define AUDIO_S16MSB 0x9010
|
|
27 #define AUDIO_U16 AUDIO_U16LSB
|
|
28 #define AUDIO_S16 AUDIO_S16LSB
|
|
29
|
|
30 #ifdef ANDROID_NDK
|
|
31 #include <endian.h>
|
|
32 #if _BYTE_ORDER == _BIG_ENDIAN
|
|
33 #define __BIG_ENDIAN__ 1
|
|
34 #elif _BYTE_ORDER == _LITTLE_ENDIAN
|
|
35 #define __LITTLE_ENDIAN__ 1
|
|
36 #else
|
|
37 #warning "Android falling back to __LITTLE_ENDIAN__"
|
|
38 #define __LITTLE_ENDIAN__ 1
|
|
39 #endif
|
|
40 #endif
|
|
41
|
|
42 #if __BIG_ENDIAN__
|
|
43 #warning "Using __BIG_ENDIAN__"
|
|
44 #define AUDIO_U16SYS AUDIO_U16MSB
|
|
45 #define AUDIO_S16SYS AUDIO_S16MSB
|
|
46 #elif __LITTLE_ENDIAN__
|
|
47 #define AUDIO_U16SYS AUDIO_U16LSB
|
|
48 #define AUDIO_S16SYS AUDIO_S16LSB
|
|
49 #else
|
|
50 #warning "Using __LITTLE_ENDIAN__ as fallback"
|
|
51 #define AUDIO_U16SYS AUDIO_U16LSB
|
|
52 #define AUDIO_S16SYS AUDIO_S16LSB
|
|
53 #endif
|
|
54
|
|
55 struct ALmixer_RWops;
|
|
56
|
|
57 typedef enum
|
|
58 {
|
|
59 SOUND_SAMPLEFLAG_NONE = 0,
|
|
60 SOUND_SAMPLEFLAG_CANSEEK = 1,
|
|
61 SOUND_SAMPLEFLAG_EOF = 1 << 29,
|
|
62 SOUND_SAMPLEFLAG_ERROR = 1 << 30,
|
|
63 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31
|
|
64 } SoundDecoder_SampleFlags;
|
|
65
|
|
66 #define Sound_SampleFlags SoundDecoder_SampleFlags;
|
|
67
|
|
68 typedef struct SoundDecoder_AudioInfo
|
|
69 {
|
|
70 //uint16_t format; /**< Equivalent of SDL_AudioSpec.format. */
|
|
71 ALushort format; /**< Equivalent of SDL_AudioSpec.format. */
|
|
72 ALubyte channels;
|
|
73 // uint8_t channels;
|
|
74 //uint32_t rate;
|
|
75 ALuint rate;
|
|
76 } SoundDecoder_AudioInfo;
|
|
77
|
|
78 //#define Sound_AudioInfo SoundDecoder_AudioInfo;
|
|
79 typedef struct SoundDecoder_AudioInfo Sound_AudioInfo;
|
|
80
|
|
81
|
|
82
|
|
83 typedef struct SoundDecoder_DecoderInfo
|
|
84 {
|
|
85 const char** extensions;
|
|
86 const char* description;
|
|
87 const char* author;
|
|
88 const char* url;
|
|
89 } SoundDecoder_DecoderInfo;
|
|
90
|
|
91 //#define Sound_DecoderInfo SoundDecoder_DecoderInfo;
|
|
92 typedef struct SoundDecoder_DecoderInfo Sound_DecoderInfo;
|
|
93
|
|
94
|
|
95
|
|
96 typedef struct SoundDecoder_Sample
|
|
97 {
|
|
98 void* opaque;
|
|
99 const SoundDecoder_DecoderInfo* decoder;
|
|
100 SoundDecoder_AudioInfo desired;
|
|
101 SoundDecoder_AudioInfo actual;
|
|
102 void *buffer;
|
|
103 size_t buffer_size;
|
|
104 SoundDecoder_SampleFlags flags;
|
|
105 } SoundDecoder_Sample;
|
|
106
|
|
107 //#define Sound_Sample SoundDecoder_Sample;
|
|
108 typedef struct SoundDecoder_Sample Sound_Sample;
|
|
109
|
|
110
|
|
111 typedef struct SoundDecoder_Version
|
|
112 {
|
|
113 int major;
|
|
114 int minor;
|
|
115 int patch;
|
|
116 } SoundDecoder_Version;
|
|
117
|
|
118 //#define Sound_Version SoundDecoder_Version;
|
|
119 typedef struct SoundDecoder_Version Sound_Version;
|
|
120
|
|
121
|
|
122 #define SOUNDDECODER_VER_MAJOR 0
|
|
123 #define SOUNDDECODER_VER_MINOR 0
|
|
124 #define SOUNDDECODER_VER_PATCH 1
|
|
125
|
|
126 #define SOUNDDECODER_VERSION(x) \
|
|
127 { \
|
|
128 (x)->major = SOUNDDECODER_VER_MAJOR; \
|
|
129 (x)->minor = SOUNDDECODER_VER_MINOR; \
|
|
130 (x)->patch = SOUNDDECODER_VER_PATCH; \
|
|
131 }
|
|
132
|
|
133 #define SOUND_VERSION SOUNDDECODER_VERSION
|
|
134
|
|
135 void SoundDecoder_GetLinkedVersion(SoundDecoder_Version *ver);
|
|
136 #define Sound_GetLinkedVersion SoundDecoder_GetLinkedVersion
|
|
137
|
|
138 int SoundDecoder_Init(void);
|
|
139 #define Sound_Init SoundDecoder_Init
|
|
140
|
|
141 void SoundDecoder_Quit(void);
|
|
142 #define Sound_Quit SoundDecoder_Quit
|
|
143
|
|
144
|
|
145 const SoundDecoder_DecoderInfo** SoundDecoder_AvailableDecoders(void);
|
|
146 #define Sound_AvailableDecoders SoundDecoder_AvailableDecoders
|
|
147
|
|
148
|
|
149 const char* SoundDecoder_GetError(void);
|
|
150 #define Sound_GetError SoundDecoder_GetError
|
|
151
|
|
152
|
|
153 void SoundDecoder_ClearError(void);
|
|
154 #define Sound_ClearError SoundDecoder_ClearError
|
|
155
|
|
156
|
|
157
|
|
158 SoundDecoder_Sample* SoundDecoder_NewSample(
|
|
159 struct ALmixer_RWops* rw_ops,
|
|
160 const char* ext,
|
|
161 SoundDecoder_AudioInfo* desired,
|
|
162 size_t buffer_size);
|
|
163 #define Sound_NewSample SoundDecoder_NewSample
|
|
164
|
|
165 SoundDecoder_Sample* SoundDecoder_NewSampleFromFile(const char* file_name,
|
|
166 SoundDecoder_AudioInfo* desired,
|
|
167 size_t bufferSize);
|
|
168 #define Sound_NewSampleFromFile SoundDecoder_NewSampleFromFile
|
|
169
|
|
170
|
|
171 void SoundDecoder_FreeSample(SoundDecoder_Sample* sound_sample);
|
|
172 #define Sound_FreeSample SoundDecoder_FreeSample
|
|
173
|
|
174
|
|
175 ptrdiff_t SoundDecoder_GetDuration(SoundDecoder_Sample* sound_sample);
|
|
176 #define Sound_GetDuration SoundDecoder_GetDuration
|
|
177
|
|
178 int SoundDecoder_SetBufferSize(SoundDecoder_Sample* sound_sample, size_t new_buffer_size);
|
|
179 #define Sound_SetBufferSize SoundDecoder_SetBufferSize
|
|
180
|
|
181 size_t SoundDecoder_Decode(SoundDecoder_Sample* sound_sample);
|
|
182 #define Sound_Decode SoundDecoder_Decode
|
|
183
|
|
184 size_t SoundDecoder_DecodeAll(SoundDecoder_Sample* sound_sample);
|
|
185 #define Sound_DecodeAll SoundDecoder_DecodeAll
|
|
186
|
|
187 int SoundDecoder_Rewind(SoundDecoder_Sample* sound_sample);
|
|
188 #define Sound_Rewind SoundDecoder_Rewind
|
|
189
|
|
190 int SoundDecoder_Seek(SoundDecoder_Sample* sound_sample, size_t ms);
|
|
191 #define Sound_Seek SoundDecoder_Seek
|
|
192
|
|
193
|
|
194 /* Ends C function definitions when using C++ */
|
|
195 #ifdef __cplusplus
|
|
196 }
|
|
197 #endif
|
|
198
|
|
199 #endif
|
|
200
|