Skip to content

Commit

Permalink
Assign DAC to dev chan 5 when enabled instead of using separate virtu…
Browse files Browse the repository at this point in the history
…al channel
  • Loading branch information
rhargreaves committed Aug 30, 2024
1 parent 1701770 commit 65a742d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ static void initDeviceChannel(u8 devChan)
} else if (devChan <= DEV_CHAN_MAX_PSG) {
chan->number = devChan - DEV_CHAN_MIN_PSG;
chan->ops = &PSG_VTable;
} else if (devChan <= DEV_CHAN_MAX_SPECIAL_MODE) {
} else {
chan->number = devChan - DEV_CHAN_MIN_SPECIAL_MODE;
chan->ops = &SpecialMode_VTable;
} else {
chan->number = DEV_CHAN_DAC;
chan->ops = &DAC_VTable;
}
chan->noteOn = false;
chan->midiChannel = devChan;
Expand Down Expand Up @@ -733,6 +730,12 @@ static void setOperatorTotalLevel(u8 chan, u8 op, u8 value)
synth_operatorTotalLevel(chan, op, value);
}

static void enableDac(bool enable)
{
deviceChannels[5].ops = enable ? &DAC_VTable : &FM_VTable;
synth_enableDac(enable);
}

static void setFmChanParameter(DeviceChannel* devChan, u8 controller, u8 value)
{
switch (controller) {
Expand Down Expand Up @@ -870,7 +873,7 @@ static void setFmChanParameter(DeviceChannel* devChan, u8 controller, u8 value)
case CC_GENMDM_ENABLE_DAC:
if (isIgnoringNonGeneralMidiCCs())
break;
synth_enableDac(RANGE(value, 2));
enableDac(RANGE(value, 2));
break;
case CC_EXPRESSION:
case CC_SUSTAIN_PEDAL:
Expand Down
3 changes: 1 addition & 2 deletions src/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define PSG_NOISE_CHAN 3
#define GENERAL_MIDI_PERCUSSION_CHANNEL 9

#define DEV_CHANS 14
#define DEV_CHANS 13
#define DEV_PHYSICAL_CHANS 10
#define DEV_CHAN_MIN_FM 0
#define DEV_CHAN_MAX_FM 5
Expand All @@ -27,7 +27,6 @@
#define DEV_CHAN_MAX_PSG 9
#define DEV_CHAN_MIN_SPECIAL_MODE 10
#define DEV_CHAN_MAX_SPECIAL_MODE 12
#define DEV_CHAN_DAC 13

#define CC_PORTAMENTO_TIME_MSB 5
#define CC_DATA_ENTRY_MSB 6
Expand Down
11 changes: 3 additions & 8 deletions tests/system/test_e2e.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const u8 TEST_CC_PORTAMENTO_TIME = 5;
static const u8 TEST_CC_VOLUME = 7;
static const u8 TEST_CC_ALGORITHM = 14;
static const u8 TEST_CC_PORTAMENTO_ON = 65;
static const u8 TEST_CC_ENABLE_DAC = 78;
static const u8 TEST_CC_SPECIAL_MODE = 80;
static const u8 TEST_CC_POLYPHONIC = 84;
static const u8 TEST_CC_DEVICE_SELECT = 86;
Expand Down Expand Up @@ -269,14 +270,8 @@ static void test_write_directly_to_ym2612_regs_via_sysex(void** state)

static void test_plays_pcm_sample(void** state)
{
const u8 MIDI_CHANNEL_UNASSIGNED = 0x7F;
const u8 DEVICE_FM_6 = 5;
const u8 DEVICE_PCM = 13;

remapChannel(MIDI_CHANNEL_UNASSIGNED, DEVICE_FM_6);
midi_receiver_read();

remapChannel(TEST_MIDI_CHANNEL_6, DEVICE_PCM);
stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_ENABLE_DAC, 127);
expect_ym2612_write_reg(0, 0x2B, 0x80);
midi_receiver_read();

stub_usb_receive_note_on(TEST_MIDI_CHANNEL_6, 60, TEST_VOLUME_MAX);
Expand Down

0 comments on commit 65a742d

Please sign in to comment.