aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock64
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs28
3 files changed, 84 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5b45d78..a98976b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -231,6 +231,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
+name = "getrandom"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -566,6 +577,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
+name = "ppv-lite86"
+version = "0.2.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
+
+[[package]]
name = "proc-macro-crate"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -593,6 +610,46 @@ dependencies = [
]
[[package]]
+name = "rand"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+dependencies = [
+ "libc",
+ "rand_chacha",
+ "rand_core",
+ "rand_hc",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.6.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
+dependencies = [
+ "getrandom",
+]
+
+[[package]]
+name = "rand_hc"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
+dependencies = [
+ "rand_core",
+]
+
+[[package]]
name = "redox_syscall"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -706,6 +763,7 @@ dependencies = [
name = "synthfinity"
version = "0.1.0"
dependencies = [
+ "rand",
"rodio",
]
@@ -777,6 +835,12 @@ dependencies = [
]
[[package]]
+name = "wasi"
+version = "0.10.2+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+
+[[package]]
name = "wasm-bindgen"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 717971b..95cdc17 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,4 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+rand = "0.8.3"
rodio = "0.13.1"
diff --git a/src/main.rs b/src/main.rs
index 8a3395a..6b79749 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,18 +1,28 @@
use std::time::Duration;
-use rodio::{source::SineWave, OutputStream, Sink, Source};
+use rand::Rng;
+use rodio::{
+ source::{SineWave, Zero},
+ OutputStream, Sink, Source,
+};
fn main() {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
- // Add a dummy source of the sake of the example.
- let source = SineWave::new(440)
- .take_duration(Duration::from_secs_f32(0.25))
- .amplify(0.20);
- sink.append(source);
+ loop {
+ let mut rng = rand::thread_rng();
+ let freq = rng.gen_range((440 / 4)..(440 * 4));
+ let wave = SineWave::new(freq);
+ let zero: Zero<f32> = Zero::new(1, 48_000);
+ let length = rng.gen_range(0.1..0.3);
+ let source = wave
+ .take_crossfade_with(zero, Duration::from_secs_f32(length))
+ .amplify(0.20);
+ sink.append(source);
- // The sound plays in a separate thread. This call will block the current thread until the sink
- // has finished playing all its queued sounds.
- sink.sleep_until_end();
+ // The sound plays in a separate thread. This call will block the current thread until the sink
+ // has finished playing all its queued sounds.
+ sink.sleep_until_end();
+ }
}