openalbridge/loaders.c
changeset 2213 bd51bbf06033
parent 2212 6b5da1a2765a
child 2214 eacb5b19d587
equal deleted inserted replaced
2212:6b5da1a2765a 2213:bd51bbf06033
    20 
    20 
    21 #ifdef __CPLUSPLUS
    21 #ifdef __CPLUSPLUS
    22 extern "C" {
    22 extern "C" {
    23 #endif 
    23 #endif 
    24 	
    24 	
    25 	int load_WavPcm (const char *filename, ALenum *format, uint8_t** data, ALsizei *bitsize, ALsizei *freq) {
    25 	int load_WavPcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
    26 		WAV_header_t WAVHeader;
    26 		WAV_header_t WAVHeader;
    27 		FILE *wavfile;
    27 		FILE *wavfile;
    28 		int t, n = 0;
    28 		int t, n = 0;
    29 		
    29 		
    30 		wavfile = Fopen(filename, "rb");
    30 		wavfile = Fopen(filename, "rb");
    73 #ifdef DEBUG
    73 #ifdef DEBUG
    74 		fprintf(stderr, "Subchunk2ID: %X\n", invert_endianness(WAVHeader.Subchunk2ID));
    74 		fprintf(stderr, "Subchunk2ID: %X\n", invert_endianness(WAVHeader.Subchunk2ID));
    75 		fprintf(stderr, "Subchunk2Size: %d\n", WAVHeader.Subchunk2Size);
    75 		fprintf(stderr, "Subchunk2Size: %d\n", WAVHeader.Subchunk2Size);
    76 #endif
    76 #endif
    77 		
    77 		
    78 		*data = (uint8_t*) malloc (sizeof(uint8_t) * WAVHeader.Subchunk2Size);
    78 		*data = (char*) malloc (sizeof(char) * WAVHeader.Subchunk2Size);
    79 		
    79 		
    80 		/*this could be improved*/
    80 		/*this could be improved*/
    81 		do {
    81 		do {
    82 			n += fread(&((*data)[n]), sizeof(uint8_t), 1, wavfile);
    82 			n += fread(&((*data)[n]), sizeof(uint8_t), 1, wavfile);
    83 		} while (n < WAVHeader.Subchunk2Size);
    83 		} while (n < WAVHeader.Subchunk2Size);
   122 		*bitsize = WAVHeader.Subchunk2Size;
   122 		*bitsize = WAVHeader.Subchunk2Size;
   123 		*freq = WAVHeader.SampleRate;
   123 		*freq = WAVHeader.SampleRate;
   124 		return AL_TRUE;
   124 		return AL_TRUE;
   125 	}
   125 	}
   126 	
   126 	
   127 	int load_OggVorbis (const char *filename, ALenum *format, uint8_t**data, ALsizei *bitsize, ALsizei *freq) {
   127 	int load_OggVorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) {
   128 		/*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
   128 		/*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
   129 		FILE			*oggFile;		/*ogg handle*/
   129 		FILE			*oggFile;		/*ogg handle*/
   130 		OggVorbis_File  oggStream;		/*stream handle*/
   130 		OggVorbis_File  oggStream;		/*stream handle*/
   131 		vorbis_info		*vorbisInfo;	/*some formatting data*/
   131 		vorbis_info		*vorbisInfo;	/*some formatting data*/
   132 		int64_t			pcm_length;		/*length of the decoded data*/
   132 		int64_t			pcm_length;		/*length of the decoded data*/
   159 		for (i = 0; i < vorbisComment->comments; i++)
   159 		for (i = 0; i < vorbisComment->comments; i++)
   160 			fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
   160 			fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
   161 #endif
   161 #endif
   162 		
   162 		
   163 		/*allocates enough room for the decoded data*/
   163 		/*allocates enough room for the decoded data*/
   164 		*data = (uint8_t*) malloc (sizeof(uint8_t) * pcm_length);
   164 		*data = (char*) malloc (sizeof(char) * pcm_length);
   165 		
   165 		
   166 		/*there *should* not be ogg at 8 bits*/
   166 		/*there *should* not be ogg at 8 bits*/
   167 		if (vorbisInfo->channels == 1)
   167 		if (vorbisInfo->channels == 1)
   168 			*format = AL_FORMAT_MONO16;
   168 			*format = AL_FORMAT_MONO16;
   169 		else {
   169 		else {