From 0d4951c36ca179d1500314ec23979991270e1fa7 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Fri, 17 Jul 2009 23:00:50 +0200 Subject: DUMB module playback WIP --- cdumb.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 cdumb.c (limited to 'cdumb.c') diff --git a/cdumb.c b/cdumb.c new file mode 100644 index 00000000..07fc159b --- /dev/null +++ b/cdumb.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include "dumb/dumb-0.9.3/include/dumb.h" +#include "codec.h" +#include "cdumb.h" +#include "playlist.h" + +extern int sdl_player_freq; // hack! +static int dumb_initialized; +static DUH *myduh; +static DUH_SIGRENDERER *renderer; +//#define DUMB_RQ_ALIASING +//#define DUMB_RQ_LINEAR +//#define DUMB_RQ_CUBIC +//#define DUMB_RQ_N_LEVELS +extern int dumb_resampling_quality; +extern int dumb_it_max_to_mix; + +void +cdumb_free (void); + +int +cdumb_init (const char *fname, int track, float start, float end) { + if (!dumb_initialized) { + atexit (&dumb_exit); + } + dumb_register_stdfiles (); + const char *ext = fname + strlen (fname) - 1; + while (*ext != '.' && ext > fname) { + ext--; + } + ext++; + if (!strcasecmp (ext, "mod")) { + myduh = dumb_load_mod_quick (fname); + } + else if (!strcasecmp (ext, "s3m")) { + myduh = dumb_load_s3m_quick (fname); + } + else if (!strcasecmp (ext, "it")) { + myduh = dumb_load_it_quick (fname); + } + else if (!strcasecmp (ext, "xm")) { + myduh = dumb_load_xm_quick (fname); + } + else { + return -1; + } + renderer = duh_start_sigrenderer (myduh, 0, 2, 0); + if (!renderer) { + cdumb_free (); + 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); + return 0; +} + +void +cdumb_free (void) { + if (renderer) { + duh_end_sigrenderer (renderer); + renderer = NULL; + } + if (myduh) { + unload_duh (myduh); + myduh = NULL; + } +} + +int +cdumb_read (char *bytes, int size) { + int length = size / 4; + long ret; + ret = duh_render (renderer, 16, 0, 1, 65536.f / cdumb.info.samplesPerSecond, length, bytes); + cdumb.info.position += ret / (float)cdumb.info.samplesPerSecond; + return ret*4; +} + +int +cdumb_seek (float time) { + int pos = time * cdumb.info.samplesPerSecond; + duh_sigrenderer_generate_samples (renderer, 0, 65536.0f / cdumb.info.samplesPerSecond, pos, NULL); + cdumb.info.position = time; + return 0; +} + +int +cdumb_add (const char *fname) { + return 0; +} + +codec_t cdumb = { + .init = cdumb_init, + .free = cdumb_free, + .read = cdumb_read, + .seek = cdumb_seek, + .add = cdumb_add +}; + -- cgit v1.2.3