generate_sine_wave

Function generate_sine_wave 

Source
pub fn generate_sine_wave(
    frequency: f32,
    sample_rate: f32,
    duration: f32,
) -> Vec<f32>
Expand description

Generates a sine wave signal based on the specified frequency, sample rate, and duration.

This function creates a vector of samples representing a sine wave. The sine wave is generated using the formula: sin(2 * π * frequency * time), where time is calculated based on the sample rate and the sample index.

§Parameters

  • frequency: The frequency of the sine wave in Hertz (Hz).
  • sample_rate: The number of samples per second (samples/second).
  • duration: The duration of the sine wave in seconds.

§Returns

A vector of f32 values representing the samples of the generated sine wave. The length of the output vector will be equal to the number of samples calculated as sample_rate * duration.

§Example

let frequency = 440.0; // A4 note
let sample_rate = 44100.0; // CD quality
let duration = 1.0; // 1 second
let sine_wave = generate_sine_wave(frequency, sample_rate, duration);