From d35efddd65934e5adebe0c01ab7953c9a34082ed Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 11 Nov 2009 19:52:14 +0100 Subject: decoder/flac: calculate bit rate in flac_common_write() Removed the "bit_rate" attribute from the flac_data struct. Pass the number of bytes since the last call to flac_common_write(), and let it calculate the bit rate. --- src/decoder/flac_plugin.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/decoder/flac_plugin.c') diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c index 7a4f11451..afc134077 100644 --- a/src/decoder/flac_plugin.c +++ b/src/decoder/flac_plugin.c @@ -194,22 +194,23 @@ flac_write_cb(const FLAC__StreamDecoder *dec, const FLAC__Frame *frame, FLAC__uint32 samples = frame->header.blocksize; struct flac_data *data = (struct flac_data *) vdata; float timeChange; - FLAC__uint64 newPosition = 0; + FLAC__uint64 nbytes = 0; timeChange = ((float)samples) / frame->header.sample_rate; data->time += timeChange; - FLAC__stream_decoder_get_decode_position(dec, &newPosition); - if (data->position && newPosition >= data->position) { - assert(timeChange >= 0); - - data->bit_rate = - ((newPosition - data->position) * 8.0 / timeChange) - / 1000 + 0.5; - } - data->position = newPosition; + if (FLAC__stream_decoder_get_decode_position(dec, &nbytes)) { + if (data->position > 0 && nbytes > data->position) { + nbytes -= data->position; + data->position += nbytes; + } else { + data->position = nbytes; + nbytes = 0; + } + } else + nbytes = 0; - return flac_common_write(data, frame, buf); + return flac_common_write(data, frame, buf, nbytes); } static struct tag * -- cgit v1.2.3