aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/_flac_common.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-11 19:52:14 +0100
committerMax Kellermann <max@duempel.org>2009-11-11 19:52:14 +0100
commitd35efddd65934e5adebe0c01ab7953c9a34082ed (patch)
treeb30c23cfeb9d644a36e3450c9602ad3e41ef255f /src/decoder/_flac_common.c
parent7b13776f2dd2feeb4bd28e8cf023ec81474e4eaa (diff)
downloadmpd-d35efddd65934e5adebe0c01ab7953c9a34082ed.tar.gz
mpd-d35efddd65934e5adebe0c01ab7953c9a34082ed.tar.xz
mpd-d35efddd65934e5adebe0c01ab7953c9a34082ed.zip
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.
Diffstat (limited to 'src/decoder/_flac_common.c')
-rw-r--r--src/decoder/_flac_common.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index fbeab43a7..0755ef641 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.c
@@ -40,7 +40,6 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
data->time = 0;
data->position = 0;
- data->bit_rate = 0;
data->decoder = decoder;
data->input_stream = input_stream;
data->replay_gain_info = NULL;
@@ -110,12 +109,14 @@ void flac_error_common_cb(const char *plugin,
FLAC__StreamDecoderWriteStatus
flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
- const FLAC__int32 *const buf[])
+ const FLAC__int32 *const buf[],
+ FLAC__uint64 nbytes)
{
enum decoder_command cmd;
size_t buffer_size = frame->header.blocksize *
audio_format_frame_size(&data->audio_format);
void *buffer;
+ unsigned bit_rate;
buffer = pcm_buffer_get(&data->buffer, buffer_size);
@@ -123,9 +124,15 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
data->audio_format.bits, buf,
0, frame->header.blocksize);
+ if (nbytes > 0)
+ bit_rate = nbytes * 8 * frame->header.sample_rate /
+ (1000 * frame->header.blocksize);
+ else
+ bit_rate = 0;
+
cmd = decoder_data(data->decoder, data->input_stream,
buffer, buffer_size,
- data->time, data->bit_rate,
+ data->time, bit_rate,
data->replay_gain_info);
data->next_frame += frame->header.blocksize;
switch (cmd) {