Skip to content

Commit 71d9a6d

Browse files
author
David Kleingeld
authored
Merge pull request #632 from UnknownSuperficialNight/feature/automatic-gain-control-example
Add AGC example
2 parents b394e55 + 34b5585 commit 71d9a6d

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ required-features = ["symphonia-isomp4", "symphonia-aac"]
6969
[[example]]
7070
name = "noise_generator"
7171
required-features = ["noise"]
72+
73+
[[example]]
74+
name = "automatic_gain_control"
75+
required-features = ["atomic_float"]

examples/automatic_gain_control.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use rodio::source::Source;
2+
use rodio::Decoder;
3+
use std::fs::File;
4+
use std::io::BufReader;
5+
6+
fn main() {
7+
let (_stream, handle) = rodio::OutputStream::try_default().unwrap();
8+
let sink = rodio::Sink::try_new(&handle).unwrap();
9+
10+
let file = BufReader::new(File::open("assets/music.flac").unwrap());
11+
12+
// Decode the sound file into a source
13+
let source = Decoder::new(file).unwrap();
14+
15+
// Apply automatic gain control to the source
16+
let agc_source = source.automatic_gain_control(1.0, 4.0, 0.005, 5.0);
17+
18+
// Get a handle to control the AGC's enabled state (only when using experimental feature)
19+
let agc_control = agc_source.get_agc_control();
20+
21+
// Disable AGC by default when using experimental feature
22+
agc_control.store(true, std::sync::atomic::Ordering::Relaxed);
23+
24+
// Add the AGC-processed source to the sink for playback
25+
sink.append(agc_source);
26+
27+
// Keep the program running until playback is complete
28+
sink.sleep_until_end();
29+
}

0 commit comments

Comments
 (0)