mirror of https://github.com/odrling/Aegisub
Still broken (and disabled) scrub code
Originally committed to SVN as r461.
This commit is contained in:
parent
4e464c97ad
commit
69330182b5
|
@ -1201,7 +1201,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop scrubbing
|
// Stop scrubbing
|
||||||
bool scrubButton = event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
|
bool scrubButton = false && event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
|
||||||
if (scrubbing && !scrubButton) {
|
if (scrubbing && !scrubButton) {
|
||||||
// Release mouse
|
// Release mouse
|
||||||
scrubbing = false;
|
scrubbing = false;
|
||||||
|
@ -1242,17 +1242,37 @@ 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
|
||||||
bool invert = scrubDelta < 0;
|
bool invert = scrubDelta < 0;
|
||||||
if (invert) scrubDelta = -scrubDelta;
|
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];
|
short *temp = new short[scrubDelta];
|
||||||
provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),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;
|
delete temp;
|
||||||
|
|
||||||
// Invert
|
// Invert
|
||||||
|
|
|
@ -40,12 +40,17 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define BUFSIZE 8192
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
StreamAudioProvider::StreamAudioProvider() {
|
StreamAudioProvider::StreamAudioProvider() {
|
||||||
bufLen = 8192;
|
bufLen = 8192;
|
||||||
startPos = 0;
|
startPos = 0;
|
||||||
endPos = 8192;
|
endPos = BUFSIZE;
|
||||||
|
buffered = 0;
|
||||||
|
hasBuf = false;
|
||||||
num_samples = 0xFFFFFFFFFFFFFF;
|
num_samples = 0xFFFFFFFFFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,16 +72,16 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
__int64 left = count;
|
__int64 left = count;
|
||||||
__int64 written = 0;
|
__int64 written = 0;
|
||||||
int toWrite;
|
int toWrite;
|
||||||
while (left > 0) {
|
while (hasBuf && left > 0) {
|
||||||
// Discard done
|
// Discard done
|
||||||
if (startPos == 8192) {
|
if (startPos == BUFSIZE) {
|
||||||
buffer.pop_front();
|
buffer.pop_front();
|
||||||
startPos = 0;
|
startPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is last?
|
// Is last?
|
||||||
bool isLast = buffer.size() == 1;
|
bool isLast = buffer.size() == 1;
|
||||||
int size = 8192;
|
int size = BUFSIZE;
|
||||||
if (isLast) size = endPos;
|
if (isLast) size = endPos;
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
|
@ -85,6 +90,7 @@ void StreamAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
startPos += toWrite;
|
startPos += toWrite;
|
||||||
written += toWrite;
|
written += toWrite;
|
||||||
left -= toWrite;
|
left -= toWrite;
|
||||||
|
buffered -= toWrite;
|
||||||
|
|
||||||
// Last
|
// Last
|
||||||
if (isLast) break;
|
if (isLast) break;
|
||||||
|
@ -92,6 +98,7 @@ 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;
|
||||||
short *dst = (short*) buf;
|
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,18 +116,22 @@ void StreamAudioProvider::Append(void *src, __int64 count) {
|
||||||
int toRead;
|
int toRead;
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
// Check space
|
// Check space
|
||||||
if (endPos == 8192) {
|
if (endPos == BUFSIZE) {
|
||||||
buffer.push_back(new BufferChunk);
|
buffer.push_back(new BufferChunk);
|
||||||
endPos = 0;
|
endPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
toRead = MIN(int(8192-endPos),int(left));
|
toRead = MIN(int(BUFSIZE-endPos),int(left));
|
||||||
memcpy(&(buffer.back()->buf[endPos]),((short*)src)+read,toRead);
|
memcpy(&(buffer.back()->buf[endPos]),((short*)src)+read,toRead);
|
||||||
endPos += toRead;
|
endPos += toRead;
|
||||||
read += toRead;
|
read += toRead;
|
||||||
|
buffered += toRead;
|
||||||
left -= 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
|
// Buffer chunk constructor
|
||||||
StreamAudioProvider::BufferChunk::BufferChunk() {
|
StreamAudioProvider::BufferChunk::BufferChunk() {
|
||||||
buf.resize(8192);
|
buf.resize(BUFSIZE);
|
||||||
isFree = true;
|
isFree = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ private:
|
||||||
int endPos;
|
int endPos;
|
||||||
int bufLen;
|
int bufLen;
|
||||||
|
|
||||||
|
int buffered;
|
||||||
|
bool hasBuf;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StreamAudioProvider();
|
StreamAudioProvider();
|
||||||
~StreamAudioProvider();
|
~StreamAudioProvider();
|
||||||
|
|
Loading…
Reference in New Issue