From a0739f21b3407c123d4c225403a01b420cc764ec Mon Sep 17 00:00:00 2001 From: vampi Date: Thu, 14 Nov 2024 16:22:34 +0200 Subject: [PATCH] add vgm logging for FM only --- Makefile | 4 ++-- fm_opm_driver.c | 5 ++++- fm_opm_driver.h | 4 +++- fm_opm_emu_driver.c | 4 ++-- fm_opm_emu_driver.h | 2 +- mdx2pcm.c | 2 +- mdxplay.c | 24 +++++++++++++++++++++--- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 421effe..60b8de5 100644 --- a/Makefile +++ b/Makefile @@ -51,9 +51,9 @@ mdx2opm_SRCS=mdx2opm.c tools.c mdx.c mdx2vgm_SRCS=mdx.c mdx_driver.c adpcm_driver.c adpcm.c speex_resampler.c timer.c tools.c x68ksjis/sjis_unicode.c x68ksjis/sjis.c ym2151.c okim6258.c vgm.c mdxdump_SRCS=mdx.c tools.c mdxinfo_SRCS=mdx.c tools.c x68ksjis/sjis_unicode.c x68ksjis/sjis.c x68ksjis/utf8.c cmdline.c md5.c -mdxplay_SRCS=mdx_driver.c timer_driver.c adpcm_driver.c fm_driver.c tools.c adpcm.c speex_resampler.c ym2151.c fixed_resampler.c mdx.c pdx.c cmdline.c adpcm_pcm_mix_driver.c fm_opm_emu_driver.c pcm_timer_driver.c fm_opm_driver.c sinctbl4.h sinctbl3.h +mdxplay_SRCS=mdx_driver.c timer_driver.c adpcm_driver.c fm_driver.c tools.c adpcm.c speex_resampler.c ym2151.c fixed_resampler.c mdx.c pdx.c cmdline.c adpcm_pcm_mix_driver.c fm_opm_emu_driver.c pcm_timer_driver.c fm_opm_driver.c sinctbl4.h sinctbl3.h vgm_logger.c mdxplay_LIBS=$(shell pkg-config portaudio-2.0 --libs) -mdx2pcm_SRCS=mdx_driver.c timer_driver.c adpcm_driver.c fm_driver.c tools.c adpcm.c speex_resampler.c ym2151.c fixed_resampler.c mdx.c pdx.c wav.c cmdline.c adpcm_pcm_mix_driver.c fm_opm_emu_driver.c pcm_timer_driver.c fm_opm_driver.c sinctbl4.h sinctbl3.h +mdx2pcm_SRCS=mdx_driver.c timer_driver.c adpcm_driver.c fm_driver.c tools.c adpcm.c speex_resampler.c ym2151.c fixed_resampler.c mdx.c pdx.c wav.c cmdline.c adpcm_pcm_mix_driver.c fm_opm_emu_driver.c pcm_timer_driver.c fm_opm_driver.c sinctbl4.h sinctbl3.h vgm_logger.c mml2mdx_SRCS=mml2mdx.c mmlc.tab.c mmlc.yy.c cmdline.c tools.c mdx_compiler.c mmlc.yy.h mmlc.tab.h pdx2wav_SRCS=pdx.c wav.c tools.c adpcm.c pdx2sf2_SRCS=pdx.c tools.c adpcm.c Soundfont.c diff --git a/fm_opm_driver.c b/fm_opm_driver.c index 1876b6a..e000c7f 100644 --- a/fm_opm_driver.c +++ b/fm_opm_driver.c @@ -115,10 +115,13 @@ static void fm_opm_driver_load_lfo(struct fm_driver *driver, int channel, uint8_ void fm_opm_driver_write(struct fm_opm_driver *driver, uint8_t reg, uint8_t val) { if(driver->write) driver->write(driver, reg, val); + if(driver->vgm_logger) + vgm_logger_write_ym2151(driver->vgm_logger, reg, val); } -void fm_opm_driver_init(struct fm_opm_driver *driver) { +void fm_opm_driver_init(struct fm_opm_driver *driver, struct vgm_logger *vgm_logger) { fm_driver_init(&driver->fm_driver); + driver->vgm_logger = vgm_logger; driver->fm_driver.reset_key_sync = fm_opm_driver_reset_key_sync; driver->fm_driver.set_pms_ams = fm_opm_driver_set_pms_ams; diff --git a/fm_opm_driver.h b/fm_opm_driver.h index 0f98e6b..dadc746 100644 --- a/fm_opm_driver.h +++ b/fm_opm_driver.h @@ -2,16 +2,18 @@ #define FM_OPM_DRIVER_H_ #include "fm_driver.h" +#include "vgm_logger.h" /* OPM driver */ struct fm_opm_driver { struct fm_driver fm_driver; + struct vgm_logger *vgm_logger; uint8_t opm_cache[256]; void (*write)(struct fm_opm_driver *driver, uint8_t reg, uint8_t val); }; -void fm_opm_driver_init(struct fm_opm_driver *driver); +void fm_opm_driver_init(struct fm_opm_driver *driver, struct vgm_logger *vgm_logger); void fm_opm_driver_write(struct fm_opm_driver *driver, uint8_t reg, uint8_t val); #endif /* FM_OPM_DRIVER_H_ */ diff --git a/fm_opm_emu_driver.c b/fm_opm_emu_driver.c index a4506e3..ce810e2 100644 --- a/fm_opm_emu_driver.c +++ b/fm_opm_emu_driver.c @@ -6,13 +6,13 @@ static void fm_opm_emu_driver_write(struct fm_opm_driver *driver, uint8_t reg, u ym2151_write_reg(&emudrv->opm, reg, val); } -void fm_opm_emu_driver_init(struct fm_opm_emu_driver *driver, int sample_rate) { +void fm_opm_emu_driver_init(struct fm_opm_emu_driver *driver, struct vgm_logger *vgm_logger, int sample_rate) { driver->sample_rate = sample_rate; ym2151_init(&driver->opm, 4000000, sample_rate); ym2151_reset_chip(&driver->opm); driver->fm_opm_driver.write = fm_opm_emu_driver_write; - fm_opm_driver_init(&driver->fm_opm_driver); + fm_opm_driver_init(&driver->fm_opm_driver, vgm_logger); } void fm_opm_emu_driver_deinit(struct fm_opm_emu_driver *driver) { diff --git a/fm_opm_emu_driver.h b/fm_opm_emu_driver.h index 508f524..5538658 100644 --- a/fm_opm_emu_driver.h +++ b/fm_opm_emu_driver.h @@ -11,7 +11,7 @@ struct fm_opm_emu_driver { int sample_rate; struct ym2151 opm; }; -void fm_opm_emu_driver_init(struct fm_opm_emu_driver *driver, int sample_rate); +void fm_opm_emu_driver_init(struct fm_opm_emu_driver *driver, struct vgm_logger *vgm_logger, int sample_rate); void fm_opm_emu_driver_deinit(struct fm_opm_emu_driver *driver); int fm_opm_emu_driver_estimate(struct fm_opm_emu_driver *d, int num_samples); void fm_opm_emu_driver_run(struct fm_opm_emu_driver *d, stream_sample_t *outL, stream_sample_t *outR, int num_samples); diff --git a/mdx2pcm.c b/mdx2pcm.c index 41f5376..dad86f2 100644 --- a/mdx2pcm.c +++ b/mdx2pcm.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) { pcm_timer_driver_init(&timer_driver, opt_sample_rate); adpcm_pcm_mix_driver_init(&adpcm_driver, opt_sample_rate, 0); - fm_opm_emu_driver_init(&fm_driver, opt_sample_rate); + fm_opm_emu_driver_init(&fm_driver, 0, opt_sample_rate); mdx_driver_init( &mdx_driver, (struct timer_driver *)&timer_driver, diff --git a/mdxplay.c b/mdxplay.c index 7e075f9..48fb035 100644 --- a/mdxplay.c +++ b/mdxplay.c @@ -11,6 +11,7 @@ #include "mdx_driver.h" #include "pcm_timer_driver.h" #include "adpcm_pcm_mix_driver.h" +#include "vgm_logger.h" #include "fm_opm_emu_driver.h" #include "mamedef.h" @@ -19,6 +20,7 @@ int opt_channel_mask = 0xffff; int opt_loops = 1; +char *opt_vgm_file = 0; stream_sample_t bufL[BUFFER_SIZE], bufR[BUFFER_SIZE], chipBufL[BUFFER_SIZE], chipBufR[BUFFER_SIZE]; int16_t buf[BUFFER_SIZE * 2]; @@ -47,6 +49,13 @@ int main(int argc, char **argv) { TYPE_REQUIRED, TYPE_INT, &opt_loops }, + { + 'V', "vgm-file", + "Enable VGM logging", + "file", + TYPE_REQUIRED, + TYPE_STRING, &opt_vgm_file + }, CMDLINE_ARG_TERMINATOR }, 1, -1, ""); @@ -60,7 +69,10 @@ int main(int argc, char **argv) { pcm_timer_driver_init(&timer_driver, opt_sample_rate); adpcm_pcm_mix_driver_init(&adpcm_driver, opt_sample_rate, 0); - fm_opm_emu_driver_init(&fm_driver, opt_sample_rate); + struct vgm_logger vgm_logger; + if(opt_vgm_file && *opt_vgm_file) + vgm_logger_init(&vgm_logger, opt_vgm_file); + fm_opm_emu_driver_init(&fm_driver, opt_vgm_file && *opt_vgm_file ? &vgm_logger : 0, opt_sample_rate); mdx_driver_init( &mdx_driver, (struct timer_driver *)&timer_driver, @@ -135,10 +147,10 @@ int main(int argc, char **argv) { int timer_samples = pcm_timer_driver_estimate(&timer_driver, samples_remaining); if(timer_samples < samples) samples = timer_samples; - + int fm_samples = fm_opm_emu_driver_estimate(&fm_driver, samples_remaining); if(fm_samples < samples) samples = fm_samples; - + int adpcm_samples = adpcm_pcm_mix_driver_estimate(&adpcm_driver, samples_remaining); if(adpcm_samples < samples) samples = adpcm_samples; @@ -154,6 +166,9 @@ int main(int argc, char **argv) { mixBufRp[n] += bufR[n]; } + if(opt_vgm_file && *opt_vgm_file) + vgm_logger_write_wait(&vgm_logger, samples); + pcm_timer_driver_advance(&timer_driver, samples); samples_remaining -= samples; @@ -177,6 +192,9 @@ int main(int argc, char **argv) { if( err != paNoError ) goto error; Pa_Terminate(); + if(opt_vgm_file && *opt_vgm_file) + vgm_logger_end(&vgm_logger); + return err; error: