Zackriya-Solutions/meetily · error · anyhow::Error

Unsupported sample format: {:?}

Error message

Unsupported sample format: {:?}

What it means

The cpal match over config.sample_format() fell through to the catch-all arm: the negotiated device format is one stream.rs does not convert (the handled arms cover f32/i16/u16/i8; anything else like I32/U32/I64/U64 hits the error). No stream can be built for that device configuration.

Source

Thrown at frontend/src-tauri/src/audio/stream.rs:307

            }
            cpal::SampleFormat::I8 => {
                let capture_clone = capture.clone();
                device.build_input_stream(
                    &config_copy.into(),
                    move |data: &[i8], _: &cpal::InputCallbackInfo| {
                        let f32_data: Vec<f32> = data.iter()
                            .map(|&sample| sample as f32 / i8::MAX as f32)
                            .collect();
                        capture.process_audio_data(&f32_data);
                    },
                    move |err| {
                        capture_clone.handle_stream_error(err);
                    },
                    None,
                )?
            }
            _ => {
                return Err(anyhow::anyhow!("Unsupported sample format: {:?}", config.sample_format()));
            }
        };

        Ok(stream)
    }

    /// Get device info
    pub fn device(&self) -> &AudioDevice {
        &self.device
    }

    /// Stop the stream
    pub fn stop(self) -> Result<()> {
        info!("Stopping audio stream for device: {}", self.device.name);

        match self.backend {
            StreamBackend::Cpal(stream) => {
                // CRITICAL: Pause the stream first to stop callbacks immediately

View on GitHub (pinned to 0281737d87)

Solutions

  1. Negotiate a supported format: iterate device.supported_input_configs() and request F32 or I16 before building
  2. Add a conversion arm for the reported format (e.g. I32 to f32 via sample as f32 / i32::MAX as f32)
  3. Pick a different device that exposes a supported format

Example fix

// before
_ => {
    return Err(anyhow::anyhow!("Unsupported sample format: {:?}", config.sample_format()));
}

// after - convert 32-bit integer PCM too, keep the guard for anything else
cpal::SampleFormat::I32 => {
    device.build_input_stream(
        &config.clone().with_sample_format(cpal::SampleFormat::I32),
        move |data: &[i32], _: &cpal::InputTimestamp| {
            let f32_data: Vec<f32> = data.iter()
                .map(|&sample| sample as f32 / i32::MAX as f32)
                .collect();
            capture_clone.process_audio_data(&f32_data);
        },
        move |err| capture_err.handle_stream_error(err),
        None,
    )?
}
_ => {
    return Err(anyhow::anyhow!("Unsupported sample format: {:?}", config.sample_format()));
}
Defensive patterns

Strategy: validation

Validate before calling

fn supported(f: cpal::SampleFormat) -> bool {
    matches!(f, cpal::SampleFormat::F32 | cpal::SampleFormat::I16
                | cpal::SampleFormat::U16 | cpal::SampleFormat::I8)
}

// Negotiate a convertible config before calling build_input_stream
let cfg = device.supported_input_configs()?
    .find(|r| {
        let c = r.with_sample_format(cpal::SampleFormat::F32);
        supported(c.sample_format())
    })
    .ok_or_else(|| anyhow!("Device exposes no supported sample format"))?;

Prevention

When it happens

Trigger: build_input_stream is called with a device whose negotiated config reports SampleFormat::I32 (professional interfaces, some ALSA/loopback configs), U32, or 64-bit formats - any format without a matching conversion arm.

Common situations: Pro audio interfaces (RME, Focusrite) exposing 32-bit integer PCM; Linux ALSA devices negotiated to unusual formats; Bluetooth HFP profiles exposing odd formats; new cpal versions adding SampleFormat variants the match does not cover.

Related errors


AI-assisted analysis of Zackriya-Solutions/meetily@0281737d87 (2026-08-16). Data as JSON: /api/errors/7be16cf4354e5399. Report an issue: GitHub.