chore(apu): update spsc depenency

This commit is contained in:
2021-10-07 15:27:51 -03:00
parent 64230973f1
commit 352a65b705
5 changed files with 84 additions and 114 deletions

View File

@@ -5,33 +5,12 @@ pub(crate) const SAMPLE_RATE: u32 = 48000; // Hz
const CHANNEL_COUNT: usize = 2;
const BUFFER_CAPACITY: usize = 2048 * CHANNEL_COUNT; // # of samples * the # of channels
pub struct AudioSPSC<T> {
inner: RingBuffer<T>,
}
impl<T> Default for AudioSPSC<T> {
fn default() -> Self {
Self {
inner: RingBuffer::new(BUFFER_CAPACITY),
}
}
}
impl<T> AudioSPSC<T> {
pub fn new(capacity: usize) -> Self {
Self {
inner: RingBuffer::new(capacity),
}
}
pub fn init(self) -> (SampleProducer<T>, SampleConsumer<T>) {
let (prod, cons) = self.inner.split();
(
SampleProducer { inner: prod },
SampleConsumer { inner: cons },
)
}
pub fn init<T>() -> (SampleProducer<T>, SampleConsumer<T>) {
let (prod, cons) = RingBuffer::new(BUFFER_CAPACITY);
(
SampleProducer { inner: prod },
SampleConsumer { inner: cons },
)
}
pub struct SampleProducer<T> {

View File

@@ -1,4 +1,4 @@
pub use apu::gen::AudioSPSC;
pub use apu::gen::init as spsc_init;
pub type Cycle = u64;
pub const GB_WIDTH: usize = 160;

View File

@@ -3,7 +3,7 @@ use std::convert::TryInto;
use anyhow::{anyhow, Result};
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
use gb::emu::build::EmulatorBuilder;
use gb::{AudioSPSC, Cycle, GB_HEIGHT, GB_WIDTH};
use gb::{Cycle, GB_HEIGHT, GB_WIDTH};
use gilrs::Gilrs;
use pixels::{PixelsBuilder, SurfaceTexture};
use rodio::{OutputStream, Sink};
@@ -74,8 +74,7 @@ fn main() -> Result<()> {
let (_stream, stream_handle) = OutputStream::try_default().expect("Initialized Audio");
if AUDIO_ENABLED {
let spsc: AudioSPSC<f32> = Default::default();
let (prod, cons) = spsc.init();
let (prod, cons) = gb::spsc_init();
let sink = {
let s = Sink::try_new(&stream_handle)?;
s.append(cons);