comparison libmpcodecs/ad_flac.c @ 11701:8ab2028e6ed9

Sync to original FLAC. Main reason from their CVS log: add support for synthesis to big-endian in plugins.
author lumag
date Mon, 29 Dec 2003 18:10:49 +0000
parents 1188bf65b776
children
comparison
equal deleted inserted replaced
11700:272fc35fd8ee 11701:8ab2028e6ed9
106 106
107 /*FIXME: we need to support format conversion:(flac specs allow bits/sample to be from 4 to 32. Not only 8 and 16 !!!)*/ 107 /*FIXME: we need to support format conversion:(flac specs allow bits/sample to be from 4 to 32. Not only 8 and 16 !!!)*/
108 FLAC__StreamDecoderWriteStatus flac_write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) 108 FLAC__StreamDecoderWriteStatus flac_write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
109 { 109 {
110 FLAC__byte *buf = ((flac_struct_t*)(client_data))->buf; 110 FLAC__byte *buf = ((flac_struct_t*)(client_data))->buf;
111 int channel, sample;
112 int bps = ((flac_struct_t*)(client_data))->sh->samplesize; 111 int bps = ((flac_struct_t*)(client_data))->sh->samplesize;
112 int lowendian = (((flac_struct_t*)(client_data))->sh->sample_format == AFMT_S16_LE);
113 int unsigned_data = (((flac_struct_t*)(client_data))->sh->sample_format == AFMT_U8);
113 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "\nWrite callback (%d bytes)!!!!\n", bps*frame->header.blocksize*frame->header.channels); 114 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "\nWrite callback (%d bytes)!!!!\n", bps*frame->header.blocksize*frame->header.channels);
114 if (buf == NULL) 115 if (buf == NULL)
115 { 116 {
116 /* This is used in control for skipping 1 audio frame */ 117 /* This is used in control for skipping 1 audio frame */
117 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; 118 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
118 } 119 }
119 #if 0 120 FLAC__replaygain_synthesis__apply_gain(
120 for (sample = 0; sample < frame->header.blocksize; sample ++)
121 for (channel = 0; channel < frame->header.channels; channel ++)
122 switch (bps)
123 {
124 case 3:
125 buf[bps*(sample*frame->header.channels+channel)+2] = (FLAC__byte)(buffer[channel][sample]>>16);
126 case 2:
127 buf[bps*(sample*frame->header.channels+channel)+1] = (FLAC__byte)(buffer[channel][sample]>>8);
128 buf[bps*(sample*frame->header.channels+channel)+0] = (FLAC__byte)(buffer[channel][sample]);
129 break;
130 case 1:
131 buf[bps*(sample*frame->header.channels+channel)] = buffer[channel][sample]^0x80;
132 break;
133 }
134 #else
135 FLAC__plugin_common__apply_gain(
136 buf, 121 buf,
122 lowendian,
123 unsigned_data,
137 buffer, 124 buffer,
138 frame->header.blocksize, 125 frame->header.blocksize,
139 frame->header.channels, 126 frame->header.channels,
140 ((flac_struct_t*)(client_data))->bits_per_sample, 127 ((flac_struct_t*)(client_data))->bits_per_sample,
141 ((flac_struct_t*)(client_data))->sh->samplesize * 8, 128 ((flac_struct_t*)(client_data))->sh->samplesize * 8,
142 ((flac_struct_t*)(client_data))->replay_scale, 129 ((flac_struct_t*)(client_data))->replay_scale,
143 hard_limit, 130 hard_limit,
144 dither, 131 dither,
145 &(((flac_struct_t*)(client_data))->dither_context) 132 &(((flac_struct_t*)(client_data))->dither_context)
146 ); 133 );
147 #endif
148 ((flac_struct_t*)(client_data))->written += bps*frame->header.blocksize*frame->header.channels; 134 ((flac_struct_t*)(client_data))->written += bps*frame->header.blocksize*frame->header.channels;
149 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; 135 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
150 } 136 }
151 137
152 #ifdef local_min 138 #ifdef local_min
236 sh->channels = metadata->data.stream_info.channels; 222 sh->channels = metadata->data.stream_info.channels;
237 mp_msg(MSGT_DECAUDIO, MSGL_V, "bits_per_sample: %u\n", metadata->data.stream_info.bits_per_sample); 223 mp_msg(MSGT_DECAUDIO, MSGL_V, "bits_per_sample: %u\n", metadata->data.stream_info.bits_per_sample);
238 ((flac_struct_t*)client_data)->bits_per_sample = metadata->data.stream_info.bits_per_sample; 224 ((flac_struct_t*)client_data)->bits_per_sample = metadata->data.stream_info.bits_per_sample;
239 sh->samplesize = (metadata->data.stream_info.bits_per_sample<=8)?1:2; 225 sh->samplesize = (metadata->data.stream_info.bits_per_sample<=8)?1:2;
240 /* FIXME: need to support dithering to samplesize 4 */ 226 /* FIXME: need to support dithering to samplesize 4 */
241 sh->sample_format=(sh->samplesize==1)?AFMT_U8:AFMT_S16_LE; // sample format, see libao2/afmt.h 227 sh->sample_format=(sh->samplesize==1)?AFMT_U8:
228 #ifdef WORDS_BIGENDIAN
229 AFMT_S16_BE;
230 #else
231 AFMT_S16_LE;
232 #endif
242 sh->o_bps = sh->samplesize * metadata->data.stream_info.channels * metadata->data.stream_info.sample_rate; 233 sh->o_bps = sh->samplesize * metadata->data.stream_info.channels * metadata->data.stream_info.sample_rate;
243 sh->i_bps = metadata->data.stream_info.bits_per_sample * metadata->data.stream_info.channels * metadata->data.stream_info.sample_rate / 8 / 2; 234 sh->i_bps = metadata->data.stream_info.bits_per_sample * metadata->data.stream_info.channels * metadata->data.stream_info.sample_rate / 8 / 2;
244 // input data rate (compressed bytes per second) 235 // input data rate (compressed bytes per second)
245 // Compression rate is near 0.5 236 // Compression rate is near 0.5
246 mp_msg(MSGT_DECAUDIO, MSGL_V, "total_samples: %llu\n", metadata->data.stream_info.total_samples); 237 mp_msg(MSGT_DECAUDIO, MSGL_V, "total_samples: %llu\n", metadata->data.stream_info.total_samples);
458 context->minlen = context->maxlen = 0; 449 context->minlen = context->maxlen = 0;
459 context->replay_scale = 1.0; 450 context->replay_scale = 1.0;
460 451
461 FLAC__stream_decoder_process_until_end_of_metadata(context->flac_dec); 452 FLAC__stream_decoder_process_until_end_of_metadata(context->flac_dec);
462 453
463 FLAC__plugin_common__init_dither_context(&(context->dither_context), sh_audio->samplesize * 8, noise_shaping); 454 FLAC__replaygain_synthesis__init_dither_context(&(context->dither_context), sh_audio->samplesize * 8, noise_shaping);
464 455
465 return 1; // return values: 1=OK 0=ERROR 456 return 1; // return values: 1=OK 0=ERROR
466 } 457 }
467 458
468 static void uninit(sh_audio_t *sh){ 459 static void uninit(sh_audio_t *sh){