Skip to content

Commit

Permalink
Merge pull request andrewcsmith#10 from l0calh05t/bela0.3.8b_rust1.52.0
Browse files Browse the repository at this point in the history
Updates for Bela 0.3.8b and Rust 1.52.0/1.53.0
  • Loading branch information
andrewcsmith authored Jun 27, 2021
2 parents 6d09149 + 0f4d3df commit f35c748
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
linker = "arm-none-linux-gnueabihf-gcc"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

.vscode
/target
**/*.rs.bk
Cargo.lock
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ authors = ["Andrew C. Smith <[email protected]>"]

[dependencies]
libc = "0.2"
nix = "0.10"
sample = "0.9"
nix = "0.21"

[dev-dependencies]
sample = { package = "dasp", version = "0.11.0", features = [ "signal", "slice" ] }

[dependencies.bela-sys]
git = "https://github.com/andrewcsmith/bela-sys.git"

[features]
static = [ "bela-sys/static" ]
28 changes: 15 additions & 13 deletions examples/auxiliary_task.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Produces a sine wave while printing "this is a string" repeatedly,
//! appending "LOL" to every iteration.
//!
//!
//! There's an example here for both the stack-allocated and a Boxed closure.
//!
//!
extern crate bela;
extern crate sample;

Expand All @@ -15,24 +15,22 @@ struct PrintTask<F> {
}

impl<F> Auxiliary for PrintTask<F>
where F: FnMut(&mut String),
for<'r> F: FnMut(&'r mut String)
where
F: FnMut(&mut String),
for<'r> F: FnMut(&'r mut String),
{
type Args = String;

fn destructure(&mut self) -> (&mut FnMut(&mut String), &mut Self::Args) {
let PrintTask {
callback,
args,
} = self;
fn destructure(&mut self) -> (&mut dyn FnMut(&mut String), &mut Self::Args) {
let PrintTask { callback, args } = self;

(callback, args)
}
}

struct MyData<'a> {
frame_index: usize,
tasks: Vec<CreatedTask<'a>>
tasks: Vec<CreatedTask<'a>>,
}

type BelaApp<'a> = Bela<AppData<'a, MyData<'a>>>;
Expand Down Expand Up @@ -64,8 +62,12 @@ fn go() -> Result<(), error::Error> {

let mut setup = |_context: &mut Context, user_data: &mut MyData| -> Result<(), error::Error> {
println!("Setting up");
user_data.tasks.push(BelaApp::create_auxiliary_task(&mut boxed, 10, "printing_stuff"));
user_data.tasks.push(BelaApp::create_auxiliary_task(&mut another_print_task, 10, "printing_more_stuff"));
user_data
.tasks
.push(unsafe { BelaApp::create_auxiliary_task(&mut boxed, 10, "printing_stuff") });
user_data.tasks.push(unsafe {
BelaApp::create_auxiliary_task(&mut another_print_task, 10, "printing_more_stuff")
});
Ok(())
};

Expand All @@ -76,7 +78,7 @@ fn go() -> Result<(), error::Error> {
let mut render = |_context: &mut Context, user_data: &mut MyData| {
if user_data.frame_index % 1024 == 0 {
for task in user_data.tasks.iter() {
BelaApp::schedule_auxiliary_task(task);
BelaApp::schedule_auxiliary_task(task).unwrap();
}
}

Expand Down
6 changes: 2 additions & 4 deletions examples/digital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn go() -> Result<(), error::Error> {
let tenms_in_frames = (context.digital_sample_rate() / 100.) as usize;
let hundreadms_in_frames = (tenms_in_frames * 10) as usize;
for f in 0..context.digital_frames() {
let v = if state.idx < tenms_in_frames { 1 } else { 0 };
let v = state.idx < tenms_in_frames;
context.digital_write_once(f, 0, v);
state.idx += 1;
if state.idx > hundreadms_in_frames {
Expand All @@ -35,9 +35,7 @@ fn go() -> Result<(), error::Error> {
}
};

let state = State {
idx: 0,
};
let state = State { idx: 0 };

let user_data = AppData::new(state, &mut render, Some(&mut setup), Some(&mut cleanup));

Expand Down
4 changes: 1 addition & 3 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fn go() -> Result<(), error::Error> {
}
};

let phasor = Phasor {
idx: 0,
};
let phasor = Phasor { idx: 0 };

let user_data = AppData::new(phasor, &mut render, Some(&mut setup), Some(&mut cleanup));

Expand Down
31 changes: 16 additions & 15 deletions examples/sample.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
extern crate bela;
extern crate sample;

use std::{thread, time};
use bela::*;
use sample::{Signal, Sample};
use sample::Signal;
use std::{thread, time};

fn main() {
go().unwrap();
}

fn go() -> Result<(), error::Error> {
let mut setup = |_context: &mut Context, user_data: &mut Option<Box<Signal<Frame=[f64; 1]>>>| -> Result<(), error::Error> {
let mut setup = |_context: &mut Context,
_user_data: &mut Option<Box<dyn Signal<Frame = f64>>>|
-> Result<(), error::Error> {
println!("Setting up");
Ok(())
};

let mut cleanup = |_context: &mut Context, _user_data: &mut Option<Box<Signal<Frame=[f64; 1]>>>| {
println!("Cleaning up");
};
let mut cleanup =
|_context: &mut Context, _user_data: &mut Option<Box<dyn Signal<Frame = f64>>>| {
println!("Cleaning up");
};

// Generates a sine wave with the period of whatever the audio frame
// size is.
let mut render = |context: &mut Context, synth: &mut Option<Box<Signal<Frame=[f64; 1]>>>| {
let audio_frames = context.audio_frames();
let mut render = |context: &mut Context, synth: &mut Option<Box<dyn Signal<Frame = f64>>>| {
let audio_out_channels = context.audio_out_channels();
assert_eq!(audio_out_channels, 2);
assert_eq!(audio_out_channels, 2);
let audio_out = context.audio_out();
let audio_out_frames: &mut [[f32; 2]] = sample::slice::to_frame_slice_mut(audio_out).unwrap();
let audio_out_frames: &mut [[f32; 2]] =
sample::slice::to_frame_slice_mut(audio_out).unwrap();

for frame in audio_out_frames.iter_mut() {
for samp in frame.iter_mut() {
let val = synth.as_mut().unwrap().next();
*samp = val[0] as f32;
*samp = val as f32;
}
}
};

let sig = sample::signal::rate(44_100.0)
.const_hz(440.0)
.sine();
let sig = sample::signal::rate(44_100.0).const_hz(440.0).sine();

let synth: Option<Box<Signal<Frame=[f64; 1]>>> = Some(Box::new(sig));
let synth: Option<Box<dyn Signal<Frame = f64>>> = Some(Box::new(sig));

let user_data = AppData::new(synth, &mut render, Some(&mut setup), Some(&mut cleanup));

Expand Down
Empty file added rustfmt.toml
Empty file.
Loading

0 comments on commit f35c748

Please sign in to comment.