vst makes audio!!

This commit is contained in:
Alex Janka 2023-03-07 09:53:56 +11:00
parent fbd3d51693
commit e80b961eca
3 changed files with 29 additions and 29 deletions

View file

@ -70,34 +70,20 @@ impl Plugin for GameboyEmu {
_: &mut AuxiliaryBuffers,
_: &mut impl ProcessContext<Self>,
) -> ProcessStatus {
nih_log!("processing");
if let Some(ref mut vars) = self.vars {
vars.emulator_core.run_until_buffer_full();
if buffer.channels() != 2 {
panic!()
}
let mut got_any = false;
let mut got_nonzero = false;
for sample in buffer.iter_samples() {
if let Some(a) = executor::block_on(vars.rx.pop()) {
got_any = true;
if (a[0] != 0.) || (a[1] != 0.) {
got_nonzero = true;
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;
}
}
}
if got_any {
if got_nonzero {
nih_log!("got some real data");
} else {
nih_log!("got some 0's");
}
}
} else {
nih_log!("vars not initialised");
}
ProcessStatus::KeepAlive
}
@ -118,7 +104,7 @@ impl Plugin for GameboyEmu {
no_save: true,
bootrom_path: None,
connect_serial: false,
verbose: true,
verbose: false,
cycle_count: false,
};
let (sender, receiver) = channel::<EmulatorMessage>();

View file

@ -154,13 +154,10 @@ impl EmulatorCore {
}
pub fn run_until_buffer_full(&mut self) {
println!("running until buffer full!!");
while !self.cpu.memory.is_audio_buffer_full() {
loop {
self.run();
}
}
}
fn run_cycle(&mut self) {
let will_pause = unsafe { PAUSE_QUEUED };

View file

@ -42,6 +42,7 @@ pub struct Apu {
mixer: Mixer,
div_apu: u8,
buffer: Vec<DacSample>,
out_buffer: Vec<[f32; 2]>,
converter: Downsampler,
output: AudioOutput,
}
@ -57,6 +58,7 @@ impl Apu {
mixer: Mixer::default(),
div_apu: 0,
buffer: vec![],
out_buffer: vec![],
converter: Downsampler::new(output.sample_rate),
output,
}
@ -101,18 +103,33 @@ impl Apu {
);
if self.buffer.len() >= CYCLES_PER_FRAME {
self.next_audio();
} else if !self.out_buffer.is_empty() {
self.push_audio();
}
}
fn next_audio(&mut self) {
let converted = self.converter.process(
self.out_buffer.append(
&mut self.converter.process(
self.buffer
.drain(..)
.map(|v| v.mixed(&self.mixer))
.collect::<Vec<[f32; 2]>>(),
),
);
println!("pushing {} samples to queue", converted.len());
executor::block_on(self.output.send_rb.push_slice(&converted)).unwrap();
self.push_audio();
}
fn push_audio(&mut self) {
let length = self.out_buffer.len().min(self.output.send_rb.free_len());
executor::block_on(
self.output
.send_rb
.push_slice(&self.out_buffer.drain(..length).collect::<Vec<[f32; 2]>>()),
)
.unwrap();
}
pub fn is_buffer_full(&self) -> bool {