From 2ec1c5ff3c1ff67825fb449c9eab2c3e4ff441f6 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Mon, 10 May 2004 12:35:18 +0000 Subject: some more work on organizing code for resampling/audioFormat conversion git-svn-id: https://svn.musicpd.org/mpd/trunk@968 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audiofile_decode.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/audiofile_decode.c') diff --git a/src/audiofile_decode.c b/src/audiofile_decode.c index f3e88395b..b6b459f08 100644 --- a/src/audiofile_decode.c +++ b/src/audiofile_decode.c @@ -51,8 +51,7 @@ int getAudiofileTotalTime(char * file) return time; } -int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) -{ +int audiofile_decode(OutputBuffer * cb, DecoderControl * dc) { int fs, frame_count; AFfilehandle af_fp; int bits; @@ -71,19 +70,20 @@ int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) } afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); - af->bits = bits; - af->sampleRate = afGetRate(af_fp, AF_DEFAULT_TRACK); - af->channels = afGetChannels(af_fp,AF_DEFAULT_TRACK); + dc->audioFormat.bits = bits; + dc->audioFormat.sampleRate = afGetRate(af_fp, AF_DEFAULT_TRACK); + dc->audioFormat.channels = afGetChannels(af_fp,AF_DEFAULT_TRACK); + getOutputAudioFormat(&(dc->audioFormat),&(cb->audioFormat)); frame_count = afGetFrameCount(af_fp,AF_DEFAULT_TRACK); - cb->totalTime = ((float)frame_count/(float)af->sampleRate); + dc->totalTime = ((float)frame_count/(float)dc->audioFormat.sampleRate); - bitRate = st.st_size*8.0/cb->totalTime/1000.0+0.5; + bitRate = st.st_size*8.0/dc->totalTime/1000.0+0.5; - if (af->bits != 8 && af->bits != 16) { + if (dc->audioFormat.bits != 8 && dc->audioFormat.bits != 16) { ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n", - dc->file,af->bits); + dc->file,dc->audioFormat.bits); afCloseFile(af_fp); return -1; } @@ -100,7 +100,8 @@ int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) if(dc->seek) { cb->end = cb->begin; cb->wrap = 0; - current = dc->seekWhere * af->sampleRate; + current = dc->seekWhere * + dc->audioFormat.sampleRate; afSeekFrame(af_fp, AF_DEFAULT_TRACK,current); dc->seek = 0; @@ -111,9 +112,9 @@ int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) else { current += ret; sendDataToOutputBuffer(cb,dc,chunk,ret*fs, - (float)current / - (float)af->sampleRate, - bitRate); + (float)current / + (float)dc->audioFormat.sampleRate, + bitRate); if(dc->stop) break; else if(dc->seek) continue; } -- cgit v1.2.3