Skip to content

Commit

Permalink
Big refactor for 0.2 (#6)
Browse files Browse the repository at this point in the history
# Objective

- This is a very big refactor that allows better ergonomics, better refactorability, and better support for streaming audio.
- Partially complete #1 for `bevy_audio`, 
	- bevyengine/bevy#5819 ~needs to be merged first.~ is now merged! Now waiting for bevy 0.9.
	- NiklasEi/bevy_kira_audio#63 is blocking for `kira`. 
- Partially complete #2 for `oddio`
	- bevyengine/bevy#5828 needs to be resolved first
	- NiklasEi/bevy_kira_audio#63 is blocking for `kira`
	- `oddio` isn't even implemented yet for this PR
    - By virtue of solving #2, then #3 will be unblocked
- Unblocks #4 by using `DspGraph`
- Fixes #5

## Solution

- [x] Add support for 
  - [x] `bevy_audio`, ~blocked by bevyengine/bevy#5819~ Now waiting for bevy 0.9.
  - [x] `bevy_kira_audio`, ~blocked by NiklasEi/bevy_kira_audio#72~ Now waiting for bevy 0.9.
  - [x] `bevy_oddio`
- [ ] Add support for streaming audio in
  - [x] `bevy_audio`, ~blocked by bevyengine/bevy#5819~
  - [ ] `bevy_kira_audio`, blocked by NiklasEi/bevy_kira_audio#63
  - [x] `bevy_oddio`
- [ ] Allow setting of parameters in
  - [ ] `bevy_audio`, blocked by bevyengine/bevy#5828
  - [ ] `bevy_kira_audio`, blocked by NiklasEi/bevy_kira_audio#63
  - [x] `bevy_oddio`

## Note for Users of this Branch

If you are a user of `bevy_fundsp`, please try to test this PR! This currently only works with bevy_audio (EDIT: and bevy_oddio!), because this relies on a branch I made on bevy.

---

## Changelog

Reworked the majority of the code.

## Added

- A way to play streaming DSP sources. See `SourceType::Dynamic`.
- You can play DSP sources using `Audio::play_dsp`.
- Two iterators on streaming audio sources: `Iter` and `IterMono`.

### Changed

- Adding the DSP plugin.
  - You must now call `DspPlugin::default()`.
- The method on adding DSP sources.
  - No more initializing using `DspAssets`!
  - Just add your DSP function using `app.add_dsp_source`
- Playing DSP sources require `Audio` to be mutable. (Use `ResMut`)
- A lot of internals are shuffled around.

### Removed

- `DspAssets`
- `FnDspGraph`
- `StreamingDspSource`
  • Loading branch information
harudagondi committed Nov 14, 2022
1 parent c123076 commit 7e1a63f
Show file tree
Hide file tree
Showing 23 changed files with 1,276 additions and 645 deletions.
136 changes: 46 additions & 90 deletions .github/workflows/rust.yml
@@ -1,107 +1,44 @@
on: [push, pull_request]
name: CI

name: Continuous integration
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
check_bevy_audio:
name: check bevy_audio
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- uses: actions-rs/cargo@v1
with:
command: check

test_bevy_audio:
name: test bevy_audio
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- uses: actions-rs/cargo@v1
with:
command: test
env:
CARGO_TERM_COLOR: always

check_kira:
name: check kira
runs-on: ubuntu-latest
jobs:
test:
strategy:
fail-fast: false
matrix:
feature: [bevy_audio, kira, oddio]
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
command: check
args: --no-default-features --features kira

test_kira:
name: test kira
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-build-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
if: runner.os == 'linux'
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features kira

# check_oddio:
# name: check oddio
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - name: Install alsa and udev
# run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
# - uses: actions-rs/cargo@v1
# with:
# command: check
# args: --no-default-features --features oddio

# test_oddio:
# name: test oddio
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - name: Install alsa and udev
# run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
# - uses: actions-rs/cargo@v1
# with:
# command: test
# args: --no-default-features --features oddio
args: --no-default-features --features ${{ matrix.feature }}

fmt:
name: fmt
Expand Down Expand Up @@ -138,3 +75,22 @@ jobs:
with:
command: clippy
args: -- -D warnings

miri:
name: miri
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
feature: [bevy_audio, kira, oddio]
steps:
- uses: actions/checkout@v3
- name: Install Miri
run: |
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Test with Miri
run: cargo miri test --no-default-features --features ${{ matrix.feature }}
41 changes: 41 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,41 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.2.0] - 14-11-2022

Reworked the majority of the internals.

## Added

- A way to play streaming DSP sources. See `SourceType::Dynamic`.
- You can play DSP sources using `Audio::play_dsp`.
- Two iterators on streaming audio sources: `Iter` and `IterMono`.

### Changed

- Adding the DSP plugin.
- You must now call `DspPlugin::default()`.
- The method on adding DSP sources.
- No more initializing using `DspAssets`!
- Just add your DSP function using `app.add_dsp_source`
- Playing DSP sources require `Audio` to be mutable. (Use `ResMut`)
- A lot of internals are shuffled around.

### Removed

- `DspAssets`. Initialize DSP graphs using `App::add_dsp_source` instead.
- `FnDspGraph`. This is now reworked to the trait `DspGraph` and can work with any type now.
- `StreamingDspSource`. This is now reworked to `Iter` (`bevy_kira_audio` and `bevy_oddio`) and `IterMono` (`bevy_audio`).

## [0.1.0] - 01-08-22

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

[Unreleased]: https://github.com/harudagondi/bevy_fundsp/compare/v0.2.0...HEAD
[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
58 changes: 42 additions & 16 deletions Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "bevy_fundsp"
authors = ["Gio Genre De Asis"]
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "A Bevy plugin that integrates FunDSP into Bevy."
homepage = "https://github.com/harudagondi/bevy_fundsp"
Expand All @@ -12,36 +12,52 @@ categories = ["game-development", "multimedia::audio"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["bevy_audio"]
kira = ["dep:kira", "bevy_kira_audio"]
bevy_audio = ["bevy/bevy_audio", "bevy/wav", "rodio"]
oddio = ["bevy_oddio"]

[dependencies]
fundsp = "0.9"
kira = { version = "0.6", default-features = false, features = ["wav"], optional = true }
# bevy_oddio = { git = "https://github.com/harudagondi/bevy_oddio.git", optional = true }
cpal = "0.14"
once_cell = "1.13"
rodio = { version = "0.16", default-features = false, features = ["wav"], optional = true }
kira = { version = "0.7", default-features = false, features = ["wav"], optional = true }
ringbuf = "0.3"
parking_lot = "0.12"

atomic = "0.5"
[dependencies.uuid]
version = "1.1"
features = [
"v5"
]

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

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

[features]
default = ["bevy_audio"]
kira = ["dep:kira", "bevy_kira_audio"]
bevy_audio = ["bevy/bevy_audio", "bevy/wav"]
# oddio = ["bevy_oddio"]
[dependencies.bevy_oddio]
# git = "https://github.com/harudagondi/bevy_oddio"
# branch = "bevy_main"
version = "0.3"
default-features = false
optional = true
features = ["wav"]

[dev-dependencies.bevy]
# git = "https://github.com/bevyengine/bevy"
version = "0.8"
version = "0.9"
default-features = false
features = [
"render",
Expand Down Expand Up @@ -76,7 +92,17 @@ name = "kira_interactive"
path = "examples/kira/interactive.rs"
required-features = ["kira"]

# [[example]]
# name = "oddio_noise"
# path = "examples/oddio/noise.rs"
# required-features = ["oddio"]
[[example]]
name = "oddio_noise"
path = "examples/oddio/noise.rs"
required-features = ["oddio"]

[[example]]
name = "oddio_interactive"
path = "examples/oddio/interactive.rs"
required-features = ["oddio"]

[[example]]
name = "oddio_controlled"
path = "examples/oddio/controlled.rs"
required-features = ["oddio"]
36 changes: 18 additions & 18 deletions README.md
Expand Up @@ -20,42 +20,42 @@ or multiplying your DSP graph with a low constant (lower than 1.0).
```rust no_run
#![allow(clippy::precedence)]

use bevy_fundsp::prelude::*;
use bevy::prelude::*;
use bevy_fundsp::prelude::*;

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

fn white_noise() -> impl AudioUnit32 {
white() >> split::<U2>() * 0.2
}

fn init_dsp(mut dsp_manager: ResMut<DspManager>) {
dsp_manager.add_graph(white_noise, 30.0); // length is in seconds
}

fn play_noise(dsp_assets: Res<DspAssets>, audio: Res<Audio>) {
let white_noise = dsp_assets.graph(&white_noise);
audio.play(white_noise.clone());
fn play_noise(
mut assets: ResMut<Assets<DspSource>>,
dsp_manager: Res<DspManager>,
mut audio: ResMut<Audio<DspSource>>,
) {
let source = dsp_manager
.get_graph(white_noise)
.unwrap_or_else(|| panic!("DSP source not found!"));
audio.play_dsp(assets.as_mut(), source);
}

```

## Compatibility

| `bevy_fundsp` | `bevy` | `bevy_kira_audio` | `fundsp` |
| ------------- | ------ | -------------------------- | -------- |
| main | main | main, branch = `bevy_main` | main |
| 0.1.0 | 0.8 | 0.11 | 0.6 |
| `bevy_fundsp` | `bevy` | `bevy_kira_audio` | `bevy_oddio` | `fundsp` |
| ------------- | ------ | ----------------- | ------------ | -------- |
| bevy_main | main | bevy_main | bevy_main | main |
| 0.2.0 | 0.9 | 0.13 | 0.3 | 0.8 |
| 0.1.0 | 0.8 | 0.11 | | 0.6 |

## License

Expand Down

0 comments on commit 7e1a63f

Please sign in to comment.