Skip to content

Commit

Permalink
barely working new mdx2midi
Browse files Browse the repository at this point in the history
  • Loading branch information
vampirefrog committed Nov 16, 2024
1 parent e79404c commit 8ebc9a8
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 461 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tests: $(TESTS)
.SECONDEXPANSION:
adpcm-decode_SRCS=adpcm.c
adpcm-encode_SRCS=adpcm.c
mdx2midi_SRCS=mdx.c tools.c cmdline.c
mdx2midi_SRCS=mdx.c tools.c cmdline.c adpcm_driver.c adpcm_midi_driver.c midi_timer_driver.c fm_driver.c fm_midi_driver.c mdx_driver.c timer_driver.c
mdx2mml_SRCS=mdx.c mdx_decompiler.c tools.c cmdline.c x68ksjis/sjis.c x68ksjis/sjis_unicode.c x68ksjis/utf8.c
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
Expand Down
1 change: 0 additions & 1 deletion adpcm_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ int adpcm_driver_set_pan(struct adpcm_driver *d, uint8_t pan) {
d->set_pan(d, pan);
return 0;
}

49 changes: 49 additions & 0 deletions adpcm_midi_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "adpcm_midi_driver.h"

int adpcm_midi_driver_play(struct adpcm_driver *d, uint8_t channel, uint8_t *data, int len, uint8_t freq, uint8_t vol) {
return 0;
}

int adpcm_midi_driver_stop(struct adpcm_driver *d, uint8_t channel) {
return 0;
}

int adpcm_midi_driver_set_volume(struct adpcm_driver *d, uint8_t channel, uint8_t vol) {
return 0;
}

int adpcm_midi_driver_set_freq(struct adpcm_driver *d, uint8_t channel, uint8_t freq) {
return 0;
}

int adpcm_midi_driver_set_pan(struct adpcm_driver *d, uint8_t pan) {
return 0;
}

int adpcm_midi_driver_init(struct adpcm_midi_driver *driver, struct midi_file *midi_file) {
adpcm_driver_init(&driver->adpcm_driver);
driver->adpcm_driver.play = adpcm_midi_driver_play;
driver->adpcm_driver.stop = adpcm_midi_driver_stop;
driver->adpcm_driver.set_freq = adpcm_midi_driver_set_freq;
driver->adpcm_driver.set_volume = adpcm_midi_driver_set_volume;
driver->adpcm_driver.set_pan = adpcm_midi_driver_set_pan;

driver->midi_file = midi_file;
for(int i = 0; i < 8; i++)
driver->channels[i].ticks = 0;

return 0;
}

void adpcm_midi_driver_end(struct adpcm_midi_driver *driver) {
for(int i = 0; i < 8; i++) {
midi_track_write_track_end(&driver->midi_file->tracks[i + 9], driver->channels[i].ticks);
driver->channels[i].ticks = 0;
}
}

int adpcm_midi_driver_tick(struct adpcm_midi_driver *driver) {
for(int i = 0; i < 8; i++)
driver->channels[i].ticks++;
return 0;
}
20 changes: 20 additions & 0 deletions adpcm_midi_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef ADPCM_MIDI_DRIVER_H_
#define ADPCM_MIDI_DRIVER_H_

#include "adpcm_driver.h"
#include "midilib/midi_file.h"

struct adpcm_midi_driver_channel {
int ticks;
};

struct adpcm_midi_driver {
struct adpcm_driver adpcm_driver; // parent
struct midi_file *midi_file;
struct adpcm_midi_driver_channel channels[8];
};
int adpcm_midi_driver_init(struct adpcm_midi_driver *driver, struct midi_file *midi_file);
int adpcm_midi_driver_tick(struct adpcm_midi_driver *driver);
void adpcm_midi_driver_end(struct adpcm_midi_driver *driver);

#endif /* ADPCM_MIDI_DRIVER_H_ */
112 changes: 112 additions & 0 deletions fm_midi_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "fm_midi_driver.h"

void fm_midi_driver_reset_key_sync(struct fm_driver *driver, int channel) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_set_pms_ams(struct fm_driver *driver, int channel, uint8_t pms_ams) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_set_pitch(struct fm_driver *driver, int channel, int pitch) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
if(mididrv->channels[channel].on && pitch != mididrv->channels[channel].pitch) {
pitch >>= 8;
pitch -= 5;
int detune = pitch & 0x3f;
int note = pitch >> 6;
printf("pitch bend channel=%d pitch=%d note=%d detune=%d ticks=%d\n", channel, pitch, note, detune, mididrv->channels[channel].ticks);
mididrv->channels[channel].ticks = 0;
}
mididrv->channels[channel].pitch = pitch;
}

