diff --git a/src/contrib/flacdecoder/FLACDecoder.cpp b/src/contrib/flacdecoder/FLACDecoder.cpp index d7e1f6601..0f58d3f9a 100644 --- a/src/contrib/flacdecoder/FLACDecoder.cpp +++ b/src/contrib/flacdecoder/FLACDecoder.cpp @@ -43,13 +43,7 @@ FLACDecoder::FLACDecoder() ,bps(0) ,totalSamples(0) { -/* this->flacCallbacks.read = &FlacRead; - this->flacCallbacks.seek = &FlacSeek; - this->flacCallbacks.tell = &FlacTell; - this->flacCallbacks.close = &FlacClose; -*/ this->decoder = FLAC__stream_decoder_new(); - } @@ -111,13 +105,6 @@ FLAC__StreamDecoderLengthStatus FLACDecoder::FlacFileSize(const FLAC__StreamDeco return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; } -/*int FLACDecoder::FlacClose(void *datasource){ - if( ((FLACDecoder*)datasource)->fileStream->Close() ){ - return 0; - } - return -1; -}*/ - bool FLACDecoder::Open(musik::core::filestreams::IFileStream *fileStream){ this->fileStream = fileStream; @@ -142,19 +129,19 @@ bool FLACDecoder::Open(musik::core::filestreams::IFileStream *fileStream){ return false; } -void FLACDecoder::FlacError(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *clientData){ - -} +void FLACDecoder::FlacError(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *clientData){ + +} void FLACDecoder::FlacMeta(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *clientData){ FLACDecoder *thisPtr = (FLACDecoder*)clientData; - if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - thisPtr->totalSamples = metadata->data.stream_info.total_samples; - thisPtr->sampleRate = metadata->data.stream_info.sample_rate; - thisPtr->channels = metadata->data.stream_info.channels; - thisPtr->bps = metadata->data.stream_info.bits_per_sample; - } + if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { + thisPtr->totalSamples = metadata->data.stream_info.total_samples; + thisPtr->sampleRate = metadata->data.stream_info.sample_rate; + thisPtr->channels = metadata->data.stream_info.channels; + thisPtr->bps = metadata->data.stream_info.bits_per_sample; + } } @@ -183,12 +170,12 @@ FLAC__StreamDecoderWriteStatus FLACDecoder::FlacWrite(const FLAC__StreamDecoder float maxAmplitude = pow(2.0f,(thisPtr->bps-1)); // Convert the buffer (16bit int) to the outputBuffer (float) - for(unsigned int i(0); iheader.blocksize; ++i){ - for(int j(0); jchannels; ++j){ - thisPtr->outputBuffer[thisPtr->outputBufferSize] = (((float)buffer[j][i])/maxAmplitude); - thisPtr->outputBufferSize++; - } - } + for(unsigned int i(0); iheader.blocksize; ++i){ + for(int j(0); jchannels; ++j){ + thisPtr->outputBuffer[thisPtr->outputBufferSize] = (((float)buffer[j][i])/maxAmplitude); + thisPtr->outputBufferSize++; + } + } return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } @@ -219,16 +206,10 @@ bool FLACDecoder::GetLength(unsigned long * MS){ } bool FLACDecoder::SetPosition(unsigned long * MS,unsigned long totalMS){ -/* double pos = *MS / 1000.0; - - if(ov_seekable(&this->oggFile)){ - if(!ov_time_seek(&this->oggFile, pos)){ - double time = ov_time_tell(&this->oggFile); - *MS = (unsigned long)(time * 1000.0); - return true; - } - } -*/ + FLAC__uint64 seekToSample = ( ((FLAC__uint64)this->sampleRate) * ((FLAC__uint64)(*MS)) )/(FLAC__uint64)1000; + if(FLAC__stream_decoder_seek_absolute(this->decoder,seekToSample)){ + return true; + } return false; } diff --git a/src/contrib/flacdecoder/FLACDecoder.h b/src/contrib/flacdecoder/FLACDecoder.h index 3bf592d99..b2279c07d 100644 --- a/src/contrib/flacdecoder/FLACDecoder.h +++ b/src/contrib/flacdecoder/FLACDecoder.h @@ -71,7 +71,7 @@ public: static FLAC__StreamDecoderWriteStatus FlacWrite(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame,const FLAC__int32 *const buffer[], void *clientData); static void FlacMeta(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *clientData); - static void FlacError(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *clientData); + static void FlacError(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *clientData); protected: