aboutsummaryrefslogtreecommitdiff
path: root/common/fmplayer_drumrom_unix.c
diff options
context:
space:
mode:
authorTakamichi Horikawa <takamichiho@gmail.com>2017-04-12 01:04:15 +0900
committerTakamichi Horikawa <takamichiho@gmail.com>2017-04-12 01:04:15 +0900
commitab379f2bb081f3fe2ea77ed163f755f59a49e6cf (patch)
treeb06142d1b4f765e23531abc50ad229494b241a04 /common/fmplayer_drumrom_unix.c
parentc6c96944ae1bb1d7363349ec21be9dca76ee9ec4 (diff)
added wave output
Diffstat (limited to 'common/fmplayer_drumrom_unix.c')
-rw-r--r--common/fmplayer_drumrom_unix.c53
1 files changed, 53 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#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;
+}