Skip to content

Commit

Permalink
Update to bevy 0.10 (#31)
Browse files Browse the repository at this point in the history
* Initial update

* Fix send and sync stuff

* Update compatibility table

* Update changelog and version
  • Loading branch information
harudagondi authored Mar 7, 2023
1 parent e0fb4d6 commit 00da900
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 51 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0] - 14-11-2022

Updated bevy and other crate dependencies.

### Added

- Implemented `Signal` for `IterMono` (`bevy_oddio`)

## [0.2.0] - 14-11-2022

Reworked the majority of the internals.
Expand Down Expand Up @@ -36,6 +44,7 @@ Reworked the majority of the internals.

- New bevy plugin! `bevy_fundsp` integrates fundsp with bevy.

[Unreleased]: https://github.com/harudagondi/bevy_fundsp/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/harudagondi/bevy_fundsp/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/harudagondi/bevy_fundsp/compare/v0.1.0...v0.3.0
[0.2.0]: https://github.com/harudagondi/bevy_fundsp/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/harudagondi/bevy_fundsp/releases/tag/v0.1.0
20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_fundsp"
authors = ["Gio Genre De Asis"]
version = "0.2.0"
version = "0.3.0"
edition = "2021"
description = "A Bevy plugin that integrates FunDSP into Bevy."
homepage = "https://github.com/harudagondi/bevy_fundsp"
Expand All @@ -22,7 +22,7 @@ oddio = ["bevy_oddio"]
fundsp = "0.12"
cpal = "0.15"
once_cell = "1.13"
rodio = { version = "0.16", default-features = false, features = ["wav"], optional = true }
rodio = { version = "0.17.1", default-features = false, features = ["wav"], optional = true }
kira = { version = "0.7", default-features = false, features = ["wav"], optional = true }

[dependencies.uuid]
Expand All @@ -33,32 +33,38 @@ features = [

[dependencies.bevy]
# git = "https://github.com/bevyengine/bevy"
version = "0.9"
version = "0.10"
default-features = false
features = ["bevy_asset"]

[dependencies.bevy_kira_audio]
# git = "https://github.com/NiklasEi/bevy_kira_audio.git"
# branch = "bevy_main"
version = "0.13"
version = "0.15"
default-features = false
features = ["wav"]
optional = true

[dependencies.bevy_oddio]
# git = "https://github.com/harudagondi/bevy_oddio"
# branch = "bevy_main"
version = "0.3"
version = "0.4"
default-features = false
optional = true
features = ["wav"]

[dev-dependencies.bevy]
# git = "https://github.com/bevyengine/bevy"
version = "0.9"
version = "0.10"
default-features = false
features = [
"render",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_gltf",
"bevy_render",
"bevy_sprite",
"bevy_text",
"bevy_ui",
"animation",
"bevy_winit",
"bevy_gilrs",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ or multiplying your DSP graph with a low constant (lower than 1.0).
```rust no_run
#![allow(clippy::precedence)]

use bevy::prelude::*;
use bevy_fundsp::prelude::*;
use {bevy::prelude::*, bevy_fundsp::prelude::*};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(DspPlugin::default())
.add_dsp_source(white_noise, SourceType::Dynamic)
.add_startup_system_to_stage(StartupStage::PostStartup, play_noise)
.add_startup_system(play_noise.in_base_set(StartupSet::PostStartup))
.run();
}

Expand All @@ -55,6 +54,7 @@ fn play_noise(
| `bevy_fundsp` | `bevy` | `bevy_kira_audio` | `bevy_oddio` | `fundsp` |
| ------------- | ------ | ----------------- | ------------ | -------- |
| bevy_main | main | bevy_main | bevy_main | main |
| 0.3.0 | 0.10 | 0.15 | 0.4 | 0.12 |
| 0.2.0 | 0.9 | 0.13 | 0.3 | 0.9 |
| 0.1.0 | 0.8 | 0.11 | | 0.6 |

Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_audio/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(DspPlugin::default())
.add_dsp_source(white_noise, SourceType::Dynamic)
.add_startup_system_to_stage(StartupStage::PostStartup, play_noise)
.add_startup_system(play_noise.in_base_set(StartupSet::PostStartup))
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion examples/kira/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
.add_plugin(AudioPlugin)
.add_plugin(DspPlugin::default())
.add_dsp_source(white_noise, SourceType::Static { duration: 60.0 })
.add_startup_system_to_stage(StartupStage::PostStartup, play_noise)
.add_startup_system(play_noise.in_base_set(StartupSet::PostStartup))
.run();
}

Expand Down
8 changes: 4 additions & 4 deletions examples/oddio/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
use {
bevy::prelude::*,
bevy_fundsp::prelude::*,
bevy_oddio::{frames::Stereo, Audio, AudioPlugin, AudioSource},
bevy_oddio::{Audio, AudioPlugin, AudioSource},
};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_plugin(AudioPlugin::new())
.add_plugin(DspPlugin::default())
.add_dsp_source(sine_wave, SourceType::Static { duration: 0.5 })
.add_dsp_source(triangle_wave, SourceType::Static { duration: 0.5 })
Expand All @@ -29,9 +29,9 @@ fn triangle_wave() -> impl AudioUnit32 {

fn interactive_audio(
input: Res<Input<KeyCode>>,
mut assets: ResMut<Assets<AudioSource<Stereo>>>,
mut assets: ResMut<Assets<AudioSource<[f32; 2]>>>,
dsp_manager: Res<DspManager>,
mut audio: ResMut<Audio<Stereo, AudioSource<Stereo>>>,
mut audio: ResMut<Audio<[f32; 2], AudioSource<[f32; 2]>>>,
) {
if input.just_pressed(KeyCode::S) {
audio.play_dsp(assets.as_mut(), dsp_manager.get_graph(sine_wave).unwrap());
Expand Down
8 changes: 4 additions & 4 deletions examples/oddio/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
use {
bevy::prelude::*,
bevy_fundsp::prelude::*,
bevy_oddio::{frames::Stereo, Audio, AudioPlugin},
bevy_oddio::{Audio, AudioPlugin},
};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_plugin(AudioPlugin::new())
.add_plugin(DspPlugin::default())
.add_dsp_source(white_noise, SourceType::Dynamic)
.add_startup_system_to_stage(StartupStage::PostStartup, play_noise)
.add_startup_system(play_noise.in_base_set(StartupSet::PostStartup))
.run();
}

Expand All @@ -23,7 +23,7 @@ fn white_noise() -> impl AudioUnit32 {
fn play_noise(
mut assets: ResMut<Assets<DspSource>>,
dsp_manager: Res<DspManager>,
mut audio: ResMut<Audio<Stereo, DspSource>>,
mut audio: ResMut<Audio<[f32; 2], DspSource>>,
) {
let source = dsp_manager
.get_graph(white_noise)
Expand Down
8 changes: 4 additions & 4 deletions src/backend/bevy_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use {
bevy::{
audio::{play_queued_audio_system, AudioSink},
prelude::{
App, Assets, Audio, AudioOutput, AudioSource, CoreStage, Decodable, Handle,
PlaybackSettings,
App, Assets, Audio, AudioOutput, AudioSource, CoreSet, Decodable, Handle,
IntoSystemConfig, PlaybackSettings,
},
},
};
Expand Down Expand Up @@ -49,8 +49,8 @@ impl Backend for BevyAudioBackend {

fn init_app(app: &mut App) {
app.init_resource::<Audio<DspSource>>()
.init_non_send_resource::<AudioOutput<DspSource>>()
.add_system_to_stage(CoreStage::PostUpdate, play_queued_audio_system::<DspSource>);
.init_resource::<AudioOutput<DspSource>>()
.add_system(play_queued_audio_system::<DspSource>.in_base_set(CoreSet::PostUpdate));
}

fn convert_to_audio_source(
Expand Down
46 changes: 20 additions & 26 deletions src/backend/oddio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use {
crate::dsp_source::{DspSource, Iter, IterMono, Source, SourceType},
bevy::prelude::{App, Assets, Handle},
bevy_oddio::{
frames::{FromFrame, Stereo},
oddio::{Frame, Frames, Sample, Signal},
oddio::{Frames, Sample, Signal},
output::AudioSink,
Audio, AudioApp, AudioSource, ToSignal,
},
Expand All @@ -18,10 +17,10 @@ use {
pub struct OddioBackend;

impl Backend for OddioBackend {
type StaticAudioSource = AudioSource<Stereo>;
type StaticAudioSource = AudioSource<[f32; 2]>;

fn init_app(app: &mut App) {
app.add_audio_source::<2, _, DspSource>();
app.add_audio_source::<_, DspSource>();
}

#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
Expand Down Expand Up @@ -49,7 +48,7 @@ impl DspSource {
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
pub(crate) fn into_exact_size_iter(
self,
) -> ExactSizeIter<impl Iterator<Item = Stereo> + ExactSizeIterator> {
) -> ExactSizeIter<impl Iterator<Item = [f32; 2]> + ExactSizeIterator> {
let audio_unit = Rc::new(RefCell::new(self.dsp_graph.generate_graph()));
let duration = match self.source_type {
SourceType::Static { duration } => duration,
Expand All @@ -62,8 +61,7 @@ impl DspSource {

let collection = (0..number_of_frames)
.map(|_| audio_unit.clone().borrow_mut().get_stereo())
.map(|frame| [frame.0, frame.1])
.map(Stereo::from);
.map(|frame| [frame.0, frame.1]);

ExactSizeIter {
sample_rate: self.sample_rate,
Expand All @@ -74,35 +72,32 @@ impl DspSource {

pub(crate) struct ExactSizeIter<I>
where
I: Iterator<Item = Stereo> + ExactSizeIterator,
I: Iterator<Item = [f32; 2]> + ExactSizeIterator,
{
sample_rate: f32,
collection: RefCell<I>,
}

impl<I> Source for ExactSizeIter<I>
where
I: Iterator<Item = Stereo> + ExactSizeIterator,
I: Iterator<Item = [f32; 2]> + ExactSizeIterator,
{
type Frame = Stereo;
type Frame = [f32; 2];

fn sample_rate(&self) -> f32 {
self.sample_rate
}

fn sample(&self) -> Self::Frame {
match self.collection.borrow_mut().next() {
Some(frame) => frame,
None => Stereo::ZERO,
}
self.collection.borrow_mut().next().unwrap_or_default()
}
}

impl<I> Iterator for ExactSizeIter<I>
where
I: Iterator<Item = Stereo> + ExactSizeIterator,
I: Iterator<Item = [f32; 2]> + ExactSizeIterator,
{
type Item = Stereo;
type Item = [f32; 2];

fn next(&mut self) -> Option<Self::Item> {
self.collection.borrow_mut().next()
Expand All @@ -111,22 +106,20 @@ where

impl<I> ExactSizeIterator for ExactSizeIter<I>
where
I: Iterator<Item = Stereo> + ExactSizeIterator,
I: Iterator<Item = [f32; 2]> + ExactSizeIterator,
{
fn len(&self) -> usize {
self.collection.borrow().len()
}
}

impl Signal for Iter {
type Frame = Stereo;
type Frame = [f32; 2];

fn sample(&self, interval: f32, out: &mut [Self::Frame]) {
self.advance(interval);
for out_frame in out {
let frame = Source::sample(self);
let stereo: Stereo = FromFrame::from_frame(frame);
*out_frame = stereo;
*out_frame = Source::sample(self);
}
}
}
Expand All @@ -136,17 +129,18 @@ impl Signal for IterMono {
type Frame = Sample;

fn sample(&self, interval: f32, out: &mut [Self::Frame]) {
self.advance(interval);
for out_frame in out {
let frame = Source::sample(self);
*out_frame = frame;
}
}
}

impl DspAudioExt for Audio<Stereo, AudioSource<Stereo>> {
type Assets = Assets<AudioSource<Stereo>>;
type Settings = <AudioSource<Stereo> as ToSignal>::Settings;
type Sink = Handle<AudioSink<AudioSource<Stereo>>>;
impl DspAudioExt for Audio<[f32; 2], AudioSource<[f32; 2]>> {
type Assets = Assets<AudioSource<[f32; 2]>>;
type Settings = <AudioSource<[f32; 2]> as ToSignal>::Settings;
type Sink = Handle<AudioSink<AudioSource<[f32; 2]>>>;

fn play_dsp_with_settings(
&mut self,
Expand All @@ -160,7 +154,7 @@ impl DspAudioExt for Audio<Stereo, AudioSource<Stereo>> {
}
}

impl DspAudioExt for Audio<Stereo, DspSource> {
impl DspAudioExt for Audio<[f32; 2], DspSource> {
type Assets = Assets<DspSource>;
type Settings = <DspSource as ToSignal>::Settings;
type Sink = Handle<AudioSink<DspSource>>;
Expand Down

0 comments on commit 00da900

Please sign in to comment.