summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2009-08-30 12:41:05 +0200
committerGravatar waker <wakeroid@gmail.com>2009-08-30 12:41:05 +0200
commited9836504315d1ecd19fb24ef32ad39f372f95c5 (patch)
tree5cbe4e948ff238a59686a44e6d99e0e272506a42
parent8ef5d928c1183f43c3f30a4f59c8ef995ac711a9 (diff)
ported gme to plugin api
-rw-r--r--Makefile.am4
-rw-r--r--cgme.c116
-rw-r--r--deadbeef.h1
-rw-r--r--moduleconf.h1
-rw-r--r--plugins.c2
5 files changed, 74 insertions, 50 deletions
diff --git a/Makefile.am b/Makefile.am
index 9eaf05a9..39a90e4d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,7 +20,7 @@ deadbeef_SOURCES =\
messagepump.c messagepump.h messages.h\
conf.c conf.h\
search.c search.h\
- cmp3.c cvorbis.c cflac.c\
+ cmp3.c cvorbis.c cflac.c cgme.c\
palsa.c palsa.h playback.h\
threading_pthread.c threading.h\
md5/md5.c md5/md5.h md5/md5_loc.h\
@@ -34,7 +34,7 @@ deadbeef_SOURCES =\
sdkdir = $(pkgincludedir)
sdk_HEADERS = deadbeef.h
-deadbeef_LDADD = $(LDADD) $(DEPS_LIBS) gme/Game_Music_Emu-0.5.2/gme/libgme.a sid/sidplay-libs-2.1.0/libsidplay2.a dumb/libdumb.a
+deadbeef_LDADD = $(LDADD) $(DEPS_LIBS) gme/Game_Music_Emu-0.5.2/gme/libgme.a sid/sidplay-libs-2.1.0/libsidplay2.a dumb/libdumb.a -lstdc++
AM_CFLAGS = $(DEPS_CFLAGS) $(SIMD_FLAGS) -I$(gmepath) -std=c99
AM_CPPFLAGS = $(DEPS_CFLAGS) -I$(sidpath)/libsidplay/include -I$(sidpath)/builders/resid-builder/include
diff --git a/cgme.c b/cgme.c
index 5f053165..75282a63 100644
--- a/cgme.c
+++ b/cgme.c
@@ -19,35 +19,37 @@
#include <stdlib.h>
#include <string.h>
#include "gme/gme.h"
-#include "codec.h"
-#include "cgme.h"
-#include "playlist.h"
-#include "playback.h"
+#include "deadbeef.h"
+
+static DB_decoder_t plugin;
+static DB_functions_t *deadbeef;
static Music_Emu *emu;
static int reallength;
static int nzerosamples;
static uint32_t cgme_voicemask = 0;
+static float duration; // of current song
-int
-cgme_init (playItem_t *it) {
- if (gme_open_file (it->fname, &emu, p_get_rate ())) {
+static int
+cgme_init (DB_playItem_t *it) {
+ if (gme_open_file (it->fname, &emu, deadbeef->playback_get_samplerate ())) {
return -1;
}
gme_mute_voices (emu, cgme_voicemask);
gme_start_track (emu, it->tracknum);
track_info_t inf;
gme_track_info (emu, &inf, it->tracknum);
- cgme.info.bitsPerSample = 16;
- cgme.info.channels = 2;
- cgme.info.samplesPerSecond = p_get_rate ();
+ plugin.info.bps = 16;
+ plugin.info.channels = 2;
+ plugin.info.samplerate = deadbeef->playback_get_samplerate ();
+ duration = it->duration;
reallength = inf.length;
nzerosamples = 0;
- cgme.info.readposition = 0;
+ plugin.info.readpos = 0;
return 0;
}
-void
+static void
cgme_free (void) {
if (emu) {
gme_delete (emu);
@@ -55,21 +57,21 @@ cgme_free (void) {
}
}
-int
+static int
cgme_read (char *bytes, int size) {
- float t = (size/4) / (float)cgme.info.samplesPerSecond;
- if (cgme.info.readposition + t >= playlist_current.duration) {
- t = playlist_current.duration - cgme.info.readposition;
+ float t = (size/4) / (float)plugin.info.samplerate;
+ if (plugin.info.readpos + t >= duration) {
+ t = duration - plugin.info.readpos;
if (t <= 0) {
return 0;
}
// DON'T ajust size, buffer must always be po2
- //size = t * (float)cgme.info.samplesPerSecond * 4;
+ //size = t * (float)plugin.info.samplerate * 4;
}
if (gme_play (emu, size/2, (short*)bytes)) {
return 0;
}
- cgme.info.readposition += t;
+ plugin.info.readpos += t;
if (reallength == -1) {
// check if whole buffer is zeroes
int i;
@@ -80,7 +82,7 @@ cgme_read (char *bytes, int size) {
}
if (i == size) {
nzerosamples += size / 4;
- if (nzerosamples > cgme.info.samplesPerSecond * 4) {
+ if (nzerosamples > plugin.info.samplerate * 4) {
return 0;
}
}
@@ -91,17 +93,17 @@ cgme_read (char *bytes, int size) {
return size;
}
-int
+static int
cgme_seek (float time) {
if (gme_seek (emu, (long)(time * 1000))) {
return -1;
}
- cgme.info.readposition = time;
+ plugin.info.readpos = time;
return 0;
}
-playItem_t *
-cgme_insert (playItem_t *after, const char *fname) {
+static DB_playItem_t *
+cgme_insert (DB_playItem_t *after, const char *fname) {
// printf ("adding %s chiptune\n", fname);
Music_Emu *emu;
if (!gme_open_file (fname, &emu, gme_info_only)) {
@@ -110,9 +112,8 @@ cgme_insert (playItem_t *after, const char *fname) {
track_info_t inf;
const char *ret = gme_track_info (emu, &inf, i);
if (!ret) {
- playItem_t *it = malloc (sizeof (playItem_t));
- memset (it, 0, sizeof (playItem_t));
- it->codec = &cgme;
+ DB_playItem_t *it = deadbeef->pl_item_alloc ();
+ it->decoder = &plugin;
it->fname = strdup (fname);
char str[1024];
if (inf.song[0]) {
@@ -124,24 +125,36 @@ cgme_insert (playItem_t *after, const char *fname) {
it->tracknum = i;
// add metadata
- pl_add_meta (it, "system", inf.system);
- pl_add_meta (it, "album", inf.game);
- pl_add_meta (it, "title", inf.song);
- pl_add_meta (it, "artist", inf.author);
- pl_add_meta (it, "copyright", inf.copyright);
- pl_add_meta (it, "comment", inf.comment);
- pl_add_meta (it, "dumper", inf.dumper);
+ deadbeef->pl_add_meta (it, "system", inf.system);
+ deadbeef->pl_add_meta (it, "album", inf.game);
+ deadbeef->pl_add_meta (it, "title", inf.song);
+ deadbeef->pl_add_meta (it, "artist", inf.author);
+ deadbeef->pl_add_meta (it, "copyright", inf.copyright);
+ deadbeef->pl_add_meta (it, "comment", inf.comment);
+ deadbeef->pl_add_meta (it, "dumper", inf.dumper);
char trk[10];
snprintf (trk, 10, "%d", i+1);
- pl_add_meta (it, "track", trk);
+ deadbeef->pl_add_meta (it, "track", trk);
if (inf.length == -1) {
it->duration = 300;
}
else {
it->duration = (float)inf.length/1000.f;
}
- it->filetype = "GameMusic";
- after = pl_insert_item (after, it);
+ const char *ext = fname + strlen (fname) - 1;
+ while (ext >= fname && *ext != '.') {
+ ext--;
+ }
+ it->filetype = NULL;
+ if (*ext == '.') {
+ ext++;
+ for (int i = 0; plugin.exts[i]; i++) {
+ if (!strcasecmp (ext, plugin.exts[i])) {
+ it->filetype = plugin.exts[i];
+ }
+ }
+ }
+ after = deadbeef->pl_insert_item (after, it);
}
else {
printf ("gme error: %s\n", ret);
@@ -162,11 +175,7 @@ static const char * exts[]=
"ay","gbs","gym","hes","kss","nsf","nsfe","sap","spc","vgm","vgz",NULL
};
-const char **cgme_getexts (void) {
- return exts;
-}
-
-int
+static int
cgme_numvoices (void) {
if (!emu) {
return 0;
@@ -174,7 +183,7 @@ cgme_numvoices (void) {
return gme_voice_count (emu);
}
-void
+static void
cgme_mutevoice (int voice, int mute) {
cgme_voicemask &= ~ (1<<voice);
cgme_voicemask |= ((mute ? 1 : 0) << voice);
@@ -183,16 +192,27 @@ cgme_mutevoice (int voice, int mute) {
}
}
-codec_t cgme = {
+// define plugin interface
+static DB_decoder_t plugin = {
+ .plugin.version_major = 0,
+ .plugin.version_minor = 1,
+ .plugin.type = DB_PLUGIN_DECODER,
+ .plugin.name = "Game_Music_Emu decoder",
+ .plugin.author = "Alexey Yakovenko",
+ .plugin.email = "waker@users.sourceforge.net",
+ .plugin.website = "http://deadbeef.sf.net",
.init = cgme_init,
.free = cgme_free,
- .read = cgme_read,
+ .read_int16 = cgme_read,
.seek = cgme_seek,
.insert = cgme_insert,
- .getexts = cgme_getexts,
- .numvoices = cgme_numvoices,
- .mutevoice = cgme_mutevoice,
+ .exts = exts,
.id = "stdgme",
- .filetypes = { "GameMusic", NULL }
+ .filetypes = exts
};
+DB_plugin_t *
+gme_load (DB_functions_t *api) {
+ deadbeef = api;
+ return DB_PLUGIN (&plugin);
+}
diff --git a/deadbeef.h b/deadbeef.h
index 8d6f6e6e..c4797f75 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -120,6 +120,7 @@ typedef struct {
void (*playback_random) (void);
float (*playback_get_pos) (void); // [0..100]
void (*playback_set_pos) (float pos); // [0..100]
+ int (*playback_get_samplerate) (void); // output samplerate
// process control
void (*quit) (void);
// threading
diff --git a/moduleconf.h b/moduleconf.h
index fa6c0c13..dffae15c 100644
--- a/moduleconf.h
+++ b/moduleconf.h
@@ -1,3 +1,4 @@
PLUG(mpegmad)
PLUG(oggvorbis)
PLUG(flac)
+PLUG(gme)
diff --git a/plugins.c b/plugins.c
index 334a28d1..de92258c 100644
--- a/plugins.c
+++ b/plugins.c
@@ -35,6 +35,7 @@
#include "playlist.h"
#include "volume.h"
#include "streamer.h"
+#include "playback.h"
// deadbeef api
DB_functions_t deadbeef_api = {
@@ -53,6 +54,7 @@ DB_functions_t deadbeef_api = {
.playback_random = plug_playback_random,
.playback_get_pos = plug_playback_get_pos,
.playback_set_pos = plug_playback_set_pos,
+ .playback_get_samplerate = p_get_rate,
.quit = plug_quit,
// threading
.thread_start = thread_start,