diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-08-05 23:23:44 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-08-05 23:23:44 +0200 |
commit | 337d90098cf48c6e3600f321081492e33cc48229 (patch) | |
tree | ef0d26f051f02cfcf1b96a10fffbd92976c52990 | |
parent | 8f749dbc5721172d1e5cf9742955fb429fa0062a (diff) |
alsa playback WIP
-rw-r--r-- | Jamfile | 5 | ||||
-rw-r--r-- | callbacks.c | 4 | ||||
-rw-r--r-- | cdumb.c | 4 | ||||
-rw-r--r-- | cgme.c | 6 | ||||
-rw-r--r-- | csid.cpp | 8 | ||||
-rw-r--r-- | gtkplaylist.c | 16 | ||||
-rw-r--r-- | main.c | 12 | ||||
-rw-r--r-- | playback.h | 28 | ||||
-rw-r--r-- | psdl.c | 8 | ||||
-rw-r--r-- | psdl.h | 3 | ||||
-rw-r--r-- | streamer.c | 14 |
11 files changed, 73 insertions, 35 deletions
@@ -5,6 +5,7 @@ SubInclude ROOT sidplay-libs-2.1.0 ; SubDir ROOT ; CCFLAGS += -D_GNU_SOURCE ; CCFLAGS += -std=c99 ; +#CCFLAGS += -DUSE_SDL ; # CCFLAGS += -D_REENTRANT ; OPTIM += -O0 ; OPTIM += -g ; @@ -20,8 +21,8 @@ HDRS += $(ROOT)/sidplay-libs-2.1.0/libsidplay/include ; HDRS += $(ROOT)/sidplay-libs-2.1.0/builders/resid-builder/include ; Main deadbeef : - codec.c cvorbis.c cmp3.c cgme.c cdumb.c cwav.c cflac.c csid.cpp playlist.c psdl.c streamer.c md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c ; + codec.c cvorbis.c cmp3.c cgme.c cdumb.c cwav.c cflac.c csid.cpp playlist.c psdl.c palsa.c streamer.c md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c ; -LINKLIBS on deadbeef = -lm -lvorbis -logg -lvorbisfile -lmad -lFLAC -lSDL -lsamplerate -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lgthread-2.0 -lstdc++ ; +LINKLIBS on deadbeef = -lm -lvorbis -logg -lvorbisfile -lmad -lFLAC -lSDL -lsamplerate -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lgthread-2.0 -lstdc++ -lasound ; LinkLibraries deadbeef : libgme libdumb libsidplay ; diff --git a/callbacks.c b/callbacks.c index c38e82b9..3418280a 100644 --- a/callbacks.c +++ b/callbacks.c @@ -13,12 +13,12 @@ #include "common.h" -#include "psdl.h" #include "playlist.h" #include "gtkplaylist.h" #include "messagepump.h" #include "messages.h" #include "codec.h" +#include "playback.h" extern GtkWidget *mainwin; @@ -35,7 +35,7 @@ on_volume_value_changed (GtkRange *range, { float db = -(60 - (gtk_range_get_value (range) * 0.6f)); float a = db <= -60.f ? 0 : pow (10, db/20.f); - psdl_set_volume (a); + p_set_volume (a); } int g_disable_seekbar_handler = 0; @@ -5,8 +5,8 @@ #include "codec.h" #include "cdumb.h" #include "playlist.h" +#include "playback.h" -extern int sdl_player_freq; // hack! static int dumb_initialized; static DUH *duh; static DUH_SIGRENDERER *renderer; @@ -75,7 +75,7 @@ cdumb_init (const char *fname, int track, float start, float end) { cdumb.info.bitsPerSample = 16; cdumb.info.channels = 2; - cdumb.info.samplesPerSecond = sdl_player_freq; + cdumb.info.samplesPerSecond = p_get_rate (); cdumb.info.position = 0; cdumb.info.duration = duh_get_length (duh)/65536.0f; printf ("duration: %f\n", cdumb.info.duration); @@ -5,16 +5,16 @@ #include "codec.h" #include "cgme.h" #include "playlist.h" +#include "playback.h" static Music_Emu *emu; static int reallength; static int nzerosamples; -extern int sdl_player_freq; // hack! static uint32_t cgme_voicemask = 0; int cgme_init (const char *fname, int track, float start, float end) { - if (gme_open_file (fname, &emu, sdl_player_freq)) { + if (gme_open_file (fname, &emu, p_get_rate ())) { return -1; } gme_mute_voices (emu, cgme_voicemask); @@ -23,7 +23,7 @@ cgme_init (const char *fname, int track, float start, float end) { gme_track_info (emu, &inf, track); cgme.info.bitsPerSample = 16; cgme.info.channels = 2; - cgme.info.samplesPerSecond = sdl_player_freq; + cgme.info.samplesPerSecond = p_get_rate (); reallength = inf.length; nzerosamples = 0; if (inf.length == -1) { @@ -10,6 +10,7 @@ extern "C" { #include "csid.h" #include "md5.h" #include "common.h" +#include "playback.h" } static inline void @@ -28,7 +29,6 @@ static sidplay2 *sidplay; static ReSIDBuilder *resid; static SidTune *tune; static uint32_t csid_voicemask = 0; -extern int sdl_player_freq; // hack! // SLDB support costs ~1M!!! // current hvsc sldb size is ~35k songs #define SLDB_MAX_SONGS 40000 @@ -218,7 +218,7 @@ csid_init (const char *fname, int track, float start, float end) { resid->create (sidplay->info ().maxsids); // resid->create (1); resid->filter (true); - resid->sampling (sdl_player_freq); + resid->sampling (p_get_rate ()); tune = new SidTune (fname); // calc md5 uint8_t sig[16]; @@ -247,7 +247,7 @@ csid_init (const char *fname, int track, float start, float end) { csid.info.channels = tune->isStereo () ? 2 : 1; sid2_config_t conf; conf = sidplay->config (); - conf.frequency = sdl_player_freq; + conf.frequency = p_get_rate (); conf.precision = 16; conf.playback = csid.info.channels == 2 ? sid2_stereo : sid2_mono; conf.sidEmulation = resid; @@ -255,7 +255,7 @@ csid_init (const char *fname, int track, float start, float end) { sidplay->config (conf); sidplay->load (tune); csid.info.bitsPerSample = 16; - csid.info.samplesPerSecond = sdl_player_freq; + csid.info.samplesPerSecond = p_get_rate (); csid.info.position = 0; float length = 120; sldb_load(sldb_fname); diff --git a/gtkplaylist.c b/gtkplaylist.c index ebc802f6..99e94462 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -14,7 +14,7 @@ #include "interface.h" #include "support.h" #include "playlist.h" -#include "psdl.h" +#include "playback.h" #include "codec.h" #include "common.h" #include "messagepump.h" @@ -461,9 +461,9 @@ gtkps_scroll (int newscroll) { void gtkps_playsong (void) { - if (psdl_ispaused ()) { + if (p_ispaused ()) { printf ("unpause\n"); - psdl_unpause (); + p_unpause (); } else if (playlist_current_ptr) { printf ("restart\n"); @@ -573,16 +573,16 @@ gtkps_randomsong (void) { void gtkps_stopsong (void) { - psdl_stop (); + p_stop (); } void gtkps_pausesong (void) { - if (psdl_ispaused ()) { - psdl_unpause (); + if (p_ispaused ()) { + p_unpause (); } else { - psdl_pause (); + p_pause (); } } @@ -620,7 +620,7 @@ gtkps_update_songinfo (void) { } char sbtext_new[512] = "-"; int songpos = 0; - if (psdl_ispaused ()) { + if (p_ispaused ()) { strcpy (sbtext_new, "Paused"); songpos = 0; } @@ -4,7 +4,7 @@ #include "interface.h" #include "support.h" #include "playlist.h" -#include "psdl.h" +#include "playback.h" #include "unistd.h" #include "threading.h" #include "messagepump.h" @@ -19,7 +19,7 @@ int psdl_terminate = 0; void psdl_thread (uintptr_t ctx) { - psdl_play (); + p_play (); while (!psdl_terminate) { uint32_t msg; uintptr_t ctx; @@ -73,11 +73,11 @@ psdl_thread (uintptr_t ctx) { break; case M_SONGSEEK: if (playlist_current.codec) { - psdl_pause (); + p_pause (); codec_lock (); playlist_current.codec->seek (p1 / 1000.f); codec_unlock (); - psdl_unpause (); + p_unpause (); } break; } @@ -93,7 +93,7 @@ main (int argc, char *argv[]) { messagepump_init (); codec_init_locking (); streamer_init (); - psdl_init (); + p_init (); thread_start (psdl_thread, 0); g_thread_init (NULL); @@ -108,7 +108,7 @@ main (int argc, char *argv[]) { gdk_threads_leave (); messagepump_free (); psdl_terminate = 1; - psdl_free (); + p_free (); streamer_free (); codec_free_locking (); ps_free (); diff --git a/playback.h b/playback.h new file mode 100644 index 00000000..c58841ae --- /dev/null +++ b/playback.h @@ -0,0 +1,28 @@ +#ifndef __PLAYBACK_H +#define __PLAYBACK_H + +#if USE_SDL +#include "psdl.h" +#define p_init psdl_init +#define p_free psdl_free +#define p_play psdl_play +#define p_stop psdl_stop +#define p_ispaused psdl_ispaused +#define p_pause psdl_pause +#define p_unpause psdl_unpause +#define p_set_volume psdl_set_volume +#define p_get_rate psdl_get_rate +#else +#include "palsa.h" +#define p_init palsa_init +#define p_free palsa_free +#define p_play palsa_play +#define p_stop palsa_stop +#define p_ispaused palsa_ispaused +#define p_pause palsa_pause +#define p_unpause palsa_unpause +#define p_set_volume palsa_set_volume +#define p_get_rate palsa_get_rate +#endif + +#endif // __PLAYBACK_H @@ -4,7 +4,7 @@ #include "common.h" static int sdl_player_numsamples = 4096; -int sdl_player_freq; +static int sdl_player_freq; static SDL_AudioSpec spec; static void psdl_callback (void *userdata, Uint8 *stream, int len); static float sdl_volume = 1; @@ -20,6 +20,7 @@ le_int16 (int16_t in, char *out) { out[0] = pin[1]; #endif } + int psdl_init (void) { SDL_AudioSpec obt; @@ -94,6 +95,11 @@ psdl_set_volume (float vol) { sdl_volume = vol; } +int +psdl_get_rate (void) { + return sdl_player_freq; +} + static void psdl_callback (void* userdata, Uint8 *stream, int len) { int bytesread = streamer_read (stream, len); @@ -25,4 +25,7 @@ psdl_unpause (void); void psdl_set_volume (float vol); +int +psdl_get_rate (void); + #endif // __PSDL_H @@ -9,8 +9,8 @@ #include "playlist.h" #include "common.h" #include "streamer.h" +#include "playback.h" -extern int sdl_player_freq; // hack! static SRC_STATE *src; static SRC_DATA srcdata; static int codecleft; @@ -114,7 +114,7 @@ streamer_read_async (char *bytes, int size) { int nchannels = codec->info.channels; int samplerate = codec->info.samplesPerSecond; // read and do SRC - if (codec->info.samplesPerSecond == sdl_player_freq) { + if (codec->info.samplesPerSecond == p_get_rate ()) { int i; if (codec->info.channels == 2) { bytesread = codec->read (bytes, size); @@ -134,11 +134,11 @@ streamer_read_async (char *bytes, int size) { else { int nsamples = size/4; // convert to codec samplerate - nsamples = nsamples * samplerate / sdl_player_freq * 2; - if (!src_is_valid_ratio ((double)sdl_player_freq/samplerate)) { - printf ("invalid ratio! %d / %d = %f", sdl_player_freq, samplerate, (float)sdl_player_freq/samplerate); + nsamples = nsamples * samplerate / p_get_rate () * 2; + if (!src_is_valid_ratio ((double)p_get_rate ()/samplerate)) { + printf ("invalid ratio! %d / %d = %f", p_get_rate (), samplerate, (float)p_get_rate ()/samplerate); } - assert (src_is_valid_ratio ((double)sdl_player_freq/samplerate)); + assert (src_is_valid_ratio ((double)p_get_rate ()/samplerate)); // read data at source samplerate (with some room for SRC) int nbytes = (nsamples - codecleft) * 2 * nchannels; if (nbytes < 0) { @@ -171,7 +171,7 @@ streamer_read_async (char *bytes, int size) { srcdata.data_out = g_srcbuffer; srcdata.input_frames = nsamples; srcdata.output_frames = size/4; - srcdata.src_ratio = (double)sdl_player_freq/samplerate; + srcdata.src_ratio = (double)p_get_rate ()/samplerate; srcdata.end_of_input = 0; // src_set_ratio (src, srcdata.src_ratio); src_process (src, &srcdata); |