Skip to content

Commit

Permalink
Rename audio::Interface::start to audio::Interface::spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed May 17, 2021
1 parent 356f889 commit a281c40
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/audio_midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() -> ! {
let mut midi_parser = instrument::midi::Parser::new();
let midi_note_clone = Arc::clone(&midi_note);

let midi_interface = midi_interface.start(move |byte| {
let midi_interface = midi_interface.spawn(move |byte| {
midi_parser.rx(byte, |_channel, message| {
if let instrument::midi::Message::NoteOn { note, velocity: _ } = message {
loggit!("note_on: {:?}", note);
Expand All @@ -69,7 +69,7 @@ fn main() -> ! {

// - audio callback -------------------------------------------------------

let audio_interface = audio_interface.start(move |fs, block| {
let audio_interface = audio_interface.spawn(move |fs, block| {
let midi_note = midi_note.load(Ordering::Relaxed);
let frequency = instrument::midi::to_hz(midi_note);
osc.dx = (1. / fs) * frequency;
Expand Down
4 changes: 2 additions & 2 deletions examples/audio_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ fn main() -> ! {
}
}

audio_interface.start(callback).unwrap()
audio_interface.spawn(callback).unwrap()
};

// handle callback with closure (needs alloc)
#[cfg(any(feature = "alloc"))]
let audio_interface = audio_interface.start(|_fs, block| {
let audio_interface = audio_interface.spawn(|_fs, block| {
for frame in block {
let (left, right) = *frame;
*frame = (left, right);
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_testsignal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn main() -> ! {
let mut osc_1: osc::Wavetable = osc::Wavetable::new(osc::Shape::Sin);
let mut osc_2: osc::Wavetable = osc::Wavetable::new(osc::Shape::Saw);

audio_interface.start(move |fs, block| {
audio_interface.spawn(move |fs, block| {
osc_1.dx = (1. / fs) * 110.00;
osc_2.dx = (1. / fs) * 110.00;
for frame in block {
Expand Down
10 changes: 5 additions & 5 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,22 @@ impl<'a> Interface<'a> {

/// assign function pointer for interrupt callback and start audio
#[cfg(not(feature = "alloc"))]
pub fn start(mut self, function_ptr:fn (f32, &mut Block)) -> Result<Self, Error> {
pub fn spawn(mut self, function_ptr:fn (f32, &mut Block)) -> Result<Self, Error> {
self.function_ptr = Some(function_ptr);
self.start_audio()?;
self.start()?;
Ok(self) // TODO type state for started audio interface
}

/// assign closure for interrupt callback and start audio
#[cfg(any(feature = "alloc"))]
pub fn start<F: FnMut(f32, &mut Block) + Send + Sync + 'a>(mut self, closure: F) -> Result<Self, Error> {
pub fn spawn<F: FnMut(f32, &mut Block) + Send + Sync + 'a>(mut self, closure: F) -> Result<Self, Error> {
self.closure = Some(Box::new(closure));
self.start_audio()?;
self.start()?;
Ok(self) // TODO type state for started audio interface
}


fn start_audio(&mut self) -> Result<(), Error> {
fn start(&mut self) -> Result<(), Error> {
// - AK4556 -----------------------------------------------------------

let ak4556_reset = self.ak4556_reset.as_mut().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ impl<'a> Interface<'a> {

/// assign function pointer for interrupt callback and start interface
#[cfg(not(feature = "alloc"))]
pub fn start(mut self, function_ptr:fn (u8)) -> Result<Self, Error> {
pub fn spawn(mut self, function_ptr:fn (u8)) -> Result<Self, Error> {
self.function_ptr = Some(function_ptr);
unsafe { pac::NVIC::unmask(pac::Interrupt::USART1); }
Ok(self)
}

/// assign closure for interrupt callback and start interface
#[cfg(any(feature = "alloc"))]
pub fn start<F: FnMut(u8) + Send + 'a>(mut self, closure: F) -> Result<Self, Error> {
pub fn spawn<F: FnMut(u8) + Send + 'a>(mut self, closure: F) -> Result<Self, Error> {
self.closure = Some(Box::new(closure));
unsafe { pac::NVIC::unmask(pac::Interrupt::USART1); }
Ok(self)
Expand Down

0 comments on commit a281c40

Please sign in to comment.