Still broken (and disabled) scrub code

Originally committed to SVN as r461.
This commit is contained in:
Rodrigo Braz Monteiro 2006-07-04 07:00:58 +00:00
parent 4e464c97ad
commit 69330182b5
3 changed files with 45 additions and 11 deletions

View file

@ -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<bufSize;i++) buf[i] = temp[int(i*scale)];
// Scale
//float scale = float(scrubDelta) / float(bufSize);
//float start,end;
//int istart,iend;
//float tempfinal;
//for (int i=0;i<bufSize;i++) {
// start = i*scale;
// end = (i+1)*scale;
// istart = (int) start;
// iend = (int) end;
// if (istart == iend) tempfinal = temp[istart] * (end - start);
// else {
// tempfinal = temp[istart] * (1 + istart - start) + temp[iend] * (end - iend);
// for (int j=istart+1;j<iend;j++) tempfinal += temp[i];
// }
// buf[i] = tempfinal / scale;
//}
int len = MIN(bufSize,scrubDelta);
for (int i=0;i<len;i++) buf[i] = temp[i];
for (int i=len;i<bufSize;i++) buf[i] = 0;
delete temp;
// Invert

View file

@ -40,12 +40,17 @@
#include "utils.h"
#define BUFSIZE 8192
///////////////
// Constructor
StreamAudioProvider::StreamAudioProvider() {
bufLen = 8192;
startPos = 0;
endPos = 8192;
endPos = BUFSIZE;
buffered = 0;
hasBuf = false;
num_samples = 0xFFFFFFFFFFFFFF;
}
@ -67,16 +72,16 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
__int64 left = count;
__int64 written = 0;
int toWrite;
while (left > 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<count;i++) {
dst[i] = 0;
@ -109,18 +116,22 @@ void StreamAudioProvider::Append(void *src, __int64 count) {
int toRead;
while (left > 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;
}

View file

@ -61,6 +61,9 @@ private:
int endPos;
int bufLen;
int buffered;
bool hasBuf;
public:
StreamAudioProvider();
~StreamAudioProvider();