<commit_before>extern crate portaudio_rs as portaudio;

use portaudio::{stream, hostapi, device};

fn main()
{
    println!("version: {} \"{}\"", portaudio::version(), portaudio::version_text());
    println!("init: {:?}", portaudio::initialize());

    print_info();
    doit();

    println!("term: {:?}", portaudio::terminate());
}

fn print_info()
{
    if let Ok(api_count) = hostapi::get_count()
    {
        for i in 0 .. api_count
        {
            let name = match hostapi::get_info(i)
            {
                None => "???".to_string(),
                Some(ha) => ha.name,
            };
            println!("api {}: {}", i, name);
        }
    }

    if let Ok(device_count) = device::get_count()
    {
        for i in 0 .. device_count
        {
            let name = match device::get_info(i)
            {
                None => "???".to_string(),
                Some(d) => d.name,
            };
            println!("dev {}: {}", i, name);
        }
    }
}

fn doit()
{
    callback_demo();
    write_demo();
    mixed_demo();
}

fn callback_demo()
{
    let callback = Box::new(|_input: &[f32], output: &mut [f32], _time: stream::StreamTimeInfo, _flags: stream::StreamCallbackFlags| -> stream::StreamCallbackResult
    {
        static mut LP: f32 = 0.0;
        static mut RP: f32 = 0.0;

        let mut left_phase = unsafe { LP };
        let mut right_phase = unsafe { RP };

        for i in 0 .. output.len() / 2
        {
            output[i*2] = left_phase;
            output[i*2+1] = right_phase;

            left_phase += 0.01;
            if left_phase >= 1.0 { left_phase -= 2.0; }

            right_phase += 0.03;
            if right_phase >= 1.0 { right_phase -= 2.0; }
        }

        unsafe { LP = left_phase; }
        unsafe { RP = right_phase; }

        stream::StreamCallbackResult::Continue
    });

    let finished_callback = Box::new(|| println!("Finshed callback called"));
    let mut stream = match stream::Stream::open_default(0, 2, 44100f64, stream::FRAMES_PER_BUFFER_UNSPECIFIED, Some(callback))
    {<commit_msg>removed unnecessary unsafes from examples/test.rs<commit_after>extern crate portaudio_rs as portaudio;

use portaudio::{stream, hostapi, device};

fn main()
{
    println!("version: {} \"{}\"", portaudio::version(), portaudio::version_text());
    println!("init: {:?}", portaudio::initialize());

    print_info();
    doit();

    println!("term: {:?}", portaudio::terminate());
}

fn print_info()
{
    if let Ok(api_count) = hostapi::get_count()
    {
        for i in 0 .. api_count
        {
            let name = match hostapi::get_info(i)
            {
                None => "???".to_string(),
                Some(ha) => ha.name,
            };
            println!("api {}: {}", i, name);
        }
    }

    if let Ok(device_count) = device::get_count()
    {
        for i in 0 .. device_count
        {
            let name = match device::get_info(i)
            {
                None => "???".to_string(),
                Some(d) => d.name,
            };
            println!("dev {}: {}", i, name);
        }
    }
}

fn doit()
{
    callback_demo();
    write_demo();
    mixed_demo();
}

fn callback_demo()
{
    let mut lp = 0.0f32;
    let mut rp = 0.0f32;
    let callback = Box::new(move |_input: &[f32], output: &mut [f32], _time: stream::StreamTimeInfo, _flags: stream::StreamCallbackFlags| -> stream::StreamCallbackResult
    {
        let mut left_phase = lp;
        let mut right_phase = rp;

        for i in 0 .. output.len() / 2
        {
            output[i*2] = left_phase;
            output[i*2+1] = right_phase;

            left_phase += 0.01;
            if left_phase >= 1.0 { left_phase -= 2.0; }

            right_phase += 0.03;
            if right_phase >= 1.0 { right_phase -= 2.0; }
        }

        lp = left_phase;
        rp = right_phase;

        stream::StreamCallbackResult::Continue
    });

    let finished_callback = Box::new(|| println!("Finshed callback called"));
    let mut stream = match stream::Stream::open_default(0, 2, 44100f64, stream::FRAMES_PER_BUFFER_UNSPECIFIED, Some(callback))
    {
{'fraction_non_alphanumeric': 0.15847784200385356, 'fraction_numerical': 0.02023121387283237, 'mean_word_length': 1.9985559566787003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1598642', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1319, 'n_words': 293}