diff --git a/fm_midi_driver.c b/fm_midi_driver.c index 489ae0d..4d1bb67 100644 --- a/fm_midi_driver.c +++ b/fm_midi_driver.c @@ -13,13 +13,11 @@ void fm_midi_driver_set_pms_ams(struct fm_driver *driver, int channel, uint8_t p 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 root_pitch = mididrv->channels[channel].note << 6; - int detune = (pitch - root_pitch); + int detune = ((pitch >> 8) - 5 - root_pitch); if(detune != mididrv->channels[channel].detune) { - midi_track_write_pitch_bend(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, detune); + midi_track_write_pitch_bend(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, 8192 + detune * 4); mididrv->channels[channel].detune = detune; mididrv->channels[channel].ticks = 0; } @@ -40,7 +38,7 @@ void fm_midi_driver_note_on(struct fm_driver *driver, int channel, uint8_t op_ma int note = pitch >> 6; mididrv->channels[channel].note = note; if(detune != mididrv->channels[channel].detune) { - midi_track_write_pitch_bend(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, detune); + midi_track_write_pitch_bend(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, 8192 + detune * 4); mididrv->channels[channel].ticks = 0; } midi_track_write_note_on(&mididrv->midi_file->tracks[channel + 1], mididrv->channels[channel].ticks, channel, note, 127); diff --git a/mdx2midi.c b/mdx2midi.c index 7d38a3a..739ea6a 100644 --- a/mdx2midi.c +++ b/mdx2midi.c @@ -67,6 +67,22 @@ int main(int argc, char **argv) { struct midi_file midi_file; midi_file_init(&midi_file, MIDI_FORMAT_MULTI_TRACKS, 16, 48); + for(int t = 0; t < 16; t++) { + struct midi_track *track = midi_file.tracks + t; + char buf[256]; + snprintf(buf, sizeof(buf), "Channel %c (%s)", mdx_track_name(t), t < 8 ? "FM" : "ADPCM"); + midi_track_write_track_name(track, 0, buf, -1); + midi_track_write_bank_select(track, 0, t, 0); + midi_track_write_control_change(track, 0, t, 126, 127); // Monophonic mode + if(t >= 8) { // OPM only + midi_track_write_nrpn_msb(track, 0, t, 0, 112); // OPM Clock = 4MHz + } + midi_track_write_control_change(track, 0, t, 12, 0); // Amplitude LFO level + midi_track_write_control_change(track, 0, t, 13, 0); // Pitch LFO level + midi_track_write_rpn_msb(track, 0, t, 0, 32); // Pitch Bend Sensitivity + midi_track_write_pitch_bend(track, 0, t, 0x2000); + } + struct midi_track *first_track = midi_file_prepend_empty_track(&midi_file); midi_track_write_time_signature(first_track, 0, 4, 2, 0, 0); char buf[PATH_MAX];