void fm_midi_driver_set_tl(struct fm_driver *driver, int channel, uint8_t tl, uint8_t *v) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
mididrv->channels[channel].tl = tl;
}

void fm_midi_driver_note_on(struct fm_driver *driver, int channel, uint8_t op_mask, uint8_t *v) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
printf("note on channel=%d op_mask=%01x\n");
mididrv->channels[channel].on = 1;
int pitch = (mididrv->channels[channel].pitch >> 8) - 5;
int detune = pitch & 0x3f;
int note = pitch >> 6;
printf("set pitch channel=%d pitch=%d note=%d detune=%d ticks=%d\n", channel, pitch, note, detune, mididrv->channels[channel].ticks);
midi_track_write_note_on(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, note, 127);
mididrv->channels[channel].ticks = 0;
}

void fm_midi_driver_note_off(struct fm_driver *driver, int channel) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
mididrv->channels[channel].on = 0;
int pitch = (mididrv->channels[channel].pitch >> 8) - 5;
int detune = pitch & 0x3f;
int note = pitch >> 6;
printf("note off channel=%d ticks=%d\n", channel, mididrv->channels[channel].ticks);
midi_track_write_note_off(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, note, 127);
mididrv->channels[channel].ticks = 0;
}

void fm_midi_driver_write_opm_reg(struct fm_driver *driver, uint8_t reg, uint8_t data) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_set_pan(struct fm_driver *driver, int channel, uint8_t pan, uint8_t *v) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_set_noise_freq(struct fm_driver *driver, int channel, int freq) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_load_voice(struct fm_driver *driver, int channel, uint8_t *v, int volume, int pan) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_load_lfo(struct fm_driver *driver, int channel, uint8_t wave, uint8_t freq, uint8_t pmd, uint8_t amd) {
struct fm_midi_driver *mididrv = (struct fm_midi_driver *)driver;
(void)mididrv;
}

void fm_midi_driver_init(struct fm_midi_driver *driver, struct midi_file *midi_file) {
fm_driver_init(&driver->fm_driver);
driver->fm_driver.reset_key_sync = fm_midi_driver_reset_key_sync;
driver->fm_driver.set_pms_ams = fm_midi_driver_set_pms_ams;
driver->fm_driver.set_pitch = fm_midi_driver_set_pitch;
driver->fm_driver.set_tl = fm_midi_driver_set_tl;
driver->fm_driver.note_on = fm_midi_driver_note_on;
driver->fm_driver.note_off = fm_midi_driver_note_off;
driver->fm_driver.write_opm_reg = fm_midi_driver_write_opm_reg;
driver->fm_driver.set_pan = fm_midi_driver_set_pan;
driver->fm_driver.set_noise_freq = fm_midi_driver_set_noise_freq;
driver->fm_driver.load_voice = fm_midi_driver_load_voice;
driver->fm_driver.load_lfo = fm_midi_driver_load_lfo;

driver->midi_file = midi_file;
for(int i = 0; i < 8; i++) {
driver->channels[i].on = 0;
driver->channels[i].pitch = 0;
driver->channels[i].ticks = 0;
}
}

void fm_midi_driver_end(struct fm_midi_driver *driver) {
for(int i = 0; i < 8; i++) {
midi_track_write_track_end(&driver->midi_file->tracks[i + 1], driver->channels[i].ticks);
driver->channels[i].ticks = 0;
}
}

void fm_midi_driver_tick(struct fm_midi_driver *driver) {
for(int i = 0; i < 8; i++)
driver->channels[i].ticks++;
}
21 changes: 21 additions & 0 deletions fm_midi_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef FM_MIDI_DRIVER_H_
#define FM_MIDI_DRIVER_H_

#include "fm_driver.h"
#include "midilib/midi_file.h"

struct fm_midi_driver_channel {
int on, pitch, tl, ticks;
};

/* MIDI driver */
struct fm_midi_driver {
struct fm_driver fm_driver;
struct midi_file *midi_file;
struct fm_midi_driver_channel channels[8];
};
void fm_midi_driver_init(struct fm_midi_driver *driver, struct midi_file *midi_file);
void fm_midi_driver_deinit(struct fm_midi_driver *driver);
void fm_midi_driver_tick(struct fm_midi_driver *driver);

#endif /* FM_MIDI_DRIVER_H_ */
1 change: 0 additions & 1 deletion fm_opm_emu_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/* OPM emulation driver */
struct fm_opm_emu_driver {
struct fm_opm_driver fm_opm_driver;

int sample_rate;
struct ym2151 opm;
};
Expand Down
76 changes: 0 additions & 76 deletions fm_opm_midi_driver.c

This file was deleted.

13 changes: 0 additions & 13 deletions fm_opm_midi_driver.h

This file was deleted.

Loading

0 comments on commit 8ebc9a8

Please sign in to comment.