diff --git a/CHANGELOG.md b/CHANGELOG.md index 63faa80..03cf51f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Support for *ALAC/AIFF* -- New sources: +- Support for *ALAC/AIFF* +- New test signal generator sources: + - `TestSignal` source generates a sine, triangle, square wave or sawtooth + of a given frequency and sample rate. + - `Chirp` source generates a sine wave with linearly period over a given + frequency range and duration. + - `white` and `pink` generate white or pink noise, respectively. These + sources depend on the `rand` crate and are guarded with the "noise" + feature. + - Documentation for the "noise" feature has been added to `lib.rs`. +- New Fade and Crossfade sources: - `fade_out` fades an input out using a linear gain fade. - `linear_gain_ramp` applies a linear gain change to a sound over a given duration. `fade_out` is implemented as a `linear_gain_ramp` and diff --git a/src/lib.rs b/src/lib.rs index 6f6c505..c47eafa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,6 +112,15 @@ //! the number of sinks that can be created (except for the fact that creating too many will slow //! down your program). //! +//! +//! ## Features +//! +//! Rodio provides several optional features that are guarded with feature gates. +//! +//! ### Feature "Noise" +//! +//! The "noise" feature adds support for white and pink noise sources. This feature requires the +//! "rand" crate. #![cfg_attr(test, deny(missing_docs))] pub use cpal::{ self, traits::DeviceTrait, Device, Devices, DevicesError, InputDevices, OutputDevices, diff --git a/src/source/chirp.rs b/src/source/chirp.rs index 8fabc29..1971c70 100644 --- a/src/source/chirp.rs +++ b/src/source/chirp.rs @@ -1,6 +1,6 @@ //! Chirp/sweep source. -use std::time::Duration; +use std::{f32::consts::TAU, time::Duration}; use crate::Source; @@ -48,9 +48,11 @@ impl Iterator for Chirp { fn next(&mut self) -> Option { let i = self.elapsed_samples; + let ratio = self.elapsed_samples as f32 / self.total_samples as f32; self.elapsed_samples += 1; - - todo!() + let freq = self.start_frequency * (1.0 - ratio) + self.end_frequency * ratio; + let t = (i as f32 / self.sample_rate() as f32) * TAU * freq; + Some( t.sin() ) } }