add seeking, update readme

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@135 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-05-16 20:57:19 +00:00
parent 599b28e497
commit 1e4e66ce3f
2 changed files with 37 additions and 5 deletions

View File

@ -6,11 +6,12 @@ line decoder called "test", and a simple Winamp plugin called "in_vgmstream".
--- test --- --- test ---
Usage: test.exe [-o outfile.wav] [-l loop count] Usage: test.exe [-o outfile.wav] [-l loop count]
[-f fade time] [-ipcmxeE] infile [-f fade time] [-d fade delay] [-ipPcmxeE] infile
Options: Options:
-o outfile.wav: name of output .wav file, default is dump.wav -o outfile.wav: name of output .wav file, default is dump.wav
-l loop count: loop count, default 2.0 -l loop count: loop count, default 2.0
-f fade time: fade time (seconds), default 10.0 -f fade time: fade time (seconds), default 10.0
-d fade delay: fade delay (seconds, default 0.0
-i: ignore looping information and play the whole stream once -i: ignore looping information and play the whole stream once
-p: output to stdout (for piping into another program) -p: output to stdout (for piping into another program)
-P: output to stdout even if stdout is a terminal -P: output to stdout even if stdout is a terminal
@ -25,8 +26,7 @@ test -o happy.wav happy.adx
to decode happy.adx to happy.wav. to decode happy.adx to happy.wav.
--- in_vgmstream --- --- in_vgmstream ---
Drop the in_vgmstream.dll in your Winamp plugins directory. There is no Drop the in_vgmstream.dll in your Winamp plugins directory.
configuration or seeking yet.
--- ---
File types supported by this version of vgmstream: File types supported by this version of vgmstream:

View File

@ -60,6 +60,7 @@ VGMSTREAM * vgmstream = NULL;
HANDLE decode_thread_handle = INVALID_HANDLE_VALUE; HANDLE decode_thread_handle = INVALID_HANDLE_VALUE;
int paused = 0; int paused = 0;
int decode_abort = 0; int decode_abort = 0;
int seek_needed_samples = -1;
int decode_pos_ms = 0; int decode_pos_ms = 0;
int decode_pos_samples = 0; int decode_pos_samples = 0;
int stream_length_samples = 0; int stream_length_samples = 0;
@ -172,7 +173,6 @@ int play(char *fn)
{ {
int max_latency; int max_latency;
/* don't lose a pointer! */ /* don't lose a pointer! */
if (vgmstream) { if (vgmstream) {
/* TODO: this should either pop up an error box or close the file */ /* TODO: this should either pop up an error box or close the file */
@ -214,6 +214,7 @@ int play(char *fn)
input_module.VSASetInfo(vgmstream->sample_rate,vgmstream->channels); input_module.VSASetInfo(vgmstream->sample_rate,vgmstream->channels);
decode_abort = 0; decode_abort = 0;
seek_needed_samples = -1;
decode_pos_ms = 0; decode_pos_ms = 0;
decode_pos_samples = 0; decode_pos_samples = 0;
paused = 0; paused = 0;
@ -274,7 +275,8 @@ int getoutputtime() {
/* seek */ /* seek */
void setoutputtime(int t) { void setoutputtime(int t) {
/* TODO: seeking */ if (vgmstream)
seek_needed_samples = (long long)t * vgmstream->sample_rate / 1000LL;
} }
/* pass these commands through */ /* pass these commands through */
@ -349,11 +351,34 @@ DWORD WINAPI __stdcall decode(void *arg) {
int samples_to_do; int samples_to_do;
int l; int l;
if (decode_pos_samples+576>stream_length_samples && !loop_forever) if (decode_pos_samples+576>stream_length_samples && !loop_forever)
samples_to_do=stream_length_samples-decode_pos_samples; samples_to_do=stream_length_samples-decode_pos_samples;
else else
samples_to_do=576; samples_to_do=576;
/* play 'till the end of this seek, or note if we're done seeking */
if (seek_needed_samples != -1) {
/* reset if we need to seek backwards */
if (seek_needed_samples < decode_pos_samples) {
VGMSTREAM * temp;
temp = vgmstream;
vgmstream = NULL;
close_vgmstream(temp);
temp = init_vgmstream(lastfn);
vgmstream = temp;
decode_pos_samples = 0;
decode_pos_ms = 0;
}
if (decode_pos_samples < seek_needed_samples) {
samples_to_do=seek_needed_samples-decode_pos_samples;
if (samples_to_do>576) samples_to_do=576;
} else
seek_needed_samples = -1;
}
l = (samples_to_do*vgmstream->channels*2)<<(input_module.dsp_isactive()?1:0); l = (samples_to_do*vgmstream->channels*2)<<(input_module.dsp_isactive()?1:0);
if (samples_to_do == 0) { if (samples_to_do == 0) {
@ -366,6 +391,13 @@ DWORD WINAPI __stdcall decode(void *arg) {
} }
Sleep(10); Sleep(10);
} }
else if (seek_needed_samples != -1) {
render_vgmstream(sample_buffer,samples_to_do,vgmstream);
input_module.outMod->Flush((int)decode_pos_ms);
decode_pos_samples+=samples_to_do;
decode_pos_ms=decode_pos_samples*1000LL/vgmstream->sample_rate;
}
else if (input_module.outMod->CanWrite() >= l) { else if (input_module.outMod->CanWrite() >= l) {
/* let vgmstream do its thing */ /* let vgmstream do its thing */
render_vgmstream(sample_buffer,samples_to_do,vgmstream); render_vgmstream(sample_buffer,samples_to_do,vgmstream);