diff --git a/src/contrib/m4adecoder/libfaad/common.h b/src/contrib/m4adecoder/libfaad/common.h index a965a35ec..89c8ce7c4 100755 --- a/src/contrib/m4adecoder/libfaad/common.h +++ b/src/contrib/m4adecoder/libfaad/common.h @@ -313,17 +313,17 @@ char *strchr(), *strrchr(); #if defined(_WIN32) && !defined(__MINGW32__) - #define HAS_LRINTF - static INLINE int lrintf(float f) - { - int i; - __asm - { - fld f - fistp i - } - return i; - } + //#define HAS_LRINTF + //static INLINE int lrintf(float f) + //{ + // int i; + // __asm + // { + // fld f + // fistp i + // } + // return i; + //} #elif (defined(__i386__) && defined(__GNUC__) && \ !defined(__CYGWIN__) && !defined(__MINGW32__)) #ifndef HAVE_LRINTF diff --git a/src/core/audio/Buffer.cpp b/src/core/audio/Buffer.cpp index ad35392e1..011ffa398 100644 --- a/src/core/audio/Buffer.cpp +++ b/src/core/audio/Buffer.cpp @@ -57,7 +57,6 @@ Buffer::Buffer(void) , internalBufferSize(0) , sampleRate(44100) , channels(2) { - } Buffer::~Buffer() { @@ -105,11 +104,7 @@ void Buffer::CopyFormat(BufferPtr fromBuffer) { void Buffer::ResizeBuffer() { if (this->sampleSize > this->internalBufferSize) { - if (this->buffer) { - delete[] this->buffer; - this->buffer = nullptr; - } - + delete[] this->buffer; this->buffer = new float[this->sampleSize]; this->internalBufferSize = this->sampleSize; } @@ -145,42 +140,31 @@ void Buffer::Copy(float* buffer, long samples) { void Buffer::Append(float* src, long samples) { /* number of floats (not bytes) in buffer */ - long newBufferSize = (this->Samples() + samples); + long newBufferSize = this->sampleSize + samples; - if (newBufferSize > this->internalBufferSize) { /* resize, then copy, if too small */ + if (newBufferSize > this->internalBufferSize) { + /* resize, then copy, if too small */ float *newBuffer = new float[newBufferSize]; CopyFloat(newBuffer, this->buffer, this->sampleSize); - float *dst = &newBuffer[this->sampleSize]; - CopyFloat(dst, src, samples); + CopyFloat(newBuffer + this->sampleSize, src, samples); delete[] this->buffer; this->buffer = newBuffer; this->internalBufferSize = newBufferSize; } - else { /* append, no resize required */ - float *dst = &this->buffer[this->sampleSize]; - CopyFloat(dst, src, samples); + else { + /* append, no resize required */ + CopyFloat(this->buffer + this->sampleSize, src, samples); this->internalBufferSize += samples; } this->sampleSize = newBufferSize; } -bool Buffer::Append(BufferPtr appendBuffer) { - if (this->SampleRate() == appendBuffer->SampleRate() && - this->Channels() == appendBuffer->Channels()) - { - this->Append(appendBuffer->BufferPointer(), appendBuffer->Samples()); - return true; - } - - return false; -} - bool Buffer::Fft(float* buffer, int size) { - if (this->sampleSize < FFT_BUFFER_SIZE || size != FFT_BUFFER_SIZE) { + if (this->sampleSize / this->channels < FFT_BUFFER_SIZE || size != FFT_BUFFER_SIZE) { return false; } @@ -188,8 +172,9 @@ bool Buffer::Fft(float* buffer, int size) { /* de-interleave the audio first */ float* deinterleaved = new float[FFT_BUFFER_SIZE * count]; + int to; for (int i = 0; i < count * FFT_BUFFER_SIZE; i++) { - const int to = ((i % this->channels) * FFT_BUFFER_SIZE) + (i / count); + to = ((i % this->channels) * FFT_BUFFER_SIZE) + (i / count); deinterleaved[to] = this->buffer[i]; } @@ -207,7 +192,7 @@ bool Buffer::Fft(float* buffer, int size) { fft_perform(this->buffer, buffer, state); for (int i = 1; i < count; i++) { - fft_perform(&deinterleaved[i * FFT_BUFFER_SIZE], scratch, state); + fft_perform(deinterleaved + (i * FFT_BUFFER_SIZE), scratch, state); /* average with the previous read */ for (int j = 0; j < FFT_BUFFER_SIZE; j++) { diff --git a/src/core/audio/Buffer.h b/src/core/audio/Buffer.h index 4dec8c856..a2b1e0719 100644 --- a/src/core/audio/Buffer.h +++ b/src/core/audio/Buffer.h @@ -67,7 +67,6 @@ namespace musik { namespace core { namespace audio { void SetPosition(double position); void Copy(float* buffer, long samples); void Append(float* buffer, long samples); - bool Append(BufferPtr appendBuffer); void CopyFormat(BufferPtr fromBuffer); private: diff --git a/src/core/audio/DynamicStream.cpp b/src/core/audio/DynamicStream.cpp index 5850a0339..8b6f3131f 100644 --- a/src/core/audio/DynamicStream.cpp +++ b/src/core/audio/DynamicStream.cpp @@ -46,12 +46,11 @@ using musik::core::PluginFactory; static std::string TAG = "DynamicStream"; DynamicStream::DynamicStream(unsigned int options) - : preferedBufferSampleSize(4096) - , options(options) - , decoderSampleRate(0) - , decoderChannels(0) - , decoderSamplePosition(0) -{ +: preferedBufferSampleSize(4096) +, options(options) +, decoderSampleRate(0) +, decoderChannels(0) +, decoderSamplePosition(0) { if ((this->options & NoDSP) == 0) { typedef PluginFactory::DestroyDeleter Deleter; this->dsps = PluginFactory::Instance().QueryInterface("GetDSP"); @@ -164,13 +163,18 @@ BufferPtr DynamicStream::GetNextProcessedOutputBuffer() { BufferPtr currentBuffer = this->GetNextBufferFromDecoder(); if (currentBuffer) { + void * f = &free; + /* try to fill the buffer to its optimal size; if the decoder didn't return a full buffer, ask it for some more data. */ bool moreBuffers = true; while (currentBuffer->Samples() < this->preferedBufferSampleSize && moreBuffers) { BufferPtr bufferToAppend = this->GetNextBufferFromDecoder(); if (bufferToAppend) { - currentBuffer->Append(bufferToAppend); + currentBuffer->Append( + bufferToAppend->BufferPointer(), + bufferToAppend->Samples()); + this->RecycleBuffer(bufferToAppend); } else { @@ -184,7 +188,7 @@ BufferPtr DynamicStream::GetNextProcessedOutputBuffer() { for (Dsps::iterator dsp = this->dsps.begin(); dsp != this->dsps.end(); ++dsp) { oldBuffer->CopyFormat(currentBuffer); - currentBuffer->SetPosition(oldBuffer->Position()); + oldBuffer->SetPosition(currentBuffer->Position()); if ((*dsp)->Process(currentBuffer.get(), oldBuffer.get())) { currentBuffer.swap(oldBuffer); diff --git a/src/core/audio/FixedSizeStream.cpp b/src/core/audio/FixedSizeStream.cpp index a1bc404ea..3ea8906b5 100644 --- a/src/core/audio/FixedSizeStream.cpp +++ b/src/core/audio/FixedSizeStream.cpp @@ -52,7 +52,7 @@ static std::string TAG = "FixedSizeStream"; ((double) this->decoderSampleRate)); #define COPY_BUFFER(target, current, count, offset) \ - target->Copy(¤t->BufferPointer()[offset], count); \ + target->Copy(current->BufferPointer() + offset, count); \ SET_OFFSET(target, offset) \ FixedSizeStream::FixedSizeStream(int samplesPerChannel, int bufferCount, unsigned int options) diff --git a/src/core/audio/Player.cpp b/src/core/audio/Player.cpp index 36abe79cd..5d5d2a924 100644 --- a/src/core/audio/Player.cpp +++ b/src/core/audio/Player.cpp @@ -138,8 +138,12 @@ int Player::State() { } void Player::ThreadLoop() { - /* create and open the stream */ - this->stream = FixedSizeStream::Create(); + /* fixed size streams are better for visualizations because they provide + consistent buffer sizes. dynamic streams are more efficient otherwise + because we don't need to worry about manually chunking data, we can just + send audio data to the output straight from the decoder. */ + this->stream = vis::SelectedVisualizer() + ? FixedSizeStream::Create() : DynamicStream::Create(); BufferPtr buffer; diff --git a/src/core/library/Indexer.cpp b/src/core/library/Indexer.cpp index f1190ac3d..557791592 100644 --- a/src/core/library/Indexer.cpp +++ b/src/core/library/Indexer.cpp @@ -84,6 +84,7 @@ Indexer::Indexer(const std::string& libraryPath, const std::string& dbFilename) : thread(nullptr) , restart(false) , filesSaved(0) +, exit(false) , prefs(Preferences::ForComponent(prefs::components::Settings)) , readSemaphore(prefs->GetInt(prefs::keys::MaxTagReadThreads, MAX_THREADS)) { this->dbFilename = dbFilename;