summaryrefslogtreecommitdiff
path: root/cgme.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgme.c')
-rw-r--r--cgme.c93
1 files changed, 53 insertions, 40 deletions
diff --git a/cgme.c b/cgme.c
index f89f9175..371a2e04 100644
--- a/cgme.c
+++ b/cgme.c
@@ -24,56 +24,69 @@
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
+typedef struct {
+ DB_fileinfo_t info;
+ Music_Emu *emu;
+ int reallength;
+ int nzerosamples;
+ uint32_t cgme_voicemask;
+ float duration; // of current song
+} gme_info_t;
-static int
+static DB_fileinfo_t *
cgme_init (DB_playItem_t *it) {
+ DB_fileinfo_t *_info = malloc (sizeof (gme_info_t));
+ gme_info_t *info = (gme_info_t*)_info;
+ memset (_info, 0, sizeof (gme_info_t));
int samplerate = deadbeef->get_output ()->samplerate ();
- if (gme_open_file (it->fname, &emu, samplerate)) {
- return -1;
+ if (gme_open_file (it->fname, &info->emu, samplerate)) {
+ plugin.free (_info);
+ return NULL;
}
- gme_mute_voices (emu, cgme_voicemask);
- gme_start_track (emu, it->tracknum);
+ gme_mute_voices (info->emu, info->cgme_voicemask);
+ gme_start_track (info->emu, it->tracknum);
+
track_info_t inf;
- gme_track_info (emu, &inf, it->tracknum);
- plugin.info.bps = 16;
- plugin.info.channels = 2;
- plugin.info.samplerate = samplerate;
- duration = deadbeef->pl_get_item_duration (it);
- reallength = inf.length;
- nzerosamples = 0;
- plugin.info.readpos = 0;
- return 0;
+
+ gme_track_info (info->emu, &inf, it->tracknum);
+
+ _info->plugin = &plugin;
+ _info->bps = 16;
+ _info->channels = 2;
+ _info->samplerate = samplerate;
+ info->duration = deadbeef->pl_get_item_duration (it);
+ info->reallength = inf.length;
+ info->nzerosamples = 0;
+ _info->readpos = 0;
+ return _info;
}
static void
-cgme_free (void) {
- if (emu) {
- gme_delete (emu);
- emu = NULL;
+cgme_free (DB_fileinfo_t *_info) {
+ gme_info_t *info = (gme_info_t*)_info;
+ if (info->emu) {
+ gme_delete (info->emu);
}
+ free (info);
}
static int
-cgme_read (char *bytes, int size) {
- float t = (size/4) / (float)plugin.info.samplerate;
- if (plugin.info.readpos + t >= duration) {
- t = duration - plugin.info.readpos;
+cgme_read (DB_fileinfo_t *_info, char *bytes, int size) {
+ gme_info_t *info = (gme_info_t*)_info;
+ float t = (size/4) / (float)_info->samplerate;
+ if (_info->readpos + t >= info->duration) {
+ t = info->duration - _info->readpos;
if (t <= 0) {
return 0;
}
// DON'T ajust size, buffer must always be po2
- //size = t * (float)plugin.info.samplerate * 4;
+ //size = t * (float)info->samplerate * 4;
}
- if (gme_play (emu, size/2, (short*)bytes)) {
+ if (gme_play (info->emu, size/2, (short*)bytes)) {
return 0;
}
- plugin.info.readpos += t;
- if (reallength == -1) {
+ _info->readpos += t;
+ if (info->reallength == -1) {
// check if whole buffer is zeroes
int i;
for (i = 0; i < size; i++) {
@@ -82,30 +95,30 @@ cgme_read (char *bytes, int size) {
}
}
if (i == size) {
- nzerosamples += size / 4;
- if (nzerosamples > plugin.info.samplerate * 4) {
+ info->nzerosamples += size / 4;
+ if (info->nzerosamples > _info->samplerate * 4) {
return 0;
}
}
else {
- nzerosamples = 0;
+ info->nzerosamples = 0;
}
}
return size;
}
static int
-cgme_seek (float time) {
- if (gme_seek (emu, (long)(time * 1000))) {
+cgme_seek (DB_fileinfo_t *_info, float time) {
+ gme_info_t *info = (gme_info_t*)_info;
+ if (gme_seek (info->emu, (long)(time * 1000))) {
return -1;
}
- plugin.info.readpos = time;
+ _info->readpos = time;
return 0;
}
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)) {
int cnt = gme_track_count (emu);
@@ -114,7 +127,7 @@ cgme_insert (DB_playItem_t *after, const char *fname) {
const char *ret = gme_track_info (emu, &inf, i);
if (!ret) {
DB_playItem_t *it = deadbeef->pl_item_alloc ();
- it->decoder_id = deadbeef->plug_get_decoder_id (plugin.id);
+ it->decoder_id = deadbeef->plug_get_decoder_id (plugin.plugin.id);
it->fname = strdup (fname);
char str[1024];
if (inf.song[0]) {
@@ -209,6 +222,7 @@ static DB_decoder_t plugin = {
.plugin.version_major = 0,
.plugin.version_minor = 1,
.plugin.type = DB_PLUGIN_DECODER,
+ .plugin.id = "stdgme",
.plugin.name = "Game_Music_Emu decoder",
.plugin.descr = "chiptune music player based on GME",
.plugin.author = "Alexey Yakovenko",
@@ -220,7 +234,6 @@ static DB_decoder_t plugin = {
.seek = cgme_seek,
.insert = cgme_insert,
.exts = exts,
- .id = "stdgme",
.filetypes = exts
};