mirror of https://github.com/odrling/Aegisub
somewhat working scrubbing
Originally committed to SVN as r462.
This commit is contained in:
parent
69330182b5
commit
4a5106daf0
|
@ -1201,7 +1201,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop scrubbing
|
// Stop scrubbing
|
||||||
bool scrubButton = false && event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
|
bool scrubButton = event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
|
||||||
if (scrubbing && !scrubButton) {
|
if (scrubbing && !scrubButton) {
|
||||||
// Release mouse
|
// Release mouse
|
||||||
scrubbing = false;
|
scrubbing = false;
|
||||||
|
@ -1214,7 +1214,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start scrubbing
|
// Start scrubbing
|
||||||
if (!scrubbing && scrubButton) {
|
if (!scrubbing && scrubButton && provider->GetChannels() == 1) {
|
||||||
// Get mouse
|
// Get mouse
|
||||||
CaptureMouse();
|
CaptureMouse();
|
||||||
scrubbing = true;
|
scrubbing = true;
|
||||||
|
@ -1233,8 +1233,8 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
// Scrub
|
// Scrub
|
||||||
if (scrubbing && scrubButton) {
|
if (scrubbing && scrubButton) {
|
||||||
// Get current data
|
// Get current data
|
||||||
__int64 curScrubPos = GetSampleAtX(x);
|
__int64 curScrubPos = MAX(0,GetSampleAtX(x));
|
||||||
__int64 scrubDelta = scrubLastPos - curScrubPos;
|
__int64 scrubDelta = curScrubPos - scrubLastPos;
|
||||||
int curScrubTime = clock();
|
int curScrubTime = clock();
|
||||||
int scrubDeltaTime = curScrubTime - scrubTime;
|
int scrubDeltaTime = curScrubTime - scrubTime;
|
||||||
|
|
||||||
|
@ -1242,7 +1242,6 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
if (scrubDelta != 0 && scrubDeltaTime > 0) {
|
if (scrubDelta != 0 && scrubDeltaTime > 0) {
|
||||||
// Create buffer
|
// Create buffer
|
||||||
int bufSize = scrubDeltaTime * scrubProvider->GetSampleRate() / CLK_TCK;
|
int bufSize = scrubDeltaTime * scrubProvider->GetSampleRate() / CLK_TCK;
|
||||||
scrubDelta = bufSize;
|
|
||||||
short *buf = new short[bufSize];
|
short *buf = new short[bufSize];
|
||||||
|
|
||||||
// Flag as inverted, if necessary
|
// Flag as inverted, if necessary
|
||||||
|
@ -1254,25 +1253,25 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),scrubDelta);
|
provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),scrubDelta);
|
||||||
|
|
||||||
// Scale
|
// Scale
|
||||||
//float scale = float(scrubDelta) / float(bufSize);
|
float scale = float(double(scrubDelta) / double(bufSize));
|
||||||
//float start,end;
|
float start,end;
|
||||||
//int istart,iend;
|
int istart,iend;
|
||||||
//float tempfinal;
|
float tempfinal;
|
||||||
//for (int i=0;i<bufSize;i++) {
|
for (int i=0;i<bufSize;i++) {
|
||||||
// start = i*scale;
|
start = i*scale;
|
||||||
// end = (i+1)*scale;
|
end = (i+1)*scale;
|
||||||
// istart = (int) start;
|
istart = (int) start;
|
||||||
// iend = (int) end;
|
iend = MIN((int) end,scrubDelta-1);
|
||||||
// if (istart == iend) tempfinal = temp[istart] * (end - start);
|
if (istart == iend) tempfinal = temp[istart] * (end - start);
|
||||||
// else {
|
else {
|
||||||
// tempfinal = temp[istart] * (1 + istart - start) + temp[iend] * (end - iend);
|
tempfinal = temp[istart] * (1 + istart - start) + temp[iend] * (end - iend);
|
||||||
// for (int j=istart+1;j<iend;j++) tempfinal += temp[i];
|
for (int j=istart+1;j<iend;j++) tempfinal += temp[i];
|
||||||
// }
|
}
|
||||||
// buf[i] = tempfinal / scale;
|
buf[i] = tempfinal / scale;
|
||||||
//}
|
}
|
||||||
int len = MIN(bufSize,scrubDelta);
|
//int len = MIN(bufSize,scrubDelta);
|
||||||
for (int i=0;i<len;i++) buf[i] = temp[i];
|
//for (int i=0;i<len;i++) buf[i] = temp[i];
|
||||||
for (int i=len;i<bufSize;i++) buf[i] = 0;
|
//for (int i=len;i<bufSize;i++) buf[i] = 0;
|
||||||
delete temp;
|
delete temp;
|
||||||
|
|
||||||
// Invert
|
// Invert
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
#define BUFSIZE 8192
|
#define BUFSIZE 65536
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
@ -70,11 +70,13 @@ StreamAudioProvider::~StreamAudioProvider() {
|
||||||
void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
// Write
|
// Write
|
||||||
__int64 left = count;
|
__int64 left = count;
|
||||||
__int64 written = 0;
|
int written = 0;
|
||||||
int toWrite;
|
int toWrite;
|
||||||
|
short *dst = (short*) buf;
|
||||||
while (hasBuf && left > 0) {
|
while (hasBuf && left > 0) {
|
||||||
// Discard done
|
// Discard done
|
||||||
if (startPos == BUFSIZE) {
|
if (startPos == BUFSIZE) {
|
||||||
|
delete buffer.front();
|
||||||
buffer.pop_front();
|
buffer.pop_front();
|
||||||
startPos = 0;
|
startPos = 0;
|
||||||
}
|
}
|
||||||
|
@ -85,8 +87,8 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
if (isLast) size = endPos;
|
if (isLast) size = endPos;
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
toWrite = MIN(int(size-startPos),int(left));
|
toWrite = MIN(size-startPos,int(left));
|
||||||
memcpy(((short*)buf)+written,&(buffer.front()->buf[startPos]),toWrite);
|
memcpy(dst+written,&(buffer.front()->buf[startPos]),toWrite*2);
|
||||||
startPos += toWrite;
|
startPos += toWrite;
|
||||||
written += toWrite;
|
written += toWrite;
|
||||||
left -= toWrite;
|
left -= toWrite;
|
||||||
|
@ -99,7 +101,6 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
// Still left, fill with zero
|
// Still left, fill with zero
|
||||||
if (left > 0) {
|
if (left > 0) {
|
||||||
hasBuf = false;
|
hasBuf = false;
|
||||||
short *dst = (short*) buf;
|
|
||||||
for (__int64 i=written;i<count;i++) {
|
for (__int64 i=written;i<count;i++) {
|
||||||
dst[i] = 0;
|
dst[i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -109,11 +110,12 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// Append audio to stream
|
// Append audio to stream
|
||||||
void StreamAudioProvider::Append(void *src, __int64 count) {
|
void StreamAudioProvider::Append(void *voidptr, __int64 count) {
|
||||||
// Read
|
// Read
|
||||||
__int64 left = count;
|
__int64 left = count;
|
||||||
__int64 read = 0;
|
int read = 0;
|
||||||
int toRead;
|
int toRead;
|
||||||
|
short *src = (short*) voidptr;
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
// Check space
|
// Check space
|
||||||
if (endPos == BUFSIZE) {
|
if (endPos == BUFSIZE) {
|
||||||
|
@ -123,7 +125,7 @@ void StreamAudioProvider::Append(void *src, __int64 count) {
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
toRead = MIN(int(BUFSIZE-endPos),int(left));
|
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;
|
endPos += toRead;
|
||||||
read += toRead;
|
read += toRead;
|
||||||
buffered += toRead;
|
buffered += toRead;
|
||||||
|
|
Loading…
Reference in New Issue