2017-07-01 14:57:59 +00:00
|
|
|
use std::io::BufReader;
|
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
2020-02-25 10:09:17 +00:00
|
|
|
let (_stream, handle) = rodio::OutputStream::try_default().unwrap();
|
|
|
|
let sink = rodio::SpatialSink::try_new(
|
|
|
|
&handle,
|
2018-04-19 08:03:48 +00:00
|
|
|
[-10.0, 0.0, 0.0],
|
|
|
|
[1.0, 0.0, 0.0],
|
|
|
|
[-1.0, 0.0, 0.0],
|
2020-02-25 10:13:08 +00:00
|
|
|
)
|
|
|
|
.unwrap();
|
2017-07-01 14:57:59 +00:00
|
|
|
|
|
|
|
let file = std::fs::File::open("examples/music.ogg").unwrap();
|
|
|
|
let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
|
|
|
|
sink.append(source);
|
2017-07-03 08:09:10 +00:00
|
|
|
|
2017-07-01 14:57:59 +00:00
|
|
|
// A sound emitter playing the music starting at the left gradually moves to the right
|
2017-07-03 08:09:10 +00:00
|
|
|
// eventually passing through the listener, then it continues on to the right for a distance
|
|
|
|
// until it stops and begins traveling to the left, it will eventually pass through the
|
|
|
|
// listener again.
|
2017-07-01 14:57:59 +00:00
|
|
|
// This is repeated 5 times.
|
2020-01-31 00:15:41 +00:00
|
|
|
for _ in 0..5 {
|
|
|
|
for i in 1..1001 {
|
2017-07-01 14:57:59 +00:00
|
|
|
thread::sleep(Duration::from_millis(5));
|
|
|
|
sink.set_emitter_position([(i - 500) as f32 / 50.0, 0.0, 0.0]);
|
|
|
|
}
|
2020-01-31 00:15:41 +00:00
|
|
|
for i in 1..1001 {
|
2017-07-01 14:57:59 +00:00
|
|
|
thread::sleep(Duration::from_millis(5));
|
|
|
|
sink.set_emitter_position([-(i - 500) as f32 / 50.0, 0.0, 0.0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sink.sleep_until_end();
|
|
|
|
}
|