openalbridge/loaders.c
changeset 2260 31756e21c436
parent 2259 ca42efdce3ce
child 2265 eae64600fb69
equal deleted inserted replaced
2259:ca42efdce3ce 2260:31756e21c436
   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         FILE		*oggFile;		/*ogg handle*/
   132         OggVorbis_File  oggStream;		/*stream handle*/
   132         OggVorbis_File  oggStream;		/*stream handle*/
   133         vorbis_info	*vorbisInfo;	/*some formatting data*/
   133         vorbis_info	*vorbisInfo;	/*some formatting data*/
   134         int64_t		pcm_length;		/*length of the decoded data*/
   134         int64_t		pcm_length;		/*length of the decoded data*/
   135         int size = 0;
   135         int             section, result, size = 0;
   136         int section, result;
       
   137 #ifdef DEBUG
   136 #ifdef DEBUG
   138         int i;
   137         int i;
   139         vorbis_comment	*vorbisComment;	/*other less useful data*/
   138         vorbis_comment	*vorbisComment;	/*other less useful data*/
   140 #endif
   139 #endif
   141         
   140         
   142         oggFile = Fopen(filename, "rb");
   141         oggFile = Fopen(filename, "rb");
   143         result = ov_open(oggFile, &oggStream, NULL, 0);	/*TODO: check returning value of result*/
   142         result = ov_open(oggFile, &oggStream, NULL, 0);	/*TODO: check returning value of result*/
   144         fclose(oggFile);
       
   145         
   143         
   146         vorbisInfo = ov_info(&oggStream, -1);
   144         vorbisInfo = ov_info(&oggStream, -1);
   147         pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;	
   145         pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;	
   148         
   146         
   149 #ifdef DEBUG
   147 #ifdef DEBUG
   171         else {
   169         else {
   172             if (vorbisInfo->channels == 2)
   170             if (vorbisInfo->channels == 2)
   173                 *format = AL_FORMAT_STEREO16;
   171                 *format = AL_FORMAT_STEREO16;
   174             else {
   172             else {
   175                 fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
   173                 fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
       
   174                 ov_clear (&oggStream);
       
   175                 fclose(oggFile);
   176                 return AL_FALSE;
   176                 return AL_FALSE;
   177             }
   177             }
   178         }
   178         }
   179         
   179         
   180         while(size < pcm_length) {
   180         while(size < pcm_length) {
   185             } else {
   185             } else {
   186                 if (result == 0)
   186                 if (result == 0)
   187                     break;
   187                     break;
   188                 else { 
   188                 else { 
   189                     fprintf(stderr, "ERROR: end of file from OGG stream\n");
   189                     fprintf(stderr, "ERROR: end of file from OGG stream\n");
       
   190                     ov_clear (&oggStream);
       
   191                     fclose(oggFile);
   190                     return AL_FALSE;
   192                     return AL_FALSE;
   191                 }
   193                 }
   192             }
   194             }
   193         }
   195         }
   194         
   196         
   195         /*records the last fields*/
   197         /*records the last fields*/
   196         *bitsize = size;
   198         *bitsize = size;
   197         *freq    = vorbisInfo->rate;
   199         *freq    = vorbisInfo->rate;
   198         
   200         
   199         ov_clear (&oggStream);
   201         ov_clear (&oggStream);
       
   202         fclose (oggFile);
   200         return AL_TRUE;
   203         return AL_TRUE;
   201     }
   204     }
   202     
   205     
   203 #ifdef __CPLUSPLUS
   206 #ifdef __CPLUSPLUS
   204 }
   207 }