diff --git a/core/audio_display.cpp b/core/audio_display.cpp index d1ea9f013..573777c4e 100644 --- a/core/audio_display.cpp +++ b/core/audio_display.cpp @@ -1201,7 +1201,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) { } // Stop scrubbing - bool scrubButton = event.ButtonIsDown(wxMOUSE_BTN_MIDDLE); + bool scrubButton = false && event.ButtonIsDown(wxMOUSE_BTN_MIDDLE); if (scrubbing && !scrubButton) { // Release mouse scrubbing = false; @@ -1242,17 +1242,37 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) { if (scrubDelta != 0 && scrubDeltaTime > 0) { // Create buffer int bufSize = scrubDeltaTime * scrubProvider->GetSampleRate() / CLK_TCK; + scrubDelta = bufSize; short *buf = new short[bufSize]; // Flag as inverted, if necessary bool invert = scrubDelta < 0; if (invert) scrubDelta = -scrubDelta; - // Copy data from original provider to buffer and normalize it + // Copy data from original provider to temp buffer short *temp = new short[scrubDelta]; provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),scrubDelta); - float scale = float(scrubDelta) / float(bufSize); - for (int i=0;i 0) { + while (hasBuf && left > 0) { // Discard done - if (startPos == 8192) { + if (startPos == BUFSIZE) { buffer.pop_front(); startPos = 0; } // Is last? bool isLast = buffer.size() == 1; - int size = 8192; + int size = BUFSIZE; if (isLast) size = endPos; // Write @@ -85,6 +90,7 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) { startPos += toWrite; written += toWrite; left -= toWrite; + buffered -= toWrite; // Last if (isLast) break; @@ -92,6 +98,7 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) { // Still left, fill with zero if (left > 0) { + hasBuf = false; short *dst = (short*) buf; for (__int64 i=written;i 0) { // Check space - if (endPos == 8192) { + if (endPos == BUFSIZE) { buffer.push_back(new BufferChunk); endPos = 0; } // Read - toRead = MIN(int(8192-endPos),int(left)); + toRead = MIN(int(BUFSIZE-endPos),int(left)); memcpy(&(buffer.back()->buf[endPos]),((short*)src)+read,toRead); endPos += toRead; read += toRead; + buffered += toRead; left -= toRead; } + + // Set buffered status + if (buffered > bufLen) hasBuf = true; } @@ -136,6 +147,6 @@ void StreamAudioProvider::SetParams(int chan,int rate,int bps) { //////////////////////////// // Buffer chunk constructor StreamAudioProvider::BufferChunk::BufferChunk() { - buf.resize(8192); + buf.resize(BUFSIZE); isFree = true; } diff --git a/core/audio_provider_stream.h b/core/audio_provider_stream.h index 648ad9507..01feeae05 100644 --- a/core/audio_provider_stream.h +++ b/core/audio_provider_stream.h @@ -61,6 +61,9 @@ private: int endPos; int bufLen; + int buffered; + bool hasBuf; + public: StreamAudioProvider(); ~StreamAudioProvider();