Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Error 'The requested stream configuration is not supported by the device on Mac with wav files' running the play wav example #173

Open
dathinaios opened this issue Apr 18, 2022 · 0 comments

Comments

@dathinaios
Copy link

I am trying to run the play wav example from the dasp repo here:

https://github.com/RustAudio/dasp/blob/master/examples/play_wav.rs

I had to change the use format from dasp::signal to dasp_signal in order for it to compile but I am getting Error: The requested stream configuration is not supported by the device. Not sure what that is about as I tried with multiple wave files, stereo and mono, 16 and 24 bit. Still getting the same issue. On a Mac with an Apollo Twin Audio Interface:

Device: Ok("Universal Audio Thunderbolt") Config: StreamConfig { channels: 2, sample_rate: SampleRate(44100), buffer_size: Default } Error: The requested stream configuration is not supported by the device.

The code:

main.rs

use cpal;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use dasp_signal::{self, Signal};
use dasp_slice::ToFrameSliceMut;

fn main() -> Result<(), anyhow::Error> {
    // Find and load the wav.
    let assets = find_folder::Search::ParentsThenKids(5, 5)
        .for_folder("assets")
        .unwrap();
    let reader = hound::WavReader::open(assets.join("amen16.wav")).unwrap();
    let spec = reader.spec();

    // Read the interleaved samples and convert them to a signal.
    let samples = reader.into_samples::<i16>().filter_map(Result::ok);
    let mut frames = dasp_signal::from_interleaved_samples_iter(samples).until_exhausted();

    // Initialise CPAL.
    let host = cpal::default_host();
    let device = host
        .default_output_device()
        .expect("failed to find a default output device");

    // Create a stream config to match the wave format.
    let config = cpal::StreamConfig {
        channels: spec.channels,
        sample_rate: cpal::SampleRate(spec.sample_rate),
        buffer_size: cpal::BufferSize::Default,
    };

    //debug
    println!("Device: {:?}", device.name());
    println!("Config: {:?}", config);

    // A channel for indicating when playback has completed.
    let (complete_tx, complete_rx) = std::sync::mpsc::sync_channel(1);

    // Create and run the CPAL stream.
    let err_fn = |err| eprintln!("an error occurred on stream: {}", err);
    let data_fn = move |data: &mut [i16], _info: &cpal::OutputCallbackInfo| {
        let buffer: &mut [[i16; 2]] = data.to_frame_slice_mut().unwrap();
        for out_frame in buffer {
            match frames.next() {
                Some(frame) => *out_frame = frame,
                None => {
                    complete_tx.try_send(()).ok();
                    *out_frame = dasp::Frame::EQUILIBRIUM;
                }
            }
        }
    };
    let stream = device.build_output_stream(&config, data_fn, err_fn)?;
    stream.play().unwrap();

    // Block until playback completes.
    complete_rx.recv().unwrap();
    stream.pause().ok();
    Ok(())
}


Cargo.toml

[package]
name = "iterate"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dasp = "0.11.0"
dasp_signal = "0.11.0"
dasp_slice = "0.11.0"
cpal = "0.13.5"
anyhow = "1.0.56"
find_folder = "0.3.0"
hound = "3.4.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant