### Write Sine Wave to WAV File in Rust Source: https://github.com/ruuda/hound/blob/release/readme.md Demonstrates how to create a WAV file containing a 440 Hz sine wave. It configures the audio specification (sample rate, channels, bits per sample) and writes samples to the file. ```rust use std::f32::consts::PI; use std::i16; use hound; let spec = hound::WavSpec { channels: 1, sample_rate: 44100, bits_per_sample: 16, sample_format: hound::SampleFormat::Int, }; let mut writer = hound::WavWriter::create("sine.wav", spec).unwrap(); for t in (0 .. 44100).map(|x| x as f32 / 44100.0) { let sample = (t * 440.0 * 2.0 * PI).sin(); let amplitude = i16::MAX as f32; writer.write_sample((sample * amplitude) as i16).unwrap(); } // The file is finalized implicitly when the writer is dropped, call // writer.finalize() to observe errors. ``` -------------------------------- ### Hound WAV File Format Support Source: https://github.com/ruuda/hound/blob/release/readme.md Details the supported formats, encodings, and bits per sample for reading and writing WAVE audio files using the Hound library. ```APIDOC Hound WAV Format Support: Features: | | Read | Write | |-----------------|---------------------------------------------------------|-----------------------------------------| | Format | `PCMWAVEFORMAT`, `WAVEFORMATEX`, `WAVEFORMATEXTENSIBLE` | `PCMWAVEFORMAT`, `WAVEFORMATEXTENSIBLE` | | Encoding | Integer PCM, IEEE Float | Integer PCM, IEEE Float | | Bits per sample | 8, 16, 24, 32 (integer), 32 (float) | 8, 16, 24, 32 (integer), 32 (float) | ``` -------------------------------- ### Calculate RMS of WAV File in Rust Source: https://github.com/ruuda/hound/blob/release/readme.md Shows how to read a WAV file and compute its Root Mean Square (RMS) value. It iterates through samples, calculates the sum of squares, and then derives the RMS. ```rust use hound; let mut reader = hound::WavReader::open("testsamples/pop.wav").unwrap(); let sqr_sum = reader.samples::() .fold(0.0, |sqr_sum, s| { let sample = s.unwrap() as f64; sqr_sum + sample * sample }); println!("RMS is {}", (sqr_sum / reader.len() as f64).sqrt()); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.