2010-04-10 10:05:16 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "../decoder_api.h"
|
|
|
|
#include "audio_check.h"
|
|
|
|
#include <glib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <gme/gme.h>
|
|
|
|
|
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "gme"
|
|
|
|
|
2010-05-31 09:45:52 +02:00
|
|
|
enum {
|
|
|
|
GME_SAMPLE_RATE = 44100,
|
|
|
|
GME_CHANNELS = 2,
|
2010-05-31 09:44:30 +02:00
|
|
|
GME_BUFFER_FRAMES = 2048,
|
|
|
|
GME_BUFFER_SAMPLES = GME_BUFFER_FRAMES * GME_CHANNELS,
|
2010-05-31 09:45:52 +02:00
|
|
|
};
|
|
|
|
|
2010-04-10 10:05:16 +02:00
|
|
|
static void
|
|
|
|
gme_file_decode(struct decoder *decoder, const char *path_fs)
|
|
|
|
{
|
|
|
|
int track = 0; /* index of track to play */
|
|
|
|
float song_len;
|
|
|
|
Music_Emu *emu;
|
|
|
|
gme_info_t *ti;
|
|
|
|
struct audio_format audio_format;
|
|
|
|
enum decoder_command cmd;
|
2010-05-31 09:44:30 +02:00
|
|
|
short buf[GME_BUFFER_SAMPLES];
|
2010-04-10 10:05:16 +02:00
|
|
|
const char* gme_err;
|
|
|
|
|
2010-05-31 09:45:52 +02:00
|
|
|
gme_err = gme_open_file(path_fs, &emu, GME_SAMPLE_RATE);
|
|
|
|
if (gme_err != NULL) {
|
2010-04-10 10:05:16 +02:00
|
|
|
g_warning("%s", gme_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if((gme_err = gme_track_info(emu, &ti, 0)) != NULL){
|
|
|
|
g_warning("%s", gme_err);
|
|
|
|
gme_delete(emu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ti->length > 0)
|
|
|
|
song_len = ti->length / 1000.0;
|
|
|
|
else song_len = -1;
|
|
|
|
|
|
|
|
/* initialize the MPD decoder */
|
|
|
|
|
|
|
|
GError *error = NULL;
|
2010-05-31 09:45:52 +02:00
|
|
|
if (!audio_format_init_checked(&audio_format, GME_SAMPLE_RATE,
|
|
|
|
SAMPLE_FORMAT_S16, GME_CHANNELS,
|
|
|
|
&error)) {
|
2010-04-10 10:05:16 +02:00
|
|
|
g_warning("%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
gme_free_info(ti);
|
|
|
|
gme_delete(emu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder_initialized(decoder, &audio_format, true, song_len);
|
|
|
|
|
|
|
|
if((gme_err = gme_start_track(emu, track)) != NULL)
|
|
|
|
g_warning("%s", gme_err);
|
|
|
|
|
|
|
|
/* play */
|
|
|
|
do {
|
2010-05-31 09:44:30 +02:00
|
|
|
gme_err = gme_play(emu, GME_BUFFER_SAMPLES, buf);
|
|
|
|
if (gme_err != NULL) {
|
2010-04-10 10:05:16 +02:00
|
|
|
g_warning("%s", gme_err);
|
|
|
|
return;
|
|
|
|
}
|
2010-05-31 09:57:15 +02:00
|
|
|
cmd = decoder_data(decoder, NULL, buf, sizeof(buf), 0);
|
2010-04-10 10:05:16 +02:00
|
|
|
|
|
|
|
if(cmd == DECODE_COMMAND_SEEK) {
|
|
|
|
float where = decoder_seek_where(decoder);
|
|
|
|
if((gme_err = gme_seek(emu, (int)where*1000)) != NULL)
|
|
|
|
g_warning("%s", gme_err);
|
|
|
|
decoder_command_finished(decoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(gme_track_ended(emu))
|
|
|
|
break;
|
|
|
|
} while(cmd != DECODE_COMMAND_STOP);
|
|
|
|
|
|
|
|
gme_free_info(ti);
|
|
|
|
gme_delete(emu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct tag *
|
|
|
|
gme_tag_dup(const char *path_fs)
|
|
|
|
{
|
|
|
|
Music_Emu *emu;
|
|
|
|
gme_info_t *ti;
|
|
|
|
const char* gme_err;
|
|
|
|
|
2010-05-31 09:45:52 +02:00
|
|
|
gme_err = gme_open_file(path_fs, &emu, GME_SAMPLE_RATE);
|
|
|
|
if (gme_err != NULL) {
|
2010-04-10 10:05:16 +02:00
|
|
|
g_warning("%s", gme_err);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if((gme_err = gme_track_info(emu, &ti, 0)) != NULL){
|
|
|
|
g_warning("%s", gme_err);
|
|
|
|
gme_delete(emu);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-31 09:43:25 +02:00
|
|
|
struct tag *tag = tag_new();
|
2010-04-10 10:05:16 +02:00
|
|
|
if(ti != NULL){
|
|
|
|
if(ti->length > 0)
|
|
|
|
tag->time = ti->length / 1000;
|
|
|
|
if(ti->song != NULL)
|
|
|
|
tag_add_item(tag, TAG_TITLE, ti->song);
|
|
|
|
if(ti->author != NULL)
|
|
|
|
tag_add_item(tag, TAG_ARTIST, ti->author);
|
|
|
|
if(ti->comment != NULL)
|
|
|
|
tag_add_item(tag, TAG_COMMENT, ti->comment);
|
|
|
|
if(ti->copyright != NULL)
|
|
|
|
tag_add_item(tag, TAG_DATE, ti->copyright);
|
|
|
|
}
|
|
|
|
|
|
|
|
gme_free_info(ti);
|
|
|
|
gme_delete(emu);
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *const gme_suffixes[] = {
|
|
|
|
"ay", "gbs", "gym", "hes", "kss", "nsf",
|
|
|
|
"nsfe", "sap", "spc", "vgm", "vgz",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct decoder_plugin gme_decoder_plugin;
|
|
|
|
const struct decoder_plugin gme_decoder_plugin = {
|
|
|
|
.name = "gme",
|
|
|
|
.file_decode = gme_file_decode,
|
|
|
|
.tag_dup = gme_tag_dup,
|
|
|
|
.suffixes = gme_suffixes,
|
|
|
|
};
|