Quite broken scrubbing implemented

Originally committed to SVN as r460.
This commit is contained in:
Rodrigo Braz Monteiro 2006-07-04 06:13:54 +00:00
parent 41a4cd3c2c
commit 4e464c97ad
4 changed files with 97 additions and 4 deletions

View file

@ -38,6 +38,7 @@
// Headers // Headers
#include <wx/tglbtn.h> #include <wx/tglbtn.h>
#include "audio_display.h" #include "audio_display.h"
#include "audio_provider_stream.h"
#include "main.h" #include "main.h"
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "subs_grid.h" #include "subs_grid.h"
@ -77,6 +78,7 @@ AudioDisplay::AudioDisplay(wxWindow *parent,VideoDisplay *display)
dontReadTimes = false; dontReadTimes = false;
holding = false; holding = false;
draggingScale = false; draggingScale = false;
scrubbing = false;
Position = 0; Position = 0;
PositionSample = 0; PositionSample = 0;
oldCurPos = 0; oldCurPos = 0;
@ -1195,7 +1197,86 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
} }
if (!event.ButtonIsDown(wxMOUSE_BTN_LEFT) && holding) { if (!event.ButtonIsDown(wxMOUSE_BTN_LEFT) && holding) {
holding = false; holding = false;
ReleaseMouse(); if (HasCapture()) ReleaseMouse();
}
// Stop scrubbing
bool scrubButton = event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
if (scrubbing && !scrubButton) {
// Release mouse
scrubbing = false;
if (HasCapture()) ReleaseMouse();
// Stop player
player->Stop();
player->SetProvider(provider);
delete scrubProvider;
}
// Start scrubbing
if (!scrubbing && scrubButton) {
// Get mouse
CaptureMouse();
scrubbing = true;
// Initialize provider
player->Stop();
scrubProvider = new StreamAudioProvider();
scrubProvider->SetParams(provider->GetChannels(),provider->GetSampleRate(),provider->GetBytesPerSample());
player->SetProvider(scrubProvider);
// Set variables
scrubLastPos = GetSampleAtX(x);
scrubTime = clock();
}
// Scrub
if (scrubbing && scrubButton) {
// Get current data
__int64 curScrubPos = GetSampleAtX(x);
__int64 scrubDelta = scrubLastPos - curScrubPos;
int curScrubTime = clock();
int scrubDeltaTime = curScrubTime - scrubTime;
// Copy data to buffer
if (scrubDelta != 0 && scrubDeltaTime > 0) {
// Create buffer
int bufSize = scrubDeltaTime * scrubProvider->GetSampleRate() / CLK_TCK;
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
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)];
delete temp;
// Invert
if (invert) {
short aux;
for (int i=0;i<bufSize/2;i++) {
aux = buf[i];
buf[i] = buf[bufSize-i-1];
buf[bufSize-i-1] = aux;
}
}
// Send data to provider
scrubProvider->Append(buf,bufSize);
if (!player->IsPlaying()) player->Play(0,0xFFFFFFFFFFFF);
delete buf;
}
// Update last pos and time
scrubLastPos = curScrubPos;
scrubTime = curScrubTime;
// Return
return;
} }
// Mouse wheel // Mouse wheel

View file

@ -48,6 +48,7 @@
////////////// //////////////
// Prototypes // Prototypes
class AssDialogue; class AssDialogue;
class StreamAudioProvider;
class SubtitlesGrid; class SubtitlesGrid;
class AudioBox; class AudioBox;
class AudioKaraoke; class AudioKaraoke;
@ -98,7 +99,7 @@ private:
int *min; int *min;
int scrubTime; int scrubTime;
int scrubLastPos; __int64 scrubLastPos;
bool scrubbing; bool scrubbing;
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
@ -119,7 +120,7 @@ private:
public: public:
AudioProvider *provider; AudioProvider *provider;
AudioProvider *scrubProvider; StreamAudioProvider *scrubProvider;
AudioPlayer *player; AudioPlayer *player;
bool NeedCommit; bool NeedCommit;

View file

@ -46,6 +46,7 @@ StreamAudioProvider::StreamAudioProvider() {
bufLen = 8192; bufLen = 8192;
startPos = 0; startPos = 0;
endPos = 8192; endPos = 8192;
num_samples = 0xFFFFFFFFFFFFFF;
} }
@ -123,9 +124,18 @@ void StreamAudioProvider::Append(void *src, __int64 count) {
} }
//////////////////
// Set parameters
void StreamAudioProvider::SetParams(int chan,int rate,int bps) {
channels = chan;
sample_rate = rate;
bytes_per_sample = bps;
}
//////////////////////////// ////////////////////////////
// Buffer chunk constructor // Buffer chunk constructor
StreamAudioProvider::BufferChunk::BufferChunk() { StreamAudioProvider::BufferChunk::BufferChunk() {
buf.resize(4096); buf.resize(8192);
isFree = true; isFree = true;
} }

View file

@ -67,4 +67,5 @@ public:
void GetAudio(void *buf, __int64 start, __int64 count); void GetAudio(void *buf, __int64 start, __int64 count);
void Append(void *buf, __int64 count); void Append(void *buf, __int64 count);
void SetParams(int channels,int rate,int bps);
}; };