Skip to content
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

Feature channelrouter (sparse matrix, other version of #656) #671

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 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
a3e262a
Alternative channel router mixing (sparse matrix)
PetrGlad Jan 5, 2025
6fa04b1
Cleanup
PetrGlad Jan 5, 2025
be578a0
Sparse-matrix channel mixer (channel router)
PetrGlad Jan 7, 2025
4dd8fba
Cleanup, small optimization
PetrGlad Jan 7, 2025
99a9920
Cleanup
PetrGlad Jan 7, 2025
e117aac
Cleanup
PetrGlad Jan 7, 2025
77f2afb
Cleanup
PetrGlad Jan 7, 2025
cc86637
Reimplement Debug for ChannelMixerSource
PetrGlad Feb 2, 2025
aa37ef4
Make clippy happy
PetrGlad Feb 2, 2025
efb13ca
Channel mixer cleanup
PetrGlad Feb 2, 2025
fee9e82
Merge remote-tracking branch 'rust-audio/master' into feature-channel…
PetrGlad Feb 2, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Adds a function to write a `Source` to a `wav` file, see `output_to_wav`.
- Output audio stream buffer size can now be adjusted.
- A `ChannelRouterSource` that can mix, re-order and extract channels from a
multi-channel source.
- Several `Source` trait helper functions including `extract_channel`,
`extract_channels`, `mono`, `mono_to_stereo`, and `downmix_51`.
- A `ChannelRouterController` type to modify the `ChannelRouterSource`
across thread boundaries.
- Sources for directly generating square waves, triangle waves, square waves, and
sawtooths have been added.
- An interface for defining `SignalGenerator` patterns with an `fn`, see
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ required-features = ["symphonia-isomp4", "symphonia-aac"]
name = "noise_generator"
required-features = ["noise"]

[[example]]
name = "channel_routing"

[[example]]
name = "into_file"
required-features = ["wav", "mp3"]

45 changes: 45 additions & 0 deletions examples/channel_routing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! Channel router example

use std::io::Read;
use std::{error::Error, io};

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

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

let sample_rate: u32 = 48000;

let (controller, router) = SignalGenerator::new(sample_rate, 440.0, Function::Triangle)
.amplify(0.1)
.channel_router(2, &vec![]);

println!("Control left and right levels separately:");
println!("q: left+\na: left-\nw: right+\ns: right-\nx: quit");

stream_handle.mixer().add(router);

let (mut left_level, mut right_level) = (0.5f32, 0.5f32);
controller.set_map(&vec![(0, 0, left_level), (0, 1, right_level)])?;
println!("Left: {left_level:.04}, Right: {right_level:.04}");

let bytes = io::stdin().bytes();
for chr in bytes {
match chr.unwrap() {
b'q' => left_level += 0.1,
b'a' => left_level -= 0.1,
b'w' => right_level += 0.1,
b's' => right_level -= 0.1,
b'x' => break,
b'\n' => {
left_level = left_level.clamp(0.0, 1.0);
right_level = right_level.clamp(0.0, 1.0);
controller.set_map(&vec![(0, 0, left_level), (0, 1, right_level)])?;
println!("Left: {left_level:.04}, Right: {right_level:.04}");
}
_ => continue,
}
}

Ok(())
}
4 changes: 2 additions & 2 deletions src/mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::time::Duration;

/// Builds a new mixer.
/// Builds a new mixer that sums corresponding channels from incoming streams.
///
/// You can choose the characteristics of the output thanks to this constructor. All the sounds
/// added to the mixer will be converted to these values.
Expand Down Expand Up @@ -116,7 +116,7 @@ where
// let mut encounterd_err = None;
//
// for source in &mut self.current_sources {
// let pos = /* source.playback_pos() */ todo!();
// let pos = /* source.playback_pos() */
// if let Err(e) = source.try_seek(pos) {
// encounterd_err = Some(e);
// break;
Expand Down
Loading
Loading