From ab379f2bb081f3fe2ea77ed163f755f59a49e6cf Mon Sep 17 00:00:00 2001 From: Takamichi Horikawa Date: Wed, 12 Apr 2017 01:04:15 +0900 Subject: added wave output --- common/fmplayer_drumrom_unix.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 common/fmplayer_drumrom_unix.c (limited to 'common/fmplayer_drumrom_unix.c') diff --git a/common/fmplayer_drumrom_unix.c b/common/fmplayer_drumrom_unix.c new file mode 100644 index 0000000..791b264 --- /dev/null +++ b/common/fmplayer_drumrom_unix.c @@ -0,0 +1,53 @@ +#include "fmplayer_common.h" +#include +#include +#include +#include "libopna/opnadrum.h" + +static struct { + uint8_t drum_rom[OPNA_ROM_SIZE]; + bool loaded; +} g; + +#define DATADIR "/.local/share/fmplayer/" + +void loadfile(void) { + const char *path = "ym2608_adpcm_rom.bin"; + const char *home = getenv("HOME"); + char *dpath = 0; + if (home) { + const char *datadir = DATADIR; + dpath = malloc(strlen(home)+strlen(datadir)+strlen(path) + 1); + if (dpath) { + strcpy(dpath, home); + strcat(dpath, datadir); + strcat(dpath, path); + path = dpath; + } + } + FILE *rhythm = fopen(path, "r"); + free(dpath); + if (!rhythm) goto err; + if (fseek(rhythm, 0, SEEK_END) != 0) goto err_file; + long size = ftell(rhythm); + if (size != OPNA_ROM_SIZE) goto err_file; + if (fseek(rhythm, 0, SEEK_SET) != 0) goto err_file; + if (fread(g.drum_rom, 1, OPNA_ROM_SIZE, rhythm) != OPNA_ROM_SIZE) goto err_file; + fclose(rhythm); + g.loaded = true; + return; +err_file: + fclose(rhythm); +err: + return; +} + +bool fmplayer_drum_rom_load(struct opna_drum *drum) { + if (!g.loaded) { + loadfile(); + } + if (g.loaded) { + opna_drum_set_rom(drum, g.drum_rom); + } + return g.loaded; +} -- cgit v1.2.3