summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2009-08-30 22:26:30 +0000
committerSimon Howard2009-08-30 22:26:30 +0000
commit61b2e3d2b8b6b2b6ddf8b92842ac4bcf47945160 (patch)
tree02ef1a4a2d51e5414cf78f44991e16551c2c9022 /src
parent1d045ed19c58abff063ac69db24a2e73d62ef530 (diff)
downloadchocolate-doom-61b2e3d2b8b6b2b6ddf8b92842ac4bcf47945160.tar.gz
chocolate-doom-61b2e3d2b8b6b2b6ddf8b92842ac4bcf47945160.tar.bz2
chocolate-doom-61b2e3d2b8b6b2b6ddf8b92842ac4bcf47945160.zip
Set the right instrument for percussion notes.
Subversion-branch: /branches/opl-branch Subversion-revision: 1645
Diffstat (limited to 'src')
-rw-r--r--src/i_oplmusic.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index 7a619c5d..d844fd7b 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -656,8 +656,10 @@ static unsigned int FrequencyForNote(unsigned int note)
static void NoteOnEvent(opl_track_data_t *track, midi_event_t *event)
{
+ genmidi_instr_t *instrument;
opl_voice_t *voice;
opl_channel_data_t *channel;
+ unsigned int note;
printf("note on: channel %i, %i, %i\n",
event->data.channel.channel,
@@ -667,6 +669,23 @@ static void NoteOnEvent(opl_track_data_t *track, midi_event_t *event)
// The channel.
channel = &track->channels[event->data.channel.channel];
+ note = event->data.channel.param1;
+
+ // Percussion channel (10) is treated differently to normal notes.
+
+ if (event->data.channel.channel == 9)
+ {
+ if (note < 35 || note > 81)
+ {
+ return;
+ }
+
+ instrument = &percussion_instrs[note - 35];
+ }
+ else
+ {
+ instrument = channel->instrument;
+ }
// Find a voice to use for this new note.
@@ -679,19 +698,17 @@ static void NoteOnEvent(opl_track_data_t *track, midi_event_t *event)
// Program the voice with the instrument data:
- SetVoiceInstrument(voice, &channel->instrument->opl2_voice);
+ SetVoiceInstrument(voice, &instrument->opl2_voice);
// TODO: Set the volume level.
WriteRegister(OPL_REGS_LEVEL + voice->op2,
volume_mapping_table[channel->volume]);
- printf("volume = %i\n", channel->volume);
-
// Play the note.
voice->channel = channel;
- voice->note = event->data.channel.param1;
+ voice->note = note;
// Write the frequency value to turn the note on.
@@ -840,7 +857,7 @@ static void StartTrack(midi_file_t *file, unsigned int track_num)
// Default is 120 bpm.
// TODO: this is wrong
- track->us_per_beat = 500 * 1000 * 200;
+ track->us_per_beat = 500 * 1000 * 260;
for (i=0; i<MIDI_CHANNELS_PER_TRACK; ++i)
{