FLAC decoder now fully working (with seeking).

This commit is contained in:
Daniel Önnerby 2008-11-02 20:47:50 +00:00
parent 279592d82c
commit 89a6c39907
2 changed files with 20 additions and 39 deletions

View File

@ -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); i<frame->header.blocksize; ++i){
for(int j(0); j<thisPtr->channels; ++j){
thisPtr->outputBuffer[thisPtr->outputBufferSize] = (((float)buffer[j][i])/maxAmplitude);
thisPtr->outputBufferSize++;
}
}
for(unsigned int i(0); i<frame->header.blocksize; ++i){
for(int j(0); j<thisPtr->channels; ++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;
}

View File

@ -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: