<commit_before>//! Writes wav files for every Oscillator waveform for analysis

extern crate oxcable;

#[cfg(not(test))]
fn main() {
    use std::vec::Vec;
    use oxcable::types::Device;
    use oxcable::io::wav::WavWriter;
    use oxcable::oscillator;
    use oxcable::oscillator::Oscillator;

    // Initialize objects
    println!("Initializing signal chain...");
    let freq = 8000.0;
    let mut oscs = Vec::<oscillator::Oscillator>::new();
    let mut wavs = Vec::<WavWriter>::new();
    oscs.push(Oscillator::new(oscillator::Sine, freq));
    wavs.push(WavWriter::new("wav/test_sine.wav", 1));
    oscs.push(Oscillator::new(oscillator::Saw(oscillator::Aliased), freq));
    wavs.push(WavWriter::new("wav/test_saw_naive.wav", 1));
    oscs.push(Oscillator::new(oscillator::Saw(oscillator::PolyBlep), freq));
    wavs.push(WavWriter::new("wav/test_saw_blep.wav", 1));
    oscs.push(Oscillator::new(oscillator::Square(oscillator::Aliased), freq));
    wavs.push(WavWriter::new("wav/test_square_naive.wav", 1));
    oscs.push(Oscillator::new(oscillator::Square(oscillator::PolyBlep), freq));
    wavs.push(WavWriter::new("wav/test_square_blep.wav", 1));
    oscs.push(Oscillator::new(oscillator::Tri(oscillator::Aliased), freq));
    wavs.push(WavWriter::new("wav/test_tri_naive.wav", 1));
    oscs.push(Oscillator::new(oscillator::Tri(oscillator::PolyBlep), freq));
    wavs.push(WavWriter::new("wav/test_tri_blep.wav", 1));
    oscs.push(Oscillator::new(oscillator::WhiteNoise, freq));
    wavs.push(WavWriter::new("wav/test_white_noise.wav", 1));
    oscs.push(Oscillator::new(oscillator::PulseTrain, freq));
    wavs.push(WavWriter::new("wav/test_pulse_train.wav", 1));

    // Link oscillators to wav outs
    println!("Writing oscillators to wav files...");
    for i in (0 .. oscs.len()) {
        wavs[i].inputs.set_channel(0, oscs[i].output.get_channel());
    }

    // Write files
    for t in (0u64 .. 44100) {
        for i in (0 .. oscs.len()) {
            oscs[i].tick(t);
            wavs[i].tick(t);
        }
    }
    println!("Done");
}
<commit_msg>Upgrade test oscillators to use chains<commit_after>//! Writes wav files for every Oscillator waveform for analysis

extern crate oxcable;

#[cfg(not(test))]
fn main() {
    use oxcable::chain::DeviceChain;
    use oxcable::io::wav::WavWriter;
    use oxcable::oscillator::{self, Oscillator};

    // Initialize objects
    println!("Initializing signal chain...");
    let freq = 8000.0;
    let mut chains: Vec<DeviceChain> = Vec::new();
    chains.push(DeviceChain::from(Oscillator::new(oscillator::Sine, freq))
        .into(WavWriter::new("wav/test_sine.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::Saw(oscillator::Aliased), freq))
        .into(WavWriter::new("wav/test_saw_naive.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::Saw(oscillator::PolyBlep), freq))
        .into(WavWriter::new("wav/test_saw_blep.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::Square(oscillator::Aliased), freq))
        .into(WavWriter::new("wav/test_square_naive.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::Square(oscillator::PolyBlep), freq))
        .into(WavWriter::new("wav/test_square_blep.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::Tri(oscillator::Aliased), freq))
        .into(WavWriter::new("wav/test_tri_naive.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::Tri(oscillator::PolyBlep), freq))
        .into(WavWriter::new("wav/test_tri_blep.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::WhiteNoise, freq))
        .into(WavWriter::new("wav/test_white_noise.wav", 1)));
    chains.push(DeviceChain::from(
            Oscillator::new(oscillator::PulseTrain, freq))
        .into(WavWriter::new("wav/test_pulse_train.wav", 1)));

    // Write files
    println!("Writing oscillators to wav files...");
    for _ in (0u64 .. 44100) {
        for chain in chains.iter_mut() {
            chain.tick();
        }
    }
    println!("Done");
}

{'fraction_non_alphanumeric': 0.17822253990945913, 'fraction_numerical': 0.011198475101262807, 'mean_word_length': 3.991676575505351, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5295919', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1572, 'n_words': 212}