music_flac.c
changeset 561 87bdb4c81c0b
parent 545 32e5ed415a34
child 601 05123263dab3
child 947 41422d16ee01
equal deleted inserted replaced
560:0fc8dffb86c5 561:87bdb4c81c0b
   185 				data->flac_data.data_len = data->flac_data.max_to_read;
   185 				data->flac_data.data_len = data->flac_data.max_to_read;
   186 				data->flac_data.data_read = 0;
   186 				data->flac_data.data_read = 0;
   187 
   187 
   188 				// create it
   188 				// create it
   189 				data->flac_data.data =
   189 				data->flac_data.data =
   190 									(char *)malloc (data->flac_data.data_len);
   190 					(char *)SDL_malloc (data->flac_data.data_len);
   191 
   191 
   192 				if (!data->flac_data.data) {
   192 				if (!data->flac_data.data) {
   193 					return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   193 					return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   194 				}
   194 				}
   195 			}
   195 			}
   225 											4 * (frame->header.blocksize - i);
   225 											4 * (frame->header.blocksize - i);
   226 				data->flac_data.overflow_read = 0;
   226 				data->flac_data.overflow_read = 0;
   227 
   227 
   228 				// make it big enough for the rest of the block
   228 				// make it big enough for the rest of the block
   229 				data->flac_data.overflow =
   229 				data->flac_data.overflow =
   230 								(char *)malloc (data->flac_data.overflow_len);
   230 					(char *)SDL_malloc (data->flac_data.overflow_len);
   231 
   231 
   232 				if (!data->flac_data.overflow) {
   232 				if (!data->flac_data.overflow) {
   233 					return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   233 					return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   234 				}
   234 				}
   235 			}
   235 			}
   311 			SDL_RWclose(rw);
   311 			SDL_RWclose(rw);
   312 		}
   312 		}
   313 		return NULL;
   313 		return NULL;
   314 	}
   314 	}
   315 
   315 
   316 	music = (FLAC_music *)malloc ( sizeof (*music));
   316 	music = (FLAC_music *)SDL_malloc ( sizeof (*music));
   317 	if (music) {
   317 	if (music) {
   318 		/* Initialize the music structure */
   318 		/* Initialize the music structure */
   319 		memset (music, 0, (sizeof (*music)));
   319 		memset (music, 0, (sizeof (*music)));
   320 		FLAC_stop (music);
   320 		FLAC_stop (music);
   321 		FLAC_setvolume (music, MIX_MAX_VOLUME);
   321 		FLAC_setvolume (music, MIX_MAX_VOLUME);
   365 					flac.FLAC__stream_decoder_finish( music->flac_decoder );
   365 					flac.FLAC__stream_decoder_finish( music->flac_decoder );
   366 				case 2:
   366 				case 2:
   367 					flac.FLAC__stream_decoder_delete( music->flac_decoder );
   367 					flac.FLAC__stream_decoder_delete( music->flac_decoder );
   368 				case 1:
   368 				case 1:
   369 				case 0:
   369 				case 0:
   370 					free(music);
   370 					SDL_free(music);
   371 					if (freerw) {
   371 					if (freerw) {
   372 						SDL_RWclose(rw);
   372 						SDL_RWclose(rw);
   373 					}
   373 					}
   374 					break;
   374 					break;
   375 			}
   375 			}
   407 	// set the max number of characters to read
   407 	// set the max number of characters to read
   408 	music->flac_data.max_to_read = 8192;
   408 	music->flac_data.max_to_read = 8192;
   409 	music->flac_data.data_len = music->flac_data.max_to_read;
   409 	music->flac_data.data_len = music->flac_data.max_to_read;
   410 	music->flac_data.data_read = 0;
   410 	music->flac_data.data_read = 0;
   411 	if (!music->flac_data.data) {
   411 	if (!music->flac_data.data) {
   412 		music->flac_data.data = (char *)malloc (music->flac_data.data_len);
   412 		music->flac_data.data = (char *)SDL_malloc (music->flac_data.data_len);
   413 	}
   413 	}
   414 
   414 
   415 	// we have data to read
   415 	// we have data to read
   416 	while(music->flac_data.max_to_read > 0) {
   416 	while(music->flac_data.max_to_read > 0) {
   417 		// first check if there is data in the overflow from before
   417 		// first check if there is data in the overflow from before
   469 						(int)music->flac_data.sample_rate, mixer.format,
   469 						(int)music->flac_data.sample_rate, mixer.format,
   470 		                mixer.channels, mixer.freq);
   470 		                mixer.channels, mixer.freq);
   471 		if (cvt->buf) {
   471 		if (cvt->buf) {
   472 			free (cvt->buf);
   472 			free (cvt->buf);
   473 		}
   473 		}
   474 		cvt->buf = (Uint8 *)malloc (music->flac_data.data_len * cvt->len_mult);
   474 		cvt->buf = (Uint8 *)SDL_malloc (music->flac_data.data_len * cvt->len_mult);
   475 		music->section = 0;
   475 		music->section = 0;
   476 	}
   476 	}
   477 	if (cvt->buf) {
   477 	if (cvt->buf) {
   478 		memcpy (cvt->buf, music->flac_data.data, music->flac_data.data_read);
   478 		memcpy (cvt->buf, music->flac_data.data, music->flac_data.data_read);
   479 		if (cvt->needed) {
   479 		if (cvt->needed) {