diff --git a/src/contrib/cddadecoder/CddaDecoder.cpp b/src/contrib/cddadecoder/CddaDecoder.cpp index e54986bb3..9c2961c7e 100644 --- a/src/contrib/cddadecoder/CddaDecoder.cpp +++ b/src/contrib/cddadecoder/CddaDecoder.cpp @@ -69,7 +69,7 @@ double CddaDecoder::SetPosition(double seconds) { bool CddaDecoder::GetBuffer(IBuffer *buffer) { int channels = data->GetChannelCount(); - buffer->SetSamples(CDDA_BUFFER_SIZE / BYTES_PER_RAW_SAMPLE / channels); + buffer->SetSamples(CDDA_BUFFER_SIZE / BYTES_PER_RAW_SAMPLE); buffer->SetChannels(data->GetChannelCount()); buffer->SetSampleRate(CDDA_SAMPLE_RATE); @@ -86,7 +86,7 @@ bool CddaDecoder::GetBuffer(IBuffer *buffer) { target[x] = (float) t[x] / 16384.0f; } - buffer->SetSamples(count / BYTES_PER_RAW_SAMPLE / channels); + buffer->SetSamples(count / BYTES_PER_RAW_SAMPLE); return true; } diff --git a/src/contrib/flacdecoder/FlacDecoder.cpp b/src/contrib/flacdecoder/FlacDecoder.cpp index 502c0c0be..be6cb93fc 100644 --- a/src/contrib/flacdecoder/FlacDecoder.cpp +++ b/src/contrib/flacdecoder/FlacDecoder.cpp @@ -234,7 +234,7 @@ bool FlacDecoder::GetBuffer(IBuffer *buffer) { /* read the next chunk */ if (FLAC__stream_decoder_process_single(this->decoder)) { if (this->outputBuffer && this->outputBufferUsed > 0) { - buffer->SetSamples(this->outputBufferUsed / this->channels); + buffer->SetSamples(this->outputBufferUsed); copy(buffer->BufferPointer(), this->outputBuffer, this->outputBufferUsed); this->outputBufferUsed = 0; /* mark consumed */ return true; diff --git a/src/contrib/m4adecoder/M4aDecoder.cpp b/src/contrib/m4adecoder/M4aDecoder.cpp index d61a16ad8..9c1d3267c 100644 --- a/src/contrib/m4adecoder/M4aDecoder.cpp +++ b/src/contrib/m4adecoder/M4aDecoder.cpp @@ -213,7 +213,7 @@ bool M4aDecoder::GetBuffer(IBuffer* target) { target->SetSampleRate(frameInfo.samplerate); target->SetChannels(frameInfo.channels); - target->SetSamples(frameInfo.samples / frameInfo.channels); + target->SetSamples(frameInfo.samples); memcpy( static_cast(target->BufferPointer()), diff --git a/src/contrib/mpg123decoder/Mpg123Decoder.cpp b/src/contrib/mpg123decoder/Mpg123Decoder.cpp index 98f32ed2d..f93487f1b 100644 --- a/src/contrib/mpg123decoder/Mpg123Decoder.cpp +++ b/src/contrib/mpg123decoder/Mpg123Decoder.cpp @@ -35,7 +35,7 @@ #include "Mpg123Decoder.h" #include -#define STREAM_FEED_SIZE 2048 * 8 +#define STREAM_FEED_SIZE 2048 * 2 #define DEBUG 0 #if DEBUG > 0 @@ -53,7 +53,7 @@ Mpg123Decoder::Mpg123Decoder() , fileStream(NULL) , lastMpg123Status(MPG123_NEED_MORE) { this->decoder = mpg123_new(NULL, NULL); - this->sampleSizeBytes = this->channels * sizeof(float); + this->sampleSizeBytes = sizeof(float); } Mpg123Decoder::~Mpg123Decoder() { @@ -103,7 +103,7 @@ double Mpg123Decoder::SetPosition(double second) { bool Mpg123Decoder::GetBuffer(IBuffer *buffer) { buffer->SetChannels(this->channels); buffer->SetSampleRate(this->sampleRate); - buffer->SetSamples(STREAM_FEED_SIZE / this->channels); + buffer->SetSamples(STREAM_FEED_SIZE); unsigned char* targetBuffer = (unsigned char*) (buffer->BufferPointer()); diff --git a/src/contrib/oggdecoder/OggDecoder.cpp b/src/contrib/oggdecoder/OggDecoder.cpp index 1a2d27206..8ed4030df 100644 --- a/src/contrib/oggdecoder/OggDecoder.cpp +++ b/src/contrib/oggdecoder/OggDecoder.cpp @@ -138,7 +138,7 @@ bool OggDecoder::GetBuffer(IBuffer *buffer) { vorbis_info *info = ov_info(&this->oggFile, -1); buffer->SetChannels(info->channels); buffer->SetSampleRate(info->rate); - buffer->SetSamples(samplesRead); + buffer->SetSamples(samplesRead * info->channels); /* The musik audio engine expects: diff --git a/src/contrib/waveout/WaveOutBuffer.cpp b/src/contrib/waveout/WaveOutBuffer.cpp index 621f7bb0b..fabf9c8e4 100644 --- a/src/contrib/waveout/WaveOutBuffer.cpp +++ b/src/contrib/waveout/WaveOutBuffer.cpp @@ -47,7 +47,7 @@ WaveOutBuffer::WaveOutBuffer(WaveOut *waveOut, IBuffer *buffer, IBufferProvider } void WaveOutBuffer::Initialize() { - this->header.dwBufferLength = this->buffer->Samples() * this->buffer->Channels() * sizeof(float); + this->header.dwBufferLength = this->buffer->Samples() * sizeof(float); this->header.lpData = (LPSTR) this->buffer->BufferPointer(); this->header.dwUser = (DWORD_PTR) this; this->header.dwBytesRecorded = 0; diff --git a/src/core/audio/Buffer.cpp b/src/core/audio/Buffer.cpp index 9c9e37650..83b9653ba 100644 --- a/src/core/audio/Buffer.cpp +++ b/src/core/audio/Buffer.cpp @@ -81,7 +81,7 @@ float* Buffer::BufferPointer() const { return this->buffer; } -long Buffer::Samples() const { /* pre-multiplied by channel count */ +long Buffer::Samples() const { return this->sampleSize; } @@ -98,21 +98,20 @@ void Buffer::CopyFormat(BufferPtr fromBuffer) { } void Buffer::ResizeBuffer() { - long requiredBufferSize = this->sampleSize * this->channels; - if (requiredBufferSize > this->internalBufferSize) { + if (this->sampleSize > this->internalBufferSize) { if (this->buffer) { delete this->buffer; this->buffer = NULL; } - this->buffer = new float[requiredBufferSize]; - this->internalBufferSize = requiredBufferSize; + this->buffer = new float[this->sampleSize]; + this->internalBufferSize = this->sampleSize; } } /* logical bytes; backing store may be be larger */ long Buffer::Bytes() const { - return sizeof(float) * this->sampleSize * this->channels; + return sizeof(float) * this->sampleSize; } double Buffer::Position() const { @@ -128,16 +127,16 @@ bool Buffer::Append(BufferPtr appendBuffer) { this->Channels() == appendBuffer->Channels()) { /* number of floats (not bytes) in buffer */ - long newBufferSize = (this->Samples() + appendBuffer->Samples()) * this->channels; + long newBufferSize = (this->Samples() + appendBuffer->Samples()); if (newBufferSize > this->internalBufferSize) { /* resize, then copy, if too small */ float *newBuffer = new float[newBufferSize]; - CopyFloat(newBuffer, this->buffer, this->sampleSize * this->channels); + CopyFloat(newBuffer, this->buffer, this->sampleSize); - float *dst = &newBuffer[this->sampleSize * this->channels]; + float *dst = &newBuffer[this->sampleSize]; float *src = appendBuffer->BufferPointer(); - long count = appendBuffer->Samples() * this->channels; + long count = appendBuffer->Samples(); CopyFloat(dst, src, count); @@ -151,9 +150,9 @@ bool Buffer::Append(BufferPtr appendBuffer) { this->internalBufferSize = newBufferSize; } else { /* append, no resize required */ - float *dst = &this->buffer[this->sampleSize * this->channels]; + float *dst = &this->buffer[this->sampleSize]; float *src = appendBuffer->BufferPointer(); - long count = appendBuffer->Samples() * this->channels; + long count = appendBuffer->Samples(); CopyFloat(dst, src, count); #if DEBUG > 0 @@ -161,7 +160,7 @@ bool Buffer::Append(BufferPtr appendBuffer) { #endif } - this->sampleSize = newBufferSize / this->channels; + this->sampleSize = newBufferSize; return true; } diff --git a/src/core/audio/Player.cpp b/src/core/audio/Player.cpp index 826bb642e..e3b206ce9 100644 --- a/src/core/audio/Player.cpp +++ b/src/core/audio/Player.cpp @@ -300,6 +300,7 @@ bool Player::Exited() { void Player::OnBufferProcessed(IBuffer *buffer) { bool started = false; bool found = false; + { boost::mutex::scoped_lock lock(this->queueMutex); @@ -314,17 +315,18 @@ void Player::OnBufferProcessed(IBuffer *buffer) { this->stream->OnBufferProcessedByPlayer(*it); } + bool isFront = this->lockedBuffers.front() == *it; it = this->lockedBuffers.erase(it); /* this sets the current time in the stream. it does this by grabbing the time at the next buffer in the queue */ - if (!this->lockedBuffers.empty()) { - this->currentPosition = this->lockedBuffers.front()->Position(); + if (this->lockedBuffers.empty() || isFront) { + this->currentPosition = ((Buffer*)buffer)->Position(); } else { /* if the queue is drained, use the position from the buffer that was just processed */ - this->currentPosition = ((Buffer*) buffer)->Position(); + this->currentPosition = this->lockedBuffers.front()->Position(); } /* if the output device's internal buffers are full, it will stop diff --git a/src/core/audio/Stream.cpp b/src/core/audio/Stream.cpp index 2461d5b00..c270cf1a9 100644 --- a/src/core/audio/Stream.cpp +++ b/src/core/audio/Stream.cpp @@ -147,7 +147,8 @@ BufferPtr Stream::GetNextBufferFromDecoder() { /* calculate the position (seconds) in the buffer */ buffer->SetPosition( - ((double) this->decoderSamplePosition) / + ((double) this->decoderSamplePosition) / + ((double) buffer->Channels()) / ((double) this->decoderSampleRate)); return buffer; diff --git a/src/musikbox/app/window/TransportWindow.cpp b/src/musikbox/app/window/TransportWindow.cpp index ad66d5441..64be8ecc0 100755 --- a/src/musikbox/app/window/TransportWindow.cpp +++ b/src/musikbox/app/window/TransportWindow.cpp @@ -60,7 +60,7 @@ using namespace boost::chrono; using namespace cursespp; #define REFRESH_TRANSPORT_READOUT 1001 -#define REFRESH_INTERVAL_MS 1000 +#define REFRESH_INTERVAL_MS 500 #define DEBOUNCE_REFRESH(x) \ this->RemoveMessage(REFRESH_TRANSPORT_READOUT); \