-
Notifications
You must be signed in to change notification settings - Fork 2
/
ogg_file.rs
29 lines (23 loc) · 1.05 KB
/
ogg_file.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use audio_mixer::{AudioMixer, IntoChannels, IntoSampleRate, OggDecoder};
use std::io::Cursor;
// The ogg file used in this example is stereo and has a sample rate of 44100 Hz.
// The output device might have a different number of channels and sample rate.
//
// The 'Into' structs make these compatible with each other so that the audio
// plays at the right speed and on the expected channels.
//
// The rodio crate does this conversion for you but this crate is minimal so you
// must apply these 'Into' conversions yourself (if you want).
fn main() {
let cursor = Cursor::new(include_bytes!("./ogg_file.ogg"));
let decoder = OggDecoder::new(cursor).unwrap();
let mixer = AudioMixer::for_default_device().unwrap();
let in_channels = decoder.channels();
let out_channels = mixer.channels();
let in_rate = decoder.sample_rate();
let out_rate = mixer.sample_rate();
let source1 = IntoSampleRate::new(in_rate, out_rate, in_channels, decoder);
let source2 = IntoChannels::new(in_channels, out_channels, source1);
mixer.add(source2);
mixer.wait();
}