Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed May 15, 2020
1 parent 0f13ca9 commit 7a40f1a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
14 changes: 7 additions & 7 deletions tests/unit/test_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#define MIDI_PITCH_AS6 94
#define MIDI_PITCH_B6 95

#define TONE_AS4 479
#define TONE_C4 427
#define TONE_CS4 403
#define TONE_DS4 380
#define TONE_A2 1016
#define TONE_NTSC_AS4 479
#define TONE_NTSC_C4 427
#define TONE_NTSC_CS4 403
#define TONE_NTSC_DS4 380
#define TONE_NTSC_A2 1016

#define SYNTH_C 653
#define SYNTH_AS 1164
#define SYNTH_NTSC_C 653
#define SYNTH_NTSC_AS 1164
#define SYNTH_PAL_C 649

#define SYSEX_EXTENDED_MANU_ID_SECTION 0x00
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_midi_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ static void test_midi_triggers_synth_note_on(UNUSED void** state)
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
print_message("Chan %d\n", chan);
expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);

Expand All @@ -29,7 +29,7 @@ static void test_midi_uses_PAL_frequencies_for_region(UNUSED void** state)
static void test_midi_triggers_synth_note_on_with_velocity(UNUSED void** state)
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume(chan, 63);
expect_value(__wrap_synth_noteOn, channel, chan);

Expand All @@ -44,7 +44,7 @@ static void test_midi_triggers_synth_note_on_with_velocity_and_channel_volume(
expect_synth_volume(chan, MAX_MIDI_VOLUME / 2);
__real_midi_cc(chan, CC_VOLUME, MAX_MIDI_VOLUME / 2);

expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume(chan, MAX_MIDI_VOLUME / 4);
expect_value(__wrap_synth_noteOn, channel, chan);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME / 2);
Expand All @@ -55,7 +55,7 @@ static void test_midi_changing_volume_during_note_on_respects_velocity(
UNUSED void** state)
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume(chan, MAX_MIDI_VOLUME / 2);
expect_value(__wrap_synth_noteOn, channel, chan);

Expand All @@ -72,7 +72,7 @@ static void test_midi_triggers_synth_note_on_boundary_values(
UNUSED void** state)
{
const u8 keys[] = { 11, 106 };
const u16 expectedFrequencies[] = { 617, SYNTH_AS };
const u16 expectedFrequencies[] = { 617, SYNTH_NTSC_AS };
const u8 expectedOctaves[] = { 0, 7 };

for (int index = 0; index < 2; index++) {
Expand Down Expand Up @@ -103,7 +103,7 @@ static void test_midi_triggers_synth_note_off(UNUSED void** state)
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
print_message("Chan %d Note On\n", chan);
expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);

Expand All @@ -121,7 +121,7 @@ static void test_midi_triggers_synth_note_off_when_note_on_has_zero_velocity(
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
print_message("Chan %d Note On\n", chan);
expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);

Expand All @@ -136,7 +136,7 @@ static void test_midi_triggers_synth_note_off_when_note_on_has_zero_velocity(

static void test_midi_triggers_synth_note_on_2(UNUSED void** state)
{
expect_synth_pitch(0, 6, SYNTH_AS);
expect_synth_pitch(0, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 0);

Expand Down Expand Up @@ -467,7 +467,7 @@ static void test_midi_sets_fm_preset(UNUSED void** state)
static void test_midi_sets_synth_pitch_bend(UNUSED void** state)
{
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(chan, 4, SYNTH_C);
expect_synth_pitch(chan, 4, SYNTH_NTSC_C);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);
__real_midi_noteOn(chan, 60, MAX_MIDI_VOLUME);
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_midi_polyphony.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void test_midi_set_overflow_flag_on_polyphony_breach(UNUSED void** state)
__real_midi_cc(0, CC_POLYPHONIC_MODE, 127);

for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(chan, 6, SYNTH_AS);
expect_synth_pitch(chan, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);
__real_midi_noteOn(chan, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);
Expand All @@ -50,7 +50,7 @@ static void test_midi_polyphonic_mode_uses_multiple_fm_channels(
__real_midi_cc(0, CC_POLYPHONIC_MODE, 127);

for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(0, 6, SYNTH_AS);
expect_synth_pitch(0, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 0);

Expand Down Expand Up @@ -80,13 +80,13 @@ static void test_midi_polyphonic_mode_note_off_silences_all_matching_pitch(
__real_midi_cc(0, CC_POLYPHONIC_MODE, 127);

for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(0, 6, SYNTH_AS);
expect_synth_pitch(0, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 0);

__real_midi_noteOn(chan, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);

expect_synth_pitch(1, 6, SYNTH_AS);
expect_synth_pitch(1, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 1);

Expand Down
34 changes: 17 additions & 17 deletions tests/unit/test_midi_psg.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ static void test_midi_psg_note_off_only_triggered_if_specific_note_is_on(
u8 chan = MIN_PSG_CHAN;

expect_psg_attenuation(0, PSG_ATTENUATION_LOUDEST);
expect_psg_tone(0, TONE_C4);
expect_psg_tone(0, TONE_NTSC_C4);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME);

expect_psg_tone(0, TONE_CS4);
expect_psg_tone(0, TONE_NTSC_CS4);
__real_midi_noteOn(chan, MIDI_PITCH_CS4, MAX_MIDI_VOLUME);

__real_midi_noteOff(chan, MIDI_PITCH_C4);
Expand All @@ -143,7 +143,7 @@ static void test_midi_channel_volume_sets_psg_attenuation(UNUSED void** state)
{
__real_midi_cc(MIN_PSG_CHAN, CC_VOLUME, 96);

expect_psg_tone(0, TONE_A2);
expect_psg_tone(0, TONE_NTSC_A2);
expect_psg_attenuation(0, 1);

__real_midi_noteOn(MIN_PSG_CHAN, MIDI_PITCH_A2, MAX_MIDI_VOLUME);
Expand All @@ -153,7 +153,7 @@ static void test_midi_channel_volume_sets_psg_attenuation_2(UNUSED void** state)
{
__real_midi_cc(MIN_PSG_CHAN, CC_VOLUME, MAX_MIDI_VOLUME);

expect_psg_tone(0, TONE_A2);
expect_psg_tone(0, TONE_NTSC_A2);
expect_psg_attenuation(0, 0);

__real_midi_noteOn(MIN_PSG_CHAN, MIDI_PITCH_A2, MAX_MIDI_VOLUME);
Expand All @@ -165,11 +165,11 @@ static void test_midi_sets_psg_pitch_bend_down(UNUSED void** state)
u8 expectedPsgChan = chan - MIN_PSG_CHAN;
print_message("PSG Chan %d\n", expectedPsgChan);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME);

expect_psg_tone(expectedPsgChan, TONE_AS4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_AS4);
__real_midi_pitchBend(chan, 0);
}
}
Expand All @@ -180,11 +180,11 @@ static void test_midi_sets_psg_pitch_bend_up(UNUSED void** state)
u8 expectedPsgChan = chan - MIN_PSG_CHAN;
print_message("PSG Chan %d\n", expectedPsgChan);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME);

expect_psg_tone(expectedPsgChan, TONE_DS4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_DS4);
__real_midi_pitchBend(chan, 0x4000);
}
}
Expand All @@ -195,7 +195,7 @@ static void test_midi_psg_pitch_bend_persists_after_tick(UNUSED void** state)
u8 expectedPsgChan = chan - MIN_PSG_CHAN;
print_message("PSG Chan %d\n", expectedPsgChan);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME);

Expand All @@ -217,7 +217,7 @@ static void test_midi_plays_psg_envelope(UNUSED void** state)

__real_midi_program(chan, 1);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, pitch, MAX_MIDI_VOLUME);

Expand All @@ -235,7 +235,7 @@ static void test_midi_plays_advanced_psg_envelope(UNUSED void** state)

__real_midi_program(chan, 2);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME);

Expand All @@ -253,7 +253,7 @@ static void test_midi_loops_psg_envelope(UNUSED void** state)

__real_midi_program(chan, 4);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME);

Expand Down Expand Up @@ -288,7 +288,7 @@ test_midi_psg_envelope_with_loop_end_continues_playing_after_note_off(

__real_midi_program(chan, 6);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, pitch, MAX_MIDI_VOLUME);

Expand All @@ -311,7 +311,7 @@ test_midi_psg_envelope_with_loop_end_resets_release_note_after_note_silenced(

__real_midi_program(chan, 6);

expect_psg_tone(expectedPsgChan, TONE_C4);
expect_psg_tone(expectedPsgChan, TONE_NTSC_C4);
expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan, pitch, MAX_MIDI_VOLUME);

Expand All @@ -337,7 +337,7 @@ static void test_midi_shifts_semitone_in_psg_envelope(UNUSED void** state)
u8 chan = MIN_PSG_CHAN;
u8 expectedPsgChan = 0;

const u16 expectedInitialTone = TONE_C4;
const u16 expectedInitialTone = TONE_NTSC_C4;
const u16 expectedShiftedTone[SHIFTS]
= { /* Up */ 0x1aa, 0x1a9, 0x1a7, 0x19f, 0x193, 0x17c, 0x140,
/* Down */ 0x1ac, 0x1ad, 0x1b0, 0x1b7, 0x1c4, 0x1df, 0x23a };
Expand Down Expand Up @@ -386,7 +386,7 @@ static void test_midi_pitch_shift_handles_lower_limit_psg_envelope(
const u8 chan = MIN_PSG_CHAN;
const u8 expectedPsgChan = 0;
const u8 minPitch = MIDI_PITCH_A2;
const u16 expectedInitialTone = TONE_A2;
const u16 expectedInitialTone = TONE_NTSC_A2;
const u8 envelope[] = { EEF_LOOP_START, 0x00, 0x80, EEF_END };
const u8* envelopes[] = { envelope };
midi_psg_init(envelopes);
Expand Down Expand Up @@ -417,7 +417,7 @@ static void test_midi_psg_sets_busy_indicators(UNUSED void** state)
{
for (u8 chan = 0; chan < MAX_PSG_CHANS; chan++) {
print_message("Chan %d\n", chan);
expect_psg_tone(chan, TONE_C4);
expect_psg_tone(chan, TONE_NTSC_C4);
expect_psg_attenuation(chan, PSG_ATTENUATION_LOUDEST);
__real_midi_noteOn(chan + MIN_PSG_CHAN, MIDI_PITCH_C4, MAX_MIDI_VOLUME);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void test_synth_sets_octave_and_freq_reg_chan(UNUSED void** state)
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
expect_ym2612_write_channel(chan, 0xA4, 0x22);
expect_ym2612_write_channel(chan, 0xA0, 0x8D);
__real_synth_pitch(chan, 4, SYNTH_C);
__real_synth_pitch(chan, 4, SYNTH_NTSC_C);
}
}

Expand Down

0 comments on commit 7a40f1a

Please sign in to comment.