Skip to content

Commit

Permalink
Stop DAC playback on note off
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Aug 30, 2024
1 parent 3e7cfab commit 1444d84
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/midi_dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void midi_dac_reset(void)

void midi_dac_note_off(u8 chan, u8 pitch)
{
SND_PCM_stopPlay();
}

void midi_dac_channel_volume(u8 chan, u8 volume)
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ MD_MOCKS=SYS_setVIntCallback \
TSK_userSet \
mw_def_ap_cfg_get \
SND_PCM_startPlay \
SND_PCM_stopPlay \
Z80_loadDriver \
Z80_releaseBus \
Z80_requestBus \
Expand Down
1 change: 1 addition & 0 deletions tests/unit/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ int main(void)
midi_test(test_midi_resets_psg_values_to_defaults),

midi_dac_test(test_midi_dac_plays_note),
midi_dac_test(test_midi_dac_stops_note),

pitchcents_test(test_pitchcents_shift_extreme_up),
pitchcents_test(test_pitchcents_bend_nil),
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_midi_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ static void test_midi_dac_plays_note(UNUSED void** state)

__real_midi_note_on(5, 100, 100);
}

static void test_midi_dac_stops_note(UNUSED void** state)
{
expect_any(__wrap_SND_PCM_startPlay, sample);
expect_any(__wrap_SND_PCM_startPlay, len);
expect_any(__wrap_SND_PCM_startPlay, rate);
expect_value(__wrap_SND_PCM_startPlay, pan, SOUND_PAN_CENTER);
expect_value(__wrap_SND_PCM_startPlay, loop, 0);

__real_midi_note_on(5, 100, 100);

expect_function_call(__wrap_SND_PCM_stopPlay);

__real_midi_note_off(5, 100);
}
5 changes: 5 additions & 0 deletions tests/wraps.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ void __wrap_SND_PCM_startPlay(const u8* sample, const u32 len, const SoundPcmSam
check_expected(loop);
}

void __wrap_SND_PCM_stopPlay(void)
{
function_called();
}

void __wrap_Z80_loadDriver(const u16 driver, const bool waitReady)
{
if (disableChecks)
Expand Down
1 change: 1 addition & 0 deletions tests/wraps.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void __wrap_JOY_init(void);
void __wrap_TSK_userSet(VoidCallback* task);
void __wrap_SND_PCM_startPlay(const u8* sample, const u32 len, const SoundPcmSampleRate rate,
const SoundPanning pan, const u8 loop);
void __wrap_SND_PCM_stopPlay(void);
void __wrap_Z80_loadDriver(const u16 driver, const bool waitReady);
void __wrap_Z80_requestBus(bool wait);
bool __wrap_Z80_getAndRequestBus(bool wait);
Expand Down

0 comments on commit 1444d84

Please sign in to comment.