-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e79404c
commit 8ebc9a8
Showing
13 changed files
with
320 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,3 @@ int adpcm_driver_set_pan(struct adpcm_driver *d, uint8_t pan) { | |
d->set_pan(d, pan); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.