somewhat working scrubbing
Originally committed to SVN as r462.
This commit is contained in:
parent
69330182b5
commit
4a5106daf0
2 changed files with 33 additions and 32 deletions
|
@ -1201,7 +1201,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
|||
}
|
||||
|
||||
// Stop scrubbing
|
||||
bool scrubButton = false && event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
|
||||
bool scrubButton = event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
|
||||
if (scrubbing && !scrubButton) {
|
||||
// Release mouse
|
||||
scrubbing = false;
|
||||
|
@ -1214,7 +1214,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
|||
}
|
||||
|
||||
// Start scrubbing
|
||||
if (!scrubbing && scrubButton) {
|
||||
if (!scrubbing && scrubButton && provider->GetChannels() == 1) {
|
||||
// Get mouse
|
||||
CaptureMouse();
|
||||
scrubbing = true;
|
||||
|
@ -1233,8 +1233,8 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
|||
// Scrub
|
||||
if (scrubbing && scrubButton) {
|
||||
// Get current data
|
||||
__int64 curScrubPos = GetSampleAtX(x);
|
||||
__int64 scrubDelta = scrubLastPos - curScrubPos;
|
||||
__int64 curScrubPos = MAX(0,GetSampleAtX(x));
|
||||
__int64 scrubDelta = curScrubPos - scrubLastPos;
|
||||
int curScrubTime = clock();
|
||||
int scrubDeltaTime = curScrubTime - scrubTime;
|
||||
|
||||
|
@ -1242,7 +1242,6 @@ 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
|
||||
|
@ -1254,25 +1253,25 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
|||
provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),scrubDelta);
|
||||
|
||||
// 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;
|
||||
float scale = float(double(scrubDelta) / double(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 = MIN((int) end,scrubDelta-1);
|
||||
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
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "utils.h"
|
||||
|
||||
|
||||
#define BUFSIZE 8192
|
||||
#define BUFSIZE 65536
|
||||
|
||||
|
||||
///////////////
|
||||
|
@ -70,11 +70,13 @@ StreamAudioProvider::~StreamAudioProvider() {
|
|||
void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||
// Write
|
||||
__int64 left = count;
|
||||
__int64 written = 0;
|
||||
int written = 0;
|
||||
int toWrite;
|
||||
short *dst = (short*) buf;
|
||||
while (hasBuf && left > 0) {
|
||||
// Discard done
|
||||
if (startPos == BUFSIZE) {
|
||||
delete buffer.front();
|
||||
buffer.pop_front();
|
||||
startPos = 0;
|
||||
}
|
||||
|
@ -85,8 +87,8 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
|||
if (isLast) size = endPos;
|
||||
|
||||
// Write
|
||||
toWrite = MIN(int(size-startPos),int(left));
|
||||
memcpy(((short*)buf)+written,&(buffer.front()->buf[startPos]),toWrite);
|
||||
toWrite = MIN(size-startPos,int(left));
|
||||
memcpy(dst+written,&(buffer.front()->buf[startPos]),toWrite*2);
|
||||
startPos += toWrite;
|
||||
written += toWrite;
|
||||
left -= toWrite;
|
||||
|
@ -99,7 +101,6 @@ 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,11 +110,12 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
|||
|
||||
//////////////////////////
|
||||
// Append audio to stream
|
||||
void StreamAudioProvider::Append(void *src, __int64 count) {
|
||||
void StreamAudioProvider::Append(void *voidptr, __int64 count) {
|
||||
// Read
|
||||
__int64 left = count;
|
||||
__int64 read = 0;
|
||||
int read = 0;
|
||||
int toRead;
|
||||
short *src = (short*) voidptr;
|
||||
while (left > 0) {
|
||||
// Check space
|
||||
if (endPos == BUFSIZE) {
|
||||
|
@ -123,7 +125,7 @@ void StreamAudioProvider::Append(void *src, __int64 count) {
|
|||
|
||||
// Read
|
||||
toRead = MIN(int(BUFSIZE-endPos),int(left));
|
||||
memcpy(&(buffer.back()->buf[endPos]),((short*)src)+read,toRead);
|
||||
memcpy(&(buffer.back()->buf[endPos]),src+read,toRead*2);
|
||||
endPos += toRead;
|
||||
read += toRead;
|
||||
buffered += toRead;
|
||||
|
|
Loading…
Reference in a new issue