mono vst + dont panic on wrong number of channels

This commit is contained in:
Alex Janka 2023-10-26 13:16:29 +11:00
parent fcf0ecac02
commit 5d61d4466a

View file

@ -129,18 +129,32 @@ impl Plugin for GameboyEmu {
const VERSION: &'static str = "0.1"; const VERSION: &'static str = "0.1";
const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[AudioIOLayout { const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[
main_input_channels: None, AudioIOLayout {
main_output_channels: NonZeroU32::new(2), main_input_channels: None,
main_output_channels: NonZeroU32::new(2),
aux_input_ports: &[], aux_input_ports: &[],
aux_output_ports: &[], aux_output_ports: &[],
// Individual ports and the layout as a whole can be named here. By default these names // Individual ports and the layout as a whole can be named here. By default these names
// are generated as needed. This layout will be called 'Stereo', while the other one is // are generated as needed. This layout will be called 'Stereo', while the other one is
// given the name 'Mono' based no the number of input and output channels. // given the name 'Mono' based no the number of input and output channels.
names: PortNames::const_default(), names: PortNames::const_default(),
}]; },
AudioIOLayout {
main_input_channels: None,
main_output_channels: NonZeroU32::new(1),
aux_input_ports: &[],
aux_output_ports: &[],
// Individual ports and the layout as a whole can be named here. By default these names
// are generated as needed. This layout will be called 'Stereo', while the other one is
// given the name 'Mono' based no the number of input and output channels.
names: PortNames::const_default(),
},
];
const MIDI_INPUT: MidiConfig = MidiConfig::MidiCCs; const MIDI_INPUT: MidiConfig = MidiConfig::MidiCCs;
const SAMPLE_ACCURATE_AUTOMATION: bool = true; const SAMPLE_ACCURATE_AUTOMATION: bool = true;
@ -228,15 +242,25 @@ impl Plugin for GameboyEmu {
} }
} }
if buffer.channels() != 2 { if buffer.channels() != 2 {
panic!() for mut sample in buffer.iter_samples() {
} if vars.rx.is_empty() {
for sample in buffer.iter_samples() { vars.emulator_core.run_until_buffer_full();
if vars.rx.is_empty() { }
vars.emulator_core.run_until_buffer_full(); if let Some(a) = executor::block_on(vars.rx.pop()) {
if let Some(g) = sample.get_mut(0) {
*g = (a[0] + a[1]) / 2.;
}
}
} }
if let Some(a) = executor::block_on(vars.rx.pop()) { } else {
for (source, dest) in a.iter().zip(sample) { for sample in buffer.iter_samples() {
*dest = *source; if vars.rx.is_empty() {
vars.emulator_core.run_until_buffer_full();
}
if let Some(a) = executor::block_on(vars.rx.pop()) {
for (source, dest) in a.iter().zip(sample) {
*dest = *source;
}
} }
} }
} }