summaryrefslogtreecommitdiff
path: root/cdumb.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-07-19 11:50:00 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-07-19 11:59:03 +0200
commit051a79c282355c72ea08c7598b7f4c1b58526e30 (patch)
tree88cb5c8040652f25288c23e4914e4c554c2b87b8 /cdumb.c
parentbe5c03f0510d62bb86c9a11b77977123239b2c7e (diff)
fixed dumb seeking
Diffstat (limited to 'cdumb.c')
-rw-r--r--cdumb.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/cdumb.c b/cdumb.c
index 66e1d0c2..ff10bfa8 100644
--- a/cdumb.c
+++ b/cdumb.c
@@ -21,6 +21,9 @@ void
cdumb_free (void);
int
+cdumb_startrenderer (void);
+
+int
cdumb_init (const char *fname, int track, float start, float end) {
if (!dumb_initialized) {
atexit (&dumb_exit);
@@ -46,26 +49,38 @@ cdumb_init (const char *fname, int track, float start, float end) {
else {
return -1;
}
+ dumb_it_do_initial_runthrough (myduh);
+
+ cdumb.info.bitsPerSample = 16;
+ cdumb.info.channels = 2;
+ cdumb.info.samplesPerSecond = sdl_player_freq;
+ cdumb.info.position = 0;
+ cdumb.info.duration = duh_get_length (myduh)/65536.0f;
+ printf ("duration: %f\n", cdumb.info.duration);
+
+ cdumb_startrenderer ();
+
+ return 0;
+}
+
+int
+cdumb_startrenderer (void) {
+ // reopen
+ if (renderer) {
+ duh_end_sigrenderer (renderer);
+ renderer = NULL;
+ }
renderer = duh_start_sigrenderer (myduh, 0, 2, 0);
if (!renderer) {
cdumb_free ();
return -1;
}
+
DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer (renderer);
dumb_it_set_loop_callback (itsr, &dumb_it_callback_terminate, NULL);
dumb_it_set_resampling_quality (itsr, 2);
dumb_it_set_xm_speed_zero_callback (itsr, &dumb_it_callback_terminate, NULL);
dumb_it_set_global_volume_zero_callback (itsr, &dumb_it_callback_terminate, NULL);
-
- dumb_it_do_initial_runthrough (myduh);
-
- cdumb.info.bitsPerSample = 16;
- cdumb.info.channels = 2;
- cdumb.info.samplesPerSecond = sdl_player_freq;
- cdumb.info.position = 0;
- cdumb.info.duration = duh_get_length (myduh)/65536.0f;
- printf ("duration: %f\n", cdumb.info.duration);
- return 0;
}
void
@@ -91,9 +106,15 @@ cdumb_read (char *bytes, int size) {
int
cdumb_seek (float time) {
+ if (time < cdumb.info.position) {
+ cdumb_startrenderer ();
+ }
+ else {
+ time -= cdumb.info.position;
+ }
int pos = time * cdumb.info.samplesPerSecond;
duh_sigrenderer_generate_samples (renderer, 0, 65536.0f / cdumb.info.samplesPerSecond, pos, NULL);
- cdumb.info.position = time;
+ cdumb.info.position = duh_sigrenderer_get_position (renderer) / 65536.f;
return 0;
}