Skip to content

Feature: ChannelRouter #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f497703
Adding a ChannelRouter source
iluvcapra Dec 7, 2024
cfdea36
Implementation continues
iluvcapra Dec 7, 2024
121105e
Simplified handling of frame endings
iluvcapra Dec 7, 2024
edc683b
More implementation, added mod functions
iluvcapra Dec 7, 2024
6037f67
Some documentation
iluvcapra Dec 7, 2024
b45b936
Flatted-out next a little
iluvcapra Dec 8, 2024
51b1f4b
rusfmt and typo
iluvcapra Dec 8, 2024
67b16a1
Typos and added methods, also documentation
iluvcapra Dec 8, 2024
f7d8220
clippy
iluvcapra Dec 8, 2024
1204fdf
Inline everything!
iluvcapra Dec 8, 2024
9d43421
Added extract_channels and extract_channel sources
iluvcapra Dec 8, 2024
77763ae
Gains implemented as an atomic array of f32s
iluvcapra Dec 9, 2024
3f16c25
Mutex-implemented, but need to clean this up
iluvcapra Dec 9, 2024
d39bbf2
Implemented updates with a mpsc::channel
iluvcapra Dec 10, 2024
45c4688
rustfmt
iluvcapra Dec 10, 2024
1662db2
Added more router conveniences
iluvcapra Dec 10, 2024
9b361b0
Added some comments and stubbed-out tests
iluvcapra Dec 10, 2024
5621477
Added some static tests
iluvcapra Dec 10, 2024
ca2ee9d
Added description to changelog
iluvcapra Dec 10, 2024
f521000
Test of the controller
iluvcapra Dec 10, 2024
9ae7119
rustfmt
iluvcapra Dec 10, 2024
0fe726c
Docstring for CI
iluvcapra Dec 10, 2024
08789de
For the pickier ubuntu-latest clippy
iluvcapra Dec 10, 2024
8cc8c6e
Removing the todo and addressing clippy
iluvcapra Dec 10, 2024
084fb78
Additional tests and impl for tests
iluvcapra Dec 10, 2024
c9cc895
Update channel_router.rs
iluvcapra Dec 10, 2024
a6f0873
Added a channel_routing example
iluvcapra Dec 10, 2024
cd51ea9
Merge branch 'feature-channelrouter' of https://github.com/iluvcapra/…
iluvcapra Dec 10, 2024
d0bdd45
Made channel_routing example interactive
iluvcapra Dec 10, 2024
276f23f
rustfmt
iluvcapra Dec 10, 2024
57b3fd3
Merge branch 'master' of https://github.com/RustAudio/rodio into feat…
iluvcapra Jan 1, 2025
5ed8da2
Test fixes
iluvcapra Jan 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ required-features = ["symphonia-isomp4", "symphonia-aac"]
[[example]]
name = "noise_generator"
required-features = ["noise"]

[[example]]
name = "channel_routing"
43 changes: 43 additions & 0 deletions examples/channel_routing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Channel router example

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
use rodio::source::{Function, SignalGenerator, Source};
use std::thread;
use std::time::Duration;

let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;

// let test_signal_duration = Duration::from_millis(1000);
let interval_duration = Duration::from_millis(100);
let sample_rate = cpal::SampleRate(48000);

let (mut controller, router) = SignalGenerator::new(sample_rate, 1000.0, Function::Triangle)
.amplify(0.1)
.channel_router(2, vec![vec![0.0f32, 0.0f32]]);

println!("Playing 1000Hz tone");

stream_handle.mixer().add(router);

for i in 0..1000 {
thread::sleep(interval_duration);
let n = i % 20;
match n {
0 => println!("Left speaker ramp up"),
1..10 => {
_ = controller.map(0, 0, n as f32 / 10.0);
_ = controller.map(0, 1, 0f32);
Copy link
Collaborator

@dvdsk dvdsk Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not very readable right? I can guess its channel from, channel too, gain? But we might be able to do better. I see a number of options, there might well be more:
1️⃣ make map take a struct like: controller.map(Mapping { from: 0, to: 1, gain: 0f32 })

2️⃣ make map a builder: controller.map().from(0).to(1).with_gain(0.f32).appy(). Here you could make the gain optional and do a default of 1.0

3️⃣ rename it so the argument names are in the name: controller.map_from_to_with_gain(0, 1, 0f32).

I think 2️⃣ is my favorite, though its a little more code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the builder too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of builder .from(0).to(1).with_gain(0.f32) should always go together at least it should be single call with 3 parameters.

I'd prefer a shorter name than controller.map_from_to_with_gain(0, 1, 0f32) since it is the only function supported by the router. maybe even controller.link(0, 1, 0f32) what it links can be figured out from the parameter names:

fn link(from_channel: ChannelNumber, to_channel: ChannelNumber, gain: f32)

}
10 => println!("Right speaker ramp up"),
11..20 => {
_ = controller.map(0, 0, 0.0f32);
_ = controller.map(0, 1, (n - 10) as f32 / 10.0);
}
_ => {}
}
}

Ok(())
}
Loading