aboutsummaryrefslogtreecommitdiffstats
path: root/src/flac_decode.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-02-26 03:21:24 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-02-26 03:21:24 +0000
commit1adca2abd2aff8e74691d180f00600c3467ded28 (patch)
tree7a4d22a7ff842b1b17466c8d6f31c5aa13b2c293 /src/flac_decode.c
parent9d4bc4efea0359896863b67e5e5223d8025099f8 (diff)
downloadmpd-1adca2abd2aff8e74691d180f00600c3467ded28.tar.gz
mpd-1adca2abd2aff8e74691d180f00600c3467ded28.tar.xz
mpd-1adca2abd2aff8e74691d180f00600c3467ded28.zip
add bitrate reporting to flac
git-svn-id: https://svn.musicpd.org/mpd/trunk@63 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/flac_decode.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/flac_decode.c b/src/flac_decode.c
index 2708795cf..fd4969073 100644
--- a/src/flac_decode.c
+++ b/src/flac_decode.c
@@ -33,6 +33,8 @@ typedef struct {
unsigned char chunk[CHUNK_SIZE];
int chunk_length;
float time;
+ int bitRate;
+ FLAC__uint64 position;
Buffer * cb;
AudioFormat * af;
DecoderControl * dc;
@@ -57,6 +59,8 @@ void flacPlayFile(char *file, Buffer * cb, AudioFormat * af,
data.chunk_length = 0;
data.time = 0;
+ data.position = 0;
+ data.bitRate = 0;
data.cb = cb;
data.af = af;
data.dc = dc;
@@ -106,6 +110,7 @@ void flacPlayFile(char *file, Buffer * cb, AudioFormat * af,
{
data.time = ((float)sampleToSeek)/
af->sampleRate;
+ data.position = 0;
}
dc->seek = 0;
}
@@ -189,7 +194,7 @@ int flacSendChunk(FlacData * data) {
CHUNK_SIZE);
data->cb->chunkSize[data->cb->end] = data->chunk_length;
data->cb->times[data->cb->end] = data->time;
- data->cb->bitRate[data->cb->end] = 0;
+ data->cb->bitRate[data->cb->end] = data->bitRate;
data->cb->end++;
if(data->cb->end>=buffered_chunks) {
@@ -207,8 +212,18 @@ FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__FileDecoder *dec, const FLA
unsigned char * uc;
int c_samp, c_chan, d_samp;
int i;
+ float timeChange;
+ FLAC__uint64 newPosition = 0;
- data->time+=((float)samples)/frame->header.sample_rate;
+ timeChange = ((float)samples)/frame->header.sample_rate;
+ data->time+= timeChange;
+
+ FLAC__file_decoder_get_decode_position(dec,&newPosition);
+ if(data->position) {
+ data->bitRate = ((newPosition-data->position)*8.0/timeChange)
+ /1024+0.5;
+ }
+ data->position = newPosition;
for(c_samp = d_samp = 0; c_samp < frame->header.blocksize; c_samp++) {
for(c_chan = 0; c_chan < frame->header.channels;