Skip to content

Commit

Permalink
chore: update kira to main (0.9)
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarLiner committed May 8, 2024
1 parent 1932421 commit 743a762
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 95 deletions.
52 changes: 33 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
kira = { version = "0.8.7", features = ["serde"] }
bevy_math = { version = "0.13.2", features = ["mint"] }
kira = { version = "0.8.6", git = "https://github.com/tesselode/kira.git", branch = "main", features = ["serde"] }
mint = "0.5.9"
thiserror = "1.0.57"
serde = { version = "1.0.197", features = ["derive"] }

Expand Down
12 changes: 6 additions & 6 deletions examples/audio_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! For loading additional audio formats, you can enable the corresponding feature for that audio format.
use bevy::prelude::*;
use bevy::utils::error;

use bevy_kira_components::kira::sound::{PlaybackRate, PlaybackState};
use bevy_kira_components::kira::tween::Tween;
use bevy_kira_components::prelude::*;
Expand Down Expand Up @@ -35,7 +35,7 @@ fn update_speed(
) {
if let Ok(mut control) = music_controller.get_single_mut() {
let factor = ((time.elapsed_seconds() / 5.0).sin() + 1.0).max(0.1);
error(control.set_playback_rate(PlaybackRate::Factor(factor as f64), Tween::default()));
control.set_playback_rate(PlaybackRate::Factor(factor as f64), Tween::default());
}
}

Expand All @@ -47,10 +47,10 @@ fn pause(
if let Ok(mut control) = music_controller.get_single_mut() {
match control.playback_state() {
PlaybackState::Playing => {
error(control.pause(Tween::default()));
control.pause(Tween::default());
}
PlaybackState::Pausing | PlaybackState::Paused => {
error(control.resume(Tween::default()));
control.resume(Tween::default());
}
PlaybackState::Stopping | PlaybackState::Stopped => {}
}
Expand All @@ -66,10 +66,10 @@ fn volume(
if let Ok(mut control) = music_controller.get_single_mut() {
if keyboard_input.just_pressed(KeyCode::Equal) {
*target_volume += 0.1;
error(control.set_volume(*target_volume + 1.0, Tween::default()));
control.set_volume(*target_volume + 1.0, Tween::default());
} else if keyboard_input.just_pressed(KeyCode::Minus) {
*target_volume -= 0.1;
error(control.set_volume(*target_volume + 1.0, Tween::default()));
control.set_volume(*target_volume + 1.0, Tween::default());
}
}
}
16 changes: 8 additions & 8 deletions examples/custom_sound/src/sine_wave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ringbuf::{HeapConsumer, HeapProducer, HeapRb};
pub struct SineWavePlugin;

impl Plugin for SineWavePlugin {
fn build(&self, app: &mut bevy::prelude::App) {
fn build(&self, app: &mut App) {
app.add_plugins(AudioSourcePlugin::<SineWave>::default());
}
}
Expand All @@ -39,14 +39,14 @@ enum SineWaveCommand {
SetFrequency(Value<f32>, Tween),
}

/// Implementation of [`kira::sound::Sound`] that generates a sine wave at the given frequency.
/// Implementation of [`Sound`] that generates a sine wave at the given frequency.
struct SineWaveSound {
/// Output destination. This tells kira where to route the audio data that the output of our
/// `Sound` implementation
output: kira::OutputDestination,
/// Commands receiver (aka. a consumer) of commands sent from other threads
commands: HeapConsumer<SineWaveCommand>,
/// Sine wave frequency (in Hz). Reuses `kira`'s [`kira::tween::Parameter`] struct to provide
/// Sine wave frequency (in Hz). Reuses `kira`'s [`Parameter`] struct to provide
/// click-free changes and ability to provide modulations.
frequency: Parameter<f32>,
/// Internal phase of the sine wave. We keep track of the phase instead of the time, as this
Expand All @@ -55,16 +55,16 @@ struct SineWaveSound {
}

impl Sound for SineWaveSound {
fn output_destination(&mut self) -> bevy_kira_components::kira::OutputDestination {
fn output_destination(&mut self) -> kira::OutputDestination {
self.output
}

fn process(
&mut self,
dt: f64,
clock_info_provider: &bevy_kira_components::kira::clock::clock_info::ClockInfoProvider,
modulator_value_provider: &bevy_kira_components::kira::modulator::value_provider::ModulatorValueProvider,
) -> bevy_kira_components::kira::dsp::Frame {
clock_info_provider: &kira::clock::clock_info::ClockInfoProvider,
modulator_value_provider: &kira::modulator::value_provider::ModulatorValueProvider,
) -> kira::Frame {
// Receive and perform commands
while let Some(command) = self.commands.pop() {
match command {
Expand All @@ -84,7 +84,7 @@ impl Sound for SineWaveSound {
let sample = 0.125 * f32::sin(TAU * self.phase);

// Return the new stereo sample
kira::dsp::Frame {
kira::Frame {
left: sample,
right: sample,
}
Expand Down
4 changes: 2 additions & 2 deletions examples/interactive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ fn handle_interactive_sound(
}
if keyboard.just_pressed(KeyCode::Space) {
for (mut handle, mut sprite) in &mut q {
error(handle.resume(Tween::default()));
handle.resume(Tween::default());
sprite.color = Color::GREEN;
}
} else if keyboard.just_released(KeyCode::Space) {
for (mut handle, mut sprite) in &mut q {
error(handle.pause(Tween::default()));
handle.pause(Tween::default());
sprite.color = Color::GRAY;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/spatial/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ fn fake_doppler_effect(
let local_dir = Vec3::normalize(cam_transform.translation - transform.translation());
doppler.0 = (SPEED_OF_SOUND - cam_motion.motion().dot(local_dir))
/ (SPEED_OF_SOUND - motion.motion().dot(local_dir));
error(handle.set_playback_rate(PlaybackRate::Factor(doppler.0 as _), Tween::default()));
handle.set_playback_rate(PlaybackRate::Factor(doppler.0 as _), Tween::default());
}
}
2 changes: 1 addition & 1 deletion src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Backend for AudioBackend {
fn setup(settings: Self::Settings) -> Result<(Self, u32), Self::Error> {
match settings {
AudioBackendSelector::Physical => {
let (backend, sample_rate) = CpalBackend::setup(())?;
let (backend, sample_rate) = CpalBackend::setup(default())?;
Ok((Self::Physical(backend), sample_rate))
}
AudioBackendSelector::Mock { sample_rate } => {
Expand Down
5 changes: 1 addition & 4 deletions src/sources/audio_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,14 @@ impl Default for AudioFileSettings {

fn play_sound_error_transmute<Out>(err: PlaySoundError<()>) -> PlaySoundError<Out> {
match err {
PlaySoundError::CommandError(cmd) => PlaySoundError::CommandError(cmd),
PlaySoundError::SoundLimitReached => PlaySoundError::SoundLimitReached,
_ => unreachable!(),
_ => unreachable!("Cannot magically go from () to {}", std::any::type_name::<Out>()),
}
}

fn play_sound_error_cast<In, Out: From<In>>(err: PlaySoundError<In>) -> PlaySoundError<Out> {
match err {
PlaySoundError::CommandError(cmd) => PlaySoundError::CommandError(cmd),
PlaySoundError::SoundLimitReached => PlaySoundError::SoundLimitReached,
PlaySoundError::IntoSoundError(input) => PlaySoundError::IntoSoundError(input.into()),
_ => unreachable!(),
}
}
Loading

0 comments on commit 743a762

Please sign in to comment.