audio_overlay

Crates.ioaudio_overlay
lib.rsaudio_overlay
version0.1.5
sourcesrc
created_at2023-03-17 20:33:52.423795
updated_at2023-05-30 14:47:06.018309
descriptionOverlay one audio sample array onto another
homepagehttps://github.com/subalterngames/audio_overlay
repositoryhttps://github.com/subalterngames/audio_overlay
max_upload_size
id813085
size12,850
Esther Alter (subalterngames)

documentation

README

Audio Overlay

Overlay audio samples from one array onto another. You can optionally expand the destination array.

The overlay function can be used for i8, i16, i32, i64, f32, and f64.

Changelog

Read this.

Example

Example implementation here. This example relies on two crates that aren't dependencies of audio_overlay: hound (to open .wav files and convert them into vecs) and rodio (to play the audio sample buffer).

use rodio::{OutputStream, Sink};
use rodio::buffer::SamplesBuffer;
use hound;
use audio_overlay::overlay;

fn main()
{
    // Set the framerate.
    let framerate: u32 = 44100;

    // Load the audio clips.
    // Source: https://archive.org/download/NasaApollo11OnboardRecordings/11_highlight_2.ogg
    let src: Vec<i16> = hound::WavReader::open("src.wav").unwrap().samples::<i16>().map(|s| s.unwrap()).collect::<Vec<i16>>();
    // Source: https://archive.org/download/airship1904/airship1904.ogg
    let mut dst: Vec<i16> = hound::WavReader::open("dst.wav").unwrap().samples::<i16>().map(|s| s.unwrap()).collect::<Vec<i16>>();

    // Overlay the audio clips. The src clip will start 1.0 seconds after dst begins.
    overlay(src.as_slice(), &mut dst, 1.0, framerate, true);

    // Play the audio clips. Source: https://docs.rs/rodio/latest/rodio
    let (_stream, stream_handle) = OutputStream::try_default().unwrap();
    let source = SamplesBuffer::new(1, framerate, dst);
    let sink = Sink::try_new(&stream_handle).unwrap();
    sink.append(source);
    sink.sleep_until_end();
}
Commit count: 24

cargo fmt