Implemented chirp generator

This commit is contained in:
Jamie Hardt 2024-09-14 09:32:51 -07:00
parent 0c2c1941d6
commit e060bdd35c
3 changed files with 25 additions and 5 deletions

View file

@ -9,7 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Support for *ALAC/AIFF*
- New sources:
- 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

View file

@ -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,

View file

@ -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<Self::Item> {
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() )
}
}