mirror of
https://github.com/RustAudio/rodio
synced 2024-12-12 13:12:30 +00:00
Implemented chirp generator
This commit is contained in:
parent
0c2c1941d6
commit
e060bdd35c
3 changed files with 25 additions and 5 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() )
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue