126 } |
126 } |
127 |
127 |
128 |
128 |
129 int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) { |
129 int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) { |
130 /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */ |
130 /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */ |
131 FILE *oggFile; /*ogg handle*/ |
131 OggVorbis_File oggStream; /*stream handle*/ |
132 OggVorbis_File oggStream; /*stream handle*/ |
|
133 vorbis_info *vorbisInfo; /*some formatting data*/ |
132 vorbis_info *vorbisInfo; /*some formatting data*/ |
134 int64_t pcm_length; /*length of the decoded data*/ |
133 int64_t pcm_length; /*length of the decoded data*/ |
135 int section, result, size = 0; |
134 int section, result, size = 0; |
136 #ifdef DEBUG |
135 #ifdef DEBUG |
137 int i; |
136 int i; |
138 vorbis_comment *vorbisComment; /*other less useful data*/ |
137 vorbis_comment *vorbisComment; /*other less useful data*/ |
139 #endif |
138 #endif |
140 |
139 |
141 oggFile = Fopen(filename, "rb"); |
140 result = ov_fopen((char*) filename, &oggStream); |
142 result = ov_open_callbacks(oggFile, &oggStream, NULL, 0, NULL); |
|
143 if (result < 0) { |
141 if (result < 0) { |
144 fprintf (stderr, "ERROR: ov_open_callbacks failed with %X", result) |
142 fprintf (stderr, "ERROR: ov_open_callbacks failed with %X", result); |
145 fclose(oggFile); |
143 ov_clear(&oggStream); |
146 return -1; |
144 return -1; |
147 } |
145 } |
148 |
146 |
149 vorbisInfo = ov_info(&oggStream, -1); |
147 vorbisInfo = ov_info(&oggStream, -1); |
150 pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels; |
148 pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels; |
175 if (vorbisInfo->channels == 2) |
173 if (vorbisInfo->channels == 2) |
176 *format = AL_FORMAT_STEREO16; |
174 *format = AL_FORMAT_STEREO16; |
177 else { |
175 else { |
178 fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels); |
176 fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels); |
179 ov_clear(&oggStream); |
177 ov_clear(&oggStream); |
180 fclose(oggFile); |
|
181 return AL_FALSE; |
178 return AL_FALSE; |
182 } |
179 } |
183 } |
180 } |
184 |
181 |
185 while (size < pcm_length) { |
182 while (size < pcm_length) { |