pub fn standalone_start(
    mut app: impl StandaloneProcessor,
    handle: Option<&Handle>,
) -> StandaloneHandles {
    let _ = wisual_logger::try_init_from_env();

    let (midi_host, mut midi_context) = initialize_midi_host(&mut app, handle);

    // Audio set-up
    let host = cpal::default_host();
    log::info!("Using host: {}", host.id().name());
    let buffer_size = 512;
    let sample_rate = 44100;
    let accepts_input = app.options().accepts_input;
    let input_tuple = if accepts_input {
        Some(configure_input_device(&host, buffer_size, sample_rate))
    } else {
        None
    };
    let (output_device, output_config) = configure_output_device(host, buffer_size, sample_rate);

    let settings = AudioProcessorSettings::new(
        output_config.sample_rate.0 as f32,
        input_tuple
            .as_ref()
            .map(|(_, input_config)| input_config.channels.into())
            .unwrap_or(0),
        output_config.channels.into(),
        buffer_size,
    );
    app.processor().prepare(settings);

    let buffer = ringbuf::RingBuffer::new((buffer_size * 10) as usize);
    let (mut producer, mut consumer) = buffer.split();
    let input_stream = input_tuple.map(|(input_device, input_config)| {
        input_device
            .build_input_stream(
                &input_config,
                move |data: &[f32], _input_info: &cpal::InputCallbackInfo| {
                    input_stream_callback(&mut producer, data)
                },
                |err| {
                    log::error!("Input error: {:?}", err);
                },
            )
            .unwrap()
    });

    // Output callback section
    let num_channels = output_config.channels.into();
    let output_stream = output_device
        .build_output_stream(
            &output_config,
            move |data: &mut [f32], _output_info: &cpal::OutputCallbackInfo| {
                output_stream_with_context(
                    midi_context.as_mut(),
                    &mut app,
                    num_channels,
                    &mut consumer,
                    data,
                );
            },
            |err| {
                log::error!("Playback error: {:?}", err);
            },
        )
        .unwrap();

    output_stream.play().unwrap();
    if let Some(input_stream) = &input_stream {
        input_stream.play().unwrap();
    }
    log::info!("Audio streams started");

    StandaloneHandles {
        input_stream,
        output_stream,
        midi_host,
    }
}
/// Start a processor using CPAL.
Start a processor using CPAL.
Start a processor using CPAL .
pub fn standalone_start(
    mut app: impl StandaloneProcessor,
    handle: Option<&Handle>,
) -> StandaloneHandles {
    let _ = wisual_logger::try_init_from_env();
    let (midi_host, mut midi_context) = initialize_midi_host(&mut app, handle);
    // Audio set-up
    let host = cpal::default_host();
    log::info!("Using host: {}", host.id().name());
    let buffer_size = 512;
    let sample_rate = 44100;
    let accepts_input = app.options().accepts_input;
    let input_tuple = if accepts_input {
        Some(configure_input_device(&host, buffer_size, sample_rate))
    } else {
        None
    };
    let (output_device, output_config) = configure_output_device(host, buffer_size, sample_rate);
    let settings = AudioProcessorSettings::new(
        output_config.sample_rate.0 as f32,
        input_tuple
            .as_ref()
            .map(|(_, input_config)| input_config.channels.into())
            .unwrap_or(0),
        output_config.channels.into(),
        buffer_size,
    );
    app.processor().prepare(settings);
    let buffer = ringbuf::RingBuffer::new((buffer_size * 10) as usize);
    let (mut producer, mut consumer) = buffer.split();
    let input_stream = input_tuple.map(|(input_device, input_config)| {
        input_device
            .build_input_stream(
                &input_config,
                move |data: &[f32], _input_info: &cpal::InputCallbackInfo| {
                    input_stream_callback(&mut producer, data)
                },
                |err| {
                    log::error!("Input error: {:?}", err);
                },
            )
            .unwrap()
    });
    // Output callback section
    let num_channels = output_config.channels.into();
    let output_stream = output_device
        .build_output_stream(
            &output_config,
            move |data: &mut [f32], _output_info: &cpal::OutputCallbackInfo| {
                output_stream_with_context(
                    midi_context.as_mut(),
                    &mut app,
                    num_channels,
                    &mut consumer,
                    data,
                );
            },
            |err| {
                log::error!("Playback error: {:?}", err);
            },
        )
        .unwrap();
    output_stream.play().unwrap();
    if let Some(input_stream) = &input_stream {
        input_stream.play().unwrap();
    }
    log::info!("Audio streams started");
    StandaloneHandles {
        input_stream,
        output_stream,
        midi_host,
    }
}
pub fn standalone_start ( mut app : impl StandaloneProcessor , handle : Option < & Handle > , ) -> StandaloneHandles { let _ = wisual_logger :: try_init_from_env ( ) ; let ( midi_host , mut midi_context ) = initialize_midi_host ( & mut app , handle ) ; // Audio set-up let host = cpal :: default_host ( ) ; log :: info ! ( " " host id ( ) name ( ) ) ; let buffer_size = 512 ; let sample_rate = 44100 ; let accepts_input = app . options ( ) . accepts_input ; let input_tuple = if accepts_input { Some ( configure_input_device ( & host , buffer_size , sample_rate ) ) } else { None } ; let ( output_device , output_config ) = configure_output_device ( host , buffer_size , sample_rate ) ; let settings = AudioProcessorSettings :: new ( output_config . sample_rate . 0 as f32 , input_tuple . as_ref ( ) . map ( | ( _ , input_config ) | input_config . channels . into ( ) ) . unwrap_or ( 0 ) , output_config . channels . into ( ) , buffer_size , ) ; app . processor ( ) . prepare ( settings ) ; let buffer = ringbuf :: RingBuffer :: new ( ( buffer_size * 10 ) as usize ) ; let ( mut producer , mut consumer ) = buffer . split ( ) ; let input_stream = input_tuple . map ( | ( input_device , input_config ) | { input_device . build_input_stream ( & input_config , move | data : & [ f32 ] , _input_info : & cpal :: InputCallbackInfo | { input_stream_callback ( & mut producer , data ) } , | err | { log :: error ! ( " " err ) ; } , ) . unwrap ( ) } ) ; // Output callback section let num_channels = output_config . channels . into ( ) ; let output_stream = output_device . build_output_stream ( & output_config , move | data : & mut [ f32 ] , _output_info : & cpal :: OutputCallbackInfo | { output_stream_with_context ( midi_context . as_mut ( ) , & mut app , num_channels , & mut consumer , data , ) ; } , | err | { log :: error ! ( " " err ) ; } , ) . unwrap ( ) ; output_stream . play ( ) . unwrap ( ) ; if let Some ( input_stream ) = & input_stream { input_stream . play ( ) . unwrap ( ) ; } log :: info ! ( " " ) ; StandaloneHandles { input_stream , output_stream , midi_host , } }
Start a processor using CPAL.
Start a processor using CPAL .
app
impl StandaloneProcessor
handle
Option<&Handle>
app
impl StandaloneProcessor
handle
Option<&Handle>