unsigned int FlacDecoder::fetch(Signal& outleft, Signal& outright) { outleft.reset(); outright.reset(); if (_opened) { unsigned int request_size=Signal::size; while (request_size > _bufferl.size() - _bufferpos) { if (!FLAC__stream_decoder_process_single(_streamdecoder) || (FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_READ_FRAME && FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC && FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA && FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_READ_METADATA )) { break; } } const unsigned int to_read=request_size >_bufferl.size() - _bufferpos ? _bufferl.size() - _bufferpos : request_size; for (unsigned int i=0; i < to_read; i++) { outleft.samples[i]=_bufferl.at(_bufferpos); outright.samples[i]=_bufferr.at(_bufferpos++); } if (to_read == 0) { _ended=true; } return to_read; } _ended=true; return 0; }
unsigned int BassDecoder::fetch(Signal& left, Signal& right){ if (_music) { DWORD readed=0; #if defined(LIBTOOLS_WINDOWS) && !defined(BASS_H) if (!BASS_ChannelGetData || ! BASS_ErrorGetCode) { std::cerr << "Error missing BASS_ChannelGetData or BASS_ErrorGetCode functions" << std::endl; return 0; } #endif readed=BASS_ChannelGetData((DWORD)_music, (void*)_samplesForSignals, _bytesFrame); if(readed==-1 && BASS_ErrorGetCode() == BASS_ERROR_ENDED) { left.reset(); right.reset(); _ended=true; return 0; } if (readed < _bytesFrame) { for (unsigned int i=readed; i< _bytesFrame ;i++) ((char*)_samplesForSignals)[i]=0; } const unsigned int signal_size=Signal::size; if (_infos.chans>=2) { unsigned int k=0; for (unsigned int i=0; i < signal_size;) { left.samples[i]=_samplesForSignals[k++]; right.samples[i++]=_samplesForSignals[k++]; k+=_infos.chans-2; } } else if (_infos.chans==1) //mono { unsigned int k=0; for (unsigned int i=0; i < signal_size;) { left.samples[i]=_samplesForSignals[k]; right.samples[i++]=_samplesForSignals[k++]; } } return readed/sizeof(sample); } return 0; }
void Signal::tfd(Signal& out_tfd) { out_tfd.reset(); for (unsigned int k=0; k < Signal::size;k++) { for (unsigned int n=0; n < Signal::size;n++) { double a=2*3.14159*k*n/(double)(Signal::size); double cos_a=cos(a); double sin_a=sin(a); out_tfd.samples[k] += (sample) (abs(samples[n])*(sqrt(abs(cos_a*cos_a+sin_a*sin_a)))); } } }