Skip to content

Commit

Permalink
add vgm logging for FM only
Browse files Browse the repository at this point in the history
  • Loading branch information
vampirefrog committed Nov 14, 2024
1 parent 336d945 commit a0739f2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion fm_opm_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion fm_opm_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
4 changes: 2 additions & 2 deletions fm_opm_emu_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion fm_opm_emu_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mdx2pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 21 additions & 3 deletions mdxplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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];
Expand Down Expand Up @@ -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, "<file.mdx>");

Expand All @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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:
Expand Down

0 comments on commit a0739f2

Please sign in to comment.