Skip to content

Commit

Permalink
Ensure pitch bend respected before note on (FM channels)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Jul 24, 2024
1 parent 0d07d15 commit c5bf817
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/midi_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ static const u8 FREQ_NORMAL_RANGE_OFFSET = 2;

typedef struct MidiFmChannel {
u8 pitch;
u16 pitchBend;
u8 volume;
u8 velocity;
u8 pan;
bool percussive;
u16 pitchBend;
} MidiFmChannel;

static MidiFmChannel fmChannels[MAX_FM_CHANS];
Expand Down
5 changes: 0 additions & 5 deletions tests/asserts.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ void expect_synth_volume(u8 channel, u8 volume)
expect_value(__wrap_synth_volume, volume, volume);
}

void expect_synth_volume_any(void)
{
expect_any(__wrap_synth_volume, channel);
expect_any(__wrap_synth_volume, volume);
}
void expect_synth_noteOn(u8 chan)
{
expect_value(__wrap_synth_noteOn, channel, chan);
Expand Down
7 changes: 6 additions & 1 deletion tests/asserts.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ void stub_usb_receive_pitch_bend(u8 chan, u16 bend);
void stub_comm_read_returns_midi_event(u8 status, u8 data, u8 data2);
void expect_ym2612_write_operator_any_data(u8 chan, u8 op, u8 baseReg);
void expect_synth_noteOn(u8 chan);
void expect_synth_volume_any(void);
void expect_synth_volume(u8 channel, u8 volume);
u8 regOpIndex(u8 op);

Expand Down Expand Up @@ -96,6 +95,12 @@ void _expect_ym2612_write_operator(

#define expect_synth_pitch_any() _expect_synth_pitch_any(__FILE__, __LINE__)

#define expect_synth_volume_any() \
{ \
expect_any(__wrap_synth_volume, channel); \
expect_any(__wrap_synth_volume, volume); \
}

#define expect_ym2612_write_operator(chan, op, baseReg, data) \
_expect_ym2612_write_operator(chan, op, baseReg, data, __FILE__, __LINE__)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int main(void)
midi_test(test_midi_channel_volume_sets_psg_attenuation),
midi_test(test_midi_channel_volume_sets_psg_attenuation_2),
midi_test(test_midi_sets_synth_pitch_bend),
midi_test(test_midi_sets_synth_pitch_bend_before_note_on),
midi_test(test_midi_pitch_bends_down_an_octave),
midi_test(test_midi_pitch_bends_up_an_octave),
midi_test(test_midi_pitch_bends_up_an_octave_upper_freq_limit),
Expand Down Expand Up @@ -379,8 +380,7 @@ int main(void)
midi_portamento_test(test_midi_portamento_glides_fully_up_and_down),
midi_portamento_test(test_midi_portamento_synth_note_off_triggered),
midi_portamento_test(test_midi_portamento_zeros_any_residual_cents),
midi_portamento_test(test_midi_portamento_glides_note_up_for_psg)
// TODO: test for PSG glide
midi_portamento_test(test_midi_portamento_glides_note_up_for_psg),
// TODO: test for special mode glide
// TODO: pitch bend conflicts
// clang-format on
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_midi_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ static void test_midi_sets_synth_pitch_bend(UNUSED void** state)
}
}

static void test_midi_sets_synth_pitch_bend_before_note_on(UNUSED void** state)
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
print_message("channel %d\n", chan);
expect_synth_pitch(chan, 4, 0x246);
__real_midi_pitch_bend(chan, 1000);

print_message("note on %d\n", chan);
expect_synth_pitch(chan, 4, 0x246);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);
__real_midi_note_on(chan, 60, MAX_MIDI_VOLUME);
}
}

static void test_midi_pitch_bends_down_an_octave(UNUSED void** state)
{
const u8 MIDI_PITCH_B3 = 59;
Expand Down

0 comments on commit c5bf817

Please sign in to comment.