Skip to content

Commit

Permalink
Merge pull request #362 from mitchmindtree/simple_audio_update
Browse files Browse the repository at this point in the history
Update simple_audio example for nannou_audio v0.2.0 release
  • Loading branch information
mitchmindtree authored Jul 18, 2019
2 parents fdf8bc7 + f12e4ff commit 68a098b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: rust

before_script:
- rustup component add rustfmt

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ winit = "0.19"

[dev-dependencies]
audrey = "0.2"
nannou_audio = "0.1"
nannou_audio = "0.2"
nannou_laser = "0.3"
nannou_osc = "0.1"
shade_runner = "0.1"
Expand Down
12 changes: 8 additions & 4 deletions examples/simple_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ fn model(app: &App) -> Model {
.build()
.unwrap();
// Initialise the audio API so we can spawn an audio stream.
let audio_api = audio::Api::new();
let audio_host = audio::Host::new();
// Initialise the state that we want to live on the audio thread.
let model = Audio {
phase: 0.0,
hz: 440.0,
};
let stream = audio_api.new_output_stream(model, audio).build().unwrap();
let stream = audio_host
.new_output_stream(model)
.render(audio)
.build()
.unwrap();
Model { stream }
}

Expand All @@ -54,9 +58,9 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
// Pause or unpause the audio when Space is pressed.
Key::Space => {
if model.stream.is_playing() {
model.stream.pause();
model.stream.pause().unwrap();
} else {
model.stream.play();
model.stream.play().unwrap();
}
}
// Raise the frequency when the up key is pressed.
Expand Down
10 changes: 7 additions & 3 deletions examples/simple_audio_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ fn model(app: &App) -> Model {
.build()
.unwrap();

// Initialise the audio API so we can spawn an audio stream.
let audio_api = audio::Api::new();
// Initialise the audio host so we can spawn an audio stream.
let audio_host = audio::Host::new();

// Initialise the state that we want to live on the audio thread.
let sounds = vec![];
let model = Audio { sounds };
let stream = audio_api.new_output_stream(model, audio).build().unwrap();
let stream = audio_host
.new_output_stream(model)
.render(audio)
.build()
.unwrap();
Model { stream }
}

Expand Down

0 comments on commit 68a098b

Please sign in to comment.