From d5eeb44a9d05a1b8072fc090fe07d7a13a8bfb06 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Mon, 17 May 2010 20:30:53 +0200 Subject: fix flac avg bitrate to work with cuesheets --- plugins/flac/flac.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'plugins/flac/flac.c') diff --git a/plugins/flac/flac.c b/plugins/flac/flac.c index a1f26f16..43b1b1c0 100644 --- a/plugins/flac/flac.c +++ b/plugins/flac/flac.c @@ -250,6 +250,23 @@ cflac_init (DB_fileinfo_t *_info, DB_playItem_t *it) { trace ("cflac_init not a flac stream\n"); return -1; } + + // bitrate + size_t fsize = deadbeef->fgetlength (info->file); + FLAC__uint64 position; + FLAC__bool res = FLAC__stream_decoder_get_decode_position (info->decoder, &position); + if (res) { + fsize -= position; + } + FLAC__uint64 flac_totalsamples = FLAC__stream_decoder_get_total_samples (info->decoder); + float sec = flac_totalsamples / _info->samplerate; + if (sec > 0) { + info->bitrate = fsize / sec * 8 / 1000; + } + else { + info->bitrate = -1; + } + info->buffer = malloc (BUFFERSIZE); info->remaining = 0; if (it->endsample > 0) { @@ -273,20 +290,6 @@ cflac_init (DB_fileinfo_t *_info, DB_playItem_t *it) { return -1; } - size_t fsize = deadbeef->fgetlength (info->file); - FLAC__uint64 position; - FLAC__bool res = FLAC__stream_decoder_get_decode_position (info->decoder, &position); - if (res) { - fsize -= position; - } - FLAC__uint64 flac_totalsamples = FLAC__stream_decoder_get_total_samples (info->decoder); - float sec = flac_totalsamples / _info->samplerate; - if (sec > 0) { - info->bitrate = fsize / sec * 8 / 1000; - } - else { - info->bitrate = -1; - } return 0; } -- cgit v1.2.3