annotate Isolated/SoundDecoder.c @ 55:8b4f80233969

merged
author Eric Wing <ewing@anscamobile.com>
date Tue, 29 May 2012 19:41:59 -0700
parents 71b465ff0622
children 5c9eaf0cc385
rev   line source
38
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
1 #ifndef ALMIXER_COMPILED_WITH_SDL
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
2
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
3 #include "SoundDecoder.h"
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
4 #include "SoundDecoder_Internal.h"
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
5 #include "tErrorLib.h"
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
6 #include "LinkedList.h"
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
7 #include <stdlib.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
8 #include <string.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
9 #include <assert.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
10
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
11 #ifdef ANDROID_NDK
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
12 #include <android/log.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
13 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
14
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
15 /* A partial shim reimplementation of SDL_sound to work around the LGPL issues.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
16 * This implementation is more limited than SDL_sound.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
17 * For example, there is no generic software conversion routines.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
18 * Functions are also not necessarily thread safe.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
19 * This implementation relies on the back-end decoder much more heavily
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
20 * than SDL_sound. (For example, I bypass the internal->buffer.)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
21 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
22
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
23 static LinkedList* s_listOfLoadedSamples = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
24
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
25 static signed char s_isInitialized = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
26 static TErrorPool* s_errorPool = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
27
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
28 static const SoundDecoder_DecoderInfo** s_availableDecoders = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
29
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
30 #ifdef __APPLE__
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
31 //extern const SoundDecoder_DecoderFunctions __SoundDecoder_DecoderFunctions_CoreAudio;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
32 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
33 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
34 #ifdef ANDROID_NDK
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
35 #ifdef SOUND_SUPPORTS_WAV
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
36 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
37 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
38 #ifdef SOUND_SUPPORTS_MPG123
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
39 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MPG123;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
40 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
41 #ifdef SOUND_SUPPORTS_OGG
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
42 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
43 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
44 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
45
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
46 typedef struct
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
47 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
48 int available;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
49 const SoundDecoder_DecoderFunctions* funcs;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
50 } SoundElement;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
51
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
52 static SoundElement s_linkedDecoders[] =
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
53 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
54 #if defined(__APPLE__)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
55 { 0, &__Sound_DecoderFunctions_CoreAudio },
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
56 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
57 #if defined(ANDROID_NDK)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
58 #ifdef SOUND_SUPPORTS_WAV
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
59 { 0, &__Sound_DecoderFunctions_WAV },
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
60 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
61 #ifdef SOUND_SUPPORTS_MPG123
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
62 { 0, &__Sound_DecoderFunctions_MPG123 },
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
63 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
64 #ifdef SOUND_SUPPORTS_OGG
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
65 { 0, &__Sound_DecoderFunctions_OGG },
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
66 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
67 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
68 { 0, NULL }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
69 };
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
70
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
71
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
72 #include <ctype.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
73 int SoundDecoder_strcasecmp(const char* str1, const char* str2)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
74 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
75 int the_char1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
76 int the_char2;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
77 int i = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
78 if(str1 == str2)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
79 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
80 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
81 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
82 if(NULL == str1)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
83 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
84 return -1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
85 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
86 if(NULL == str2)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
87 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
88 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
89 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
90
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
91 do
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
92 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
93 the_char1 = tolower(str1[i]);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
94 the_char2 = tolower(str2[i]);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
95 if(the_char1 < the_char2)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
96 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
97 return -1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
98 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
99 else if(the_char1 > the_char2)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
100 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
101 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
102 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
103 i++;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
104 } while( (0 != the_char1) && (0 != the_char2) );
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
105
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
106 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
107 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
108
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
109
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
110 #ifdef ANDROID_NDK
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
111 #include <stdarg.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
112 #include <android/log.h>
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
113 int SoundDecoder_DebugPrint(const char* format, ...)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
114 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
115 va_list arg_list;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
116 int ret_val;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
117
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
118 va_start(arg_list, format);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
119 ret_val = __android_log_vprint(ANDROID_LOG_INFO, "SoundDecoder", format, arg_list);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
120 va_end(arg_list);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
121 return ret_val;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
122 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
123 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
124
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
125 const char* SoundDecoder_GetError()
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
126 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
127 const char* error_string = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
128 if(NULL == s_errorPool)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
129 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
130 return "Error: You should not call SoundDecoder_GetError while Sound is not initialized";
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
131 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
132 error_string = TError_GetLastErrorStr(s_errorPool);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
133 /* SDL returns empty strings instead of NULL */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
134 if(NULL == error_string)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
135 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
136 return "";
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
137 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
138 else
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
139 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
140 return error_string;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
141 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
142 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
143
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
144 void SoundDecoder_ClearError()
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
145 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
146 if(NULL == s_errorPool)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
147 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
148 return;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
149 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
150 TError_SetError(s_errorPool, 0, NULL);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
151 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
152
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
153 void SoundDecoder_SetError(const char* err_str, ...)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
154 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
155 if(NULL == s_errorPool)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
156 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
157 fprintf(stderr, "Error: You should not call SoundDecoder_SetError while Sound is not initialized\n");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
158 return;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
159 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
160 va_list argp;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
161 va_start(argp, err_str);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
162 // SDL_SetError which I'm emulating has no number parameter.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
163 TError_SetErrorv(s_errorPool, 1, err_str, argp);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
164 va_end(argp);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
165 #ifdef ANDROID_NDK
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
166 __android_log_print(ANDROID_LOG_INFO, "SoundDecoder_SetError", TError_GetLastErrorStr(s_errorPool));
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
167 #endif
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
168 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
169
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
170
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
171 void SoundDecoder_GetLinkedVersion(SoundDecoder_Version* the_version)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
172 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
173 if(NULL != the_version)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
174 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
175 the_version->major = SOUNDDECODER_VER_MAJOR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
176 the_version->minor = SOUNDDECODER_VER_MINOR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
177 the_version->patch = SOUNDDECODER_VER_PATCH;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
178 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
179 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
180
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
181
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
182 const SoundDecoder_DecoderInfo** SoundDecoder_AvailableDecoders()
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
183 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
184 return(s_availableDecoders);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
185 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
186
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
187 int SoundDecoder_Init()
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
188 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
189 size_t total_number_of_decoders;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
190 size_t i;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
191 size_t current_pos = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
192 if(1 == s_isInitialized)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
193 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
194 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
195 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
196 if(NULL == s_errorPool)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
197 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
198 s_errorPool = TError_CreateErrorPool();
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
199 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
200 if(NULL == s_errorPool)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
201 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
202 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
203 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
204
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
205 total_number_of_decoders = sizeof(s_linkedDecoders) / sizeof(s_linkedDecoders[0]);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
206 s_availableDecoders = (const SoundDecoder_DecoderInfo **)malloc((total_number_of_decoders) * sizeof(SoundDecoder_DecoderInfo*));
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
207 if(NULL == s_availableDecoders)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
208 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
209 SoundDecoder_SetError(ERR_OUT_OF_MEMORY);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
210 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
211 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
212
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
213 /* Allocate memory for linked list of sound samples. */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
214 s_listOfLoadedSamples = LinkedList_Create();
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
215 if(NULL == s_listOfLoadedSamples)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
216 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
217 free(s_availableDecoders);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
218 s_availableDecoders = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
219 SoundDecoder_SetError(ERR_OUT_OF_MEMORY);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
220 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
221 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
222
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
223 for(i = 0; s_linkedDecoders[i].funcs != NULL; i++)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
224 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
225 s_linkedDecoders[i].available = s_linkedDecoders[i].funcs->init();
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
226 if(s_linkedDecoders[i].available)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
227 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
228 s_availableDecoders[current_pos] = &(s_linkedDecoders[i].funcs->info);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
229 current_pos++;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
230 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
231 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
232
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
233 s_availableDecoders[current_pos] = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
234 s_isInitialized = 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
235 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
236 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
237
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
238 void SoundDecoder_Quit()
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
239 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
240 size_t i;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
241 if(0 == s_isInitialized)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
242 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
243 return;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
244 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
245
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
246 /*
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
247 * SDL_sound actually embeds the linked list in the internal data structure.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
248 * So any sample can potentially reach any other sample.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
249 * But I'm keeping my own separate list.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
250 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
251 while(LinkedList_Size(s_listOfLoadedSamples) > 0)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
252 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
253 SoundDecoder_Sample* sound_sample = (SoundDecoder_Sample*)LinkedList_PopBack(s_listOfLoadedSamples);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
254 SoundDecoder_FreeSample(sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
255 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
256 LinkedList_Free(s_listOfLoadedSamples);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
257 s_listOfLoadedSamples = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
258
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
259
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
260 for(i = 0; s_linkedDecoders[i].funcs != NULL; i++)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
261 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
262 if (s_linkedDecoders[i].available)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
263 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
264 s_linkedDecoders[i].funcs->quit();
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
265 s_linkedDecoders[i].available = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
266 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
267 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
268
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
269 if(NULL != s_availableDecoders)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
270 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
271 free(s_availableDecoders);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
272 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
273 s_availableDecoders = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
274
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
275
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
276 /* Remember: ALmixer_SetError/GetError calls will not work while this is gone. */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
277 TError_FreeErrorPool(s_errorPool);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
278 s_errorPool = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
279
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
280 s_isInitialized = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
281 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
282
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
283
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
284 void SoundDecoder_FreeSample(SoundDecoder_Sample* sound_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
285 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
286 SoundDecoder_SampleInternal* sample_internal;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
287
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
288 /* Quit unloads all samples, so it is not possible to free a sample
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
289 * when not initialized.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
290 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
291 if(0 == s_isInitialized)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
292 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
293 return;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
294 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
295
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
296 if(sound_sample == NULL)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
297 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
298 return;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
299 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
300
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
301 /* SDL_sound keeps a linked list of all the loaded samples.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
302 * We want to remove the current sample from that list.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
303 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
304 LinkedListNode* the_node = LinkedList_Find(s_listOfLoadedSamples, sound_sample, NULL);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
305 if(NULL == the_node)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
306 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
307 SoundDecoder_SetError("SoundDecoder_FreeSample: Internal Error, sample does not exist in linked list.");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
308 return;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
309 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
310 LinkedList_Remove(s_listOfLoadedSamples, the_node);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
311
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
312 sample_internal = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
313
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
314 /* Ugh...SDL_sound has a lot of pointers.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
315 * I hope I didn't miss any dynamic memory.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
316 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
317
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
318 /* Call close on the decoder */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
319 sample_internal->funcs->close(sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
320
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
321 if(NULL != sample_internal->rw)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
322 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
323 sample_internal->rw->close(sample_internal->rw);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
324 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
325
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
326 /* Ooops. The public buffer might be shared with the internal buffer.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
327 * Make sure to not accidentally double delete.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
328 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
329 if((NULL != sample_internal->buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
330 && (sample_internal->buffer != sound_sample->buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
331 )
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
332 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
333 free(sample_internal->buffer);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
334 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
335 free(sample_internal);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
336
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
337 if(NULL != sound_sample->buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
338 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
339 free(sound_sample->buffer);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
340 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
341 free(sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
342 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
343
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
344
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
345
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
346 static int Internal_LoadSample(const SoundDecoder_DecoderFunctions *funcs,
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
347 SoundDecoder_Sample* sound_sample, const char *ext
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
348 )
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
349 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
350 SoundDecoder_SampleInternal* internal_sample = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
351 long current_file_position = internal_sample->rw->seek(internal_sample->rw, 0, SEEK_CUR);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
352
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
353 /* fill in the funcs for this decoder... */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
354 sound_sample->decoder = &funcs->info;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
355 internal_sample->funcs = funcs;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
356 if (!funcs->open(sound_sample, ext))
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
357 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
358 internal_sample->rw->seek(internal_sample->rw, current_file_position, SEEK_SET);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
359 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
360 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
361
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
362 /* we found a compatible decoder */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
363
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
364 /* SDL_sound normally goes on to setup a bunch of things to
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
365 * support format conversion via SDL APIs.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
366 * I am not porting any of that stuff.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
367 * My goal is to simply setup the struct properties to values
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
368 * that will not cause any confusion with other parts of the implementation.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
369 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
370
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
371
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
372 if(0 == sound_sample->desired.format)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
373 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
374 sound_sample->desired.format = sound_sample->actual.format;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
375 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
376 if(0 == sound_sample->desired.channels)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
377 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
378 sound_sample->desired.channels = sound_sample->actual.channels;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
379 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
380 if(0 == sound_sample->desired.rate)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
381 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
382 sound_sample->desired.rate = sound_sample->actual.rate;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
383 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
384
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
385 /* I'm a little confused at the difference between the internal
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
386 * public buffer. I am going to make them the same.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
387 * I assume I already allocated the public buffer.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
388 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
389 internal_sample->buffer = sound_sample->buffer;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
390 internal_sample->buffer_size = sound_sample->buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
391
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
392 /* Insert the new sample into the linked list of samples. */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
393 LinkedList_PushBack(s_listOfLoadedSamples, sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
394
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
395 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
396 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
397
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
398
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
399
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
400 SoundDecoder_Sample* SoundDecoder_NewSampleFromFile(const char* file_name,
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
401 SoundDecoder_AudioInfo* desired_format,
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
402 size_t buffer_size)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
403 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
404
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
405 const char* file_extension;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
406 ALmixer_RWops* rw_ops;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
407
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
408
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
409 if(0 == s_isInitialized)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
410 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
411 SoundDecoder_SetError(ERR_NOT_INITIALIZED);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
412 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
413 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
414 if(NULL == file_name)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
415 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
416 SoundDecoder_SetError("No file specified");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
417 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
418 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
419
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
420 file_extension = strrchr(file_name, '.');
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
421 if(NULL != file_extension)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
422 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
423 file_extension++;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
424 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
425
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
426 rw_ops = ALmixer_RWFromFile(file_name, "rb");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
427
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
428 return SoundDecoder_NewSample(rw_ops, file_extension, desired_format, buffer_size);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
429 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
430
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
431
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
432 SoundDecoder_Sample* SoundDecoder_NewSample(ALmixer_RWops* rw_ops, const char* file_extension, SoundDecoder_AudioInfo* desired_format, size_t buffer_size)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
433 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
434 SoundDecoder_Sample* new_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
435 SoundDecoder_SampleInternal* internal_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
436 SoundElement* current_decoder;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
437
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
438 if(0 == s_isInitialized)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
439 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
440 SoundDecoder_SetError(ERR_NOT_INITIALIZED);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
441 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
442 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
443 if(NULL == rw_ops)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
444 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
445 SoundDecoder_SetError("No file specified");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
446 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
447 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
448
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
449 new_sample = (SoundDecoder_Sample*)calloc(1, sizeof(SoundDecoder_Sample));
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
450 if(NULL == new_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
451 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
452 SoundDecoder_SetError(ERR_OUT_OF_MEMORY);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
453 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
454 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
455 internal_sample = (SoundDecoder_SampleInternal*)calloc(1, sizeof(SoundDecoder_SampleInternal));
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
456 if(NULL == internal_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
457 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
458 free(new_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
459 SoundDecoder_SetError(ERR_OUT_OF_MEMORY);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
460 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
461 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
462 new_sample->buffer = calloc(1, buffer_size);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
463 if(NULL == new_sample->buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
464 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
465 free(internal_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
466 free(new_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
467 SoundDecoder_SetError(ERR_OUT_OF_MEMORY);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
468 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
469 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
470
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
471 new_sample->buffer_size = buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
472
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
473 if(NULL != desired_format)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
474 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
475 memcpy(&new_sample->desired, desired_format, sizeof(SoundDecoder_AudioInfo));
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
476 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
477
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
478 internal_sample->rw = rw_ops;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
479 new_sample->opaque = internal_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
480
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
481
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
482 if(NULL != file_extension)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
483 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
484 for(current_decoder = &s_linkedDecoders[0]; current_decoder->funcs != NULL; current_decoder++)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
485 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
486 if(current_decoder->available)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
487 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
488 const char** decoder_file_extension = current_decoder->funcs->info.extensions;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
489 while(*decoder_file_extension)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
490 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
491 if(0 == (SoundDecoder_strcasecmp(*decoder_file_extension, file_extension)))
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
492 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
493 if(Internal_LoadSample(current_decoder->funcs, new_sample, file_extension))
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
494 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
495 return(new_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
496 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
497 break; /* go to the next decoder */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
498 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
499 decoder_file_extension++;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
500 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
501 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
502 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
503 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
504
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
505 /* no direct file_extensionension match? Try everything we've got... */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
506 for(current_decoder = &s_linkedDecoders[0]; current_decoder->funcs != NULL; current_decoder++)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
507 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
508 if(current_decoder->available)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
509 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
510 int already_tried_decoder = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
511 const char** decoder_file_extension = current_decoder->funcs->info.extensions;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
512
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
513 /* skip decoders we already tried from the above loop */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
514 while(*decoder_file_extension)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
515 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
516 if(SoundDecoder_strcasecmp(*decoder_file_extension, file_extension) == 0)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
517 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
518 already_tried_decoder = 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
519 break;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
520 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
521 decoder_file_extension++;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
522 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
523
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
524 if(0 == already_tried_decoder)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
525 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
526 if (Internal_LoadSample(current_decoder->funcs, new_sample, file_extension))
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
527 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
528 return new_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
529 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
530 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
531 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
532 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
533
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
534 /* could not find a decoder */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
535 SoundDecoder_SetError(ERR_UNSUPPORTED_FORMAT);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
536 /* clean up the memory */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
537 free(new_sample->opaque);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
538 if(NULL != new_sample->buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
539 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
540 free(new_sample->buffer);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
541 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
542 free(new_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
543
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
544 rw_ops->close(rw_ops);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
545 return NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
546 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
547
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
548
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
549 int SoundDecoder_SetBufferSize(SoundDecoder_Sample* sound_sample, size_t new_buffer_size)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
550 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
551 SoundDecoder_SampleInternal* internal_sample = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
552 void* new_buffer_ptr = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
553
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
554 BAIL_IF_MACRO(!s_isInitialized, ERR_NOT_INITIALIZED, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
555 BAIL_IF_MACRO(NULL == sound_sample, ERR_NULL_SAMPLE, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
556
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
557 internal_sample = ((SoundDecoder_SampleInternal*)sound_sample->opaque);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
558
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
559
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
560 new_buffer_ptr = realloc(sound_sample->buffer, new_buffer_size);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
561 BAIL_IF_MACRO(NULL == new_buffer_ptr, ERR_OUT_OF_MEMORY, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
562
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
563 sound_sample->buffer = new_buffer_ptr;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
564 sound_sample->buffer_size = new_buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
565 internal_sample->buffer = sound_sample->buffer;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
566 internal_sample->buffer_size = sound_sample->buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
567
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
568 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
569 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
570
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
571
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
572 size_t SoundDecoder_Decode(SoundDecoder_Sample* sound_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
573 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
574 SoundDecoder_SampleInternal* internal_sample = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
575 size_t bytes_read = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
576
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
577 BAIL_IF_MACRO(!s_isInitialized, ERR_NOT_INITIALIZED, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
578 BAIL_IF_MACRO(NULL == sound_sample, ERR_NULL_SAMPLE, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
579 BAIL_IF_MACRO(sound_sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREVIOUS_SAMPLE_ERROR, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
580 BAIL_IF_MACRO(sound_sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_ALREADY_AT_EOF_ERROR, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
581
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
582 internal_sample = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
583
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
584 assert(sound_sample->buffer != NULL);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
585 assert(sound_sample->buffer_size > 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
586 assert(internal_sample->buffer != NULL);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
587 assert(internal_sample->buffer_size > 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
588
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
589 /* reset EAGAIN. Decoder can flip it back on if it needs to. */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
590 sound_sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
591 bytes_read = internal_sample->funcs->read(sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
592 return bytes_read;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
593 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
594
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
595
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
596 size_t SoundDecoder_DecodeAll(SoundDecoder_Sample* sound_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
597 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
598 SoundDecoder_SampleInternal* internal_sample = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
599 void* data_buffer = NULL;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
600 size_t updated_buffer_size = 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
601
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
602 BAIL_IF_MACRO(!s_isInitialized, ERR_NOT_INITIALIZED, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
603 BAIL_IF_MACRO(NULL == sound_sample, ERR_NULL_SAMPLE, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
604
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
605 /* My original thought was to call SetBufferSize and resize to
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
606 * the size needed to hold the entire decoded file utilizing total_time,
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
607 * but it appears SDL_sound simply loops on SoundDecoder_Decode.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
608 * I suppose it is possible to partially decode or seek a file, and then
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
609 * call DecodeAll so you won't have the whole thing in which case
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
610 * my idea would waste memory.
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
611 */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
612 while( (0 == (sound_sample->flags & SOUND_SAMPLEFLAG_EOF) )
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
613 && (0 == (sound_sample->flags & SOUND_SAMPLEFLAG_ERROR))
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
614 )
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
615 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
616 size_t bytes_decoded = SoundDecoder_Decode(sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
617 void* realloced_ptr = realloc(data_buffer, updated_buffer_size + bytes_decoded);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
618 if(NULL == realloced_ptr)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
619 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
620 sound_sample->flags |= SOUND_SAMPLEFLAG_ERROR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
621 SoundDecoder_SetError(ERR_OUT_OF_MEMORY);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
622 if(NULL != data_buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
623 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
624 free(data_buffer);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
625 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
626 return bytes_decoded;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
627 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
628 data_buffer = realloced_ptr;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
629 /* copy the chunk of decoded PCM to the end of our new data buffer */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
630 memcpy( ((char*)data_buffer) + updated_buffer_size, sound_sample->buffer, bytes_decoded );
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
631 updated_buffer_size += bytes_decoded;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
632 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
633
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
634 internal_sample = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
635 if(internal_sample->buffer != sound_sample->buffer)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
636 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
637 free(internal_sample->buffer);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
638 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
639 free(sound_sample->buffer);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
640
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
641 sound_sample->buffer = data_buffer;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
642 sound_sample->buffer_size = updated_buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
643 internal_sample->buffer = sound_sample->buffer;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
644 internal_sample->buffer_size = sound_sample->buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
645
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
646 return sound_sample->buffer_size;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
647 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
648
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
649
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
650 int SoundDecoder_Rewind(SoundDecoder_Sample* sound_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
651 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
652 SoundDecoder_SampleInternal* internal_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
653 int ret_val;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
654
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
655 BAIL_IF_MACRO(!s_isInitialized, ERR_NOT_INITIALIZED, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
656 BAIL_IF_MACRO(NULL == sound_sample, ERR_NULL_SAMPLE, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
657
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
658 internal_sample = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
659 ret_val = internal_sample->funcs->rewind(sound_sample);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
660 if(0 == ret_val)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
661 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
662 sound_sample->flags |= SOUND_SAMPLEFLAG_ERROR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
663 SoundDecoder_SetError("Rewind failed");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
664 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
665 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
666 /* reset flags */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
667 sound_sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
668 sound_sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
669 sound_sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
670
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
671 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
672 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
673
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
674
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
675 int SoundDecoder_Seek(SoundDecoder_Sample* sound_sample, size_t ms)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
676 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
677 SoundDecoder_SampleInternal* internal_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
678 int ret_val;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
679
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
680 BAIL_IF_MACRO(!s_isInitialized, ERR_NOT_INITIALIZED, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
681 BAIL_IF_MACRO(NULL == sound_sample, ERR_NULL_SAMPLE, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
682
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
683 BAIL_IF_MACRO(!(sound_sample->flags & SOUND_SAMPLEFLAG_CANSEEK), "Sound sample is not seekable", 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
684
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
685 internal_sample = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
686 ret_val = internal_sample->funcs->seek(sound_sample, ms);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
687 if(0 == ret_val)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
688 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
689 sound_sample->flags |= SOUND_SAMPLEFLAG_ERROR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
690 SoundDecoder_SetError("Seek failed");
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
691 return 0;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
692 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
693 /* reset flags */
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
694 sound_sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
695 sound_sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
696 sound_sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
697
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
698 return 1;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
699 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
700
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
701
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
702 ptrdiff_t SoundDecoder_GetDuration(SoundDecoder_Sample* sound_sample)
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
703 {
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
704 SoundDecoder_SampleInternal* internal_sample;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
705 BAIL_IF_MACRO(!s_isInitialized, ERR_NOT_INITIALIZED, -1);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
706 BAIL_IF_MACRO(NULL == sound_sample, ERR_NULL_SAMPLE, 0);
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
707 internal_sample = (SoundDecoder_SampleInternal*)sound_sample->opaque;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
708 return internal_sample->total_time;
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
709 }
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
710
71b465ff0622 Added support files.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
711 #endif