load_flac.c
changeset 561 87bdb4c81c0b
parent 518 8bc9b5fd2aae
child 601 05123263dab3
equal deleted inserted replaced
560:0fc8dffb86c5 561:87bdb4c81c0b
   174 	// check if it is the first audio frame so we can initialize the output
   174 	// check if it is the first audio frame so we can initialize the output
   175 	// buffer
   175 	// buffer
   176 	if (frame->header.number.sample_number == 0) {
   176 	if (frame->header.number.sample_number == 0) {
   177 		*(data->sdl_audio_len) = data->sdl_spec->size;
   177 		*(data->sdl_audio_len) = data->sdl_spec->size;
   178 		data->sdl_audio_read = 0;
   178 		data->sdl_audio_read = 0;
   179     	*(data->sdl_audio_buf) = malloc (*(data->sdl_audio_len));
   179     	*(data->sdl_audio_buf) = SDL_malloc (*(data->sdl_audio_len));
   180 
   180 
   181     	if (*(data->sdl_audio_buf) == NULL) {
   181     	if (*(data->sdl_audio_buf) == NULL) {
   182     		SDL_SetError
   182     		SDL_SetError
   183 					("Unable to allocate memory to store the FLAC stream.");
   183 					("Unable to allocate memory to store the FLAC stream.");
   184     		return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   184     		return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   272 	int was_init = 0;
   272 	int was_init = 0;
   273 	Uint32 samplesize;
   273 	Uint32 samplesize;
   274 
   274 
   275 	// create the client data passing information
   275 	// create the client data passing information
   276 	FLAC_SDL_Data* client_data;
   276 	FLAC_SDL_Data* client_data;
   277 	client_data = (FLAC_SDL_Data *)malloc (sizeof (FLAC_SDL_Data));
   277 	client_data = (FLAC_SDL_Data *)SDL_malloc (sizeof (FLAC_SDL_Data));
   278 
   278 
   279 	if ((!src) || (!audio_buf) || (!audio_len))   /* sanity checks. */
   279 	if ((!src) || (!audio_buf) || (!audio_len))   /* sanity checks. */
   280 		goto done;
   280 		goto done;
   281 
   281 
   282 	if (!Mix_Init(MIX_INIT_FLAC))
   282 	if (!Mix_Init(MIX_INIT_FLAC))
   311 		goto done;
   311 		goto done;
   312 	}
   312 	}
   313 
   313 
   314 	was_error = 0;
   314 	was_error = 0;
   315 
   315 
   316     /* Don't return a buffer that isn't a multiple of samplesize */
   316 	/* Don't return a buffer that isn't a multiple of samplesize */
   317     samplesize = ((spec->format & 0xFF) / 8) * spec->channels;
   317 	samplesize = ((spec->format & 0xFF) / 8) * spec->channels;
   318     *audio_len &= ~(samplesize - 1);
   318 	*audio_len &= ~(samplesize - 1);
   319 
   319 
   320 done:
   320 done:
   321 	if (was_init && decoder) {
   321 	if (was_init && decoder) {
   322 		flac.FLAC__stream_decoder_finish (decoder);
   322 		flac.FLAC__stream_decoder_finish (decoder);
   323 	}
   323 	}