Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl Device {
// Test both LE and BE formats to detect what the hardware actually supports.
// LE is listed first as it's the common case for most audio hardware.
// Hardware reports its supported formats regardless of CPU endianness.
const FORMATS: [(SampleFormat, alsa::pcm::Format); 18] = [
const FORMATS: [(SampleFormat, alsa::pcm::Format); 23] = [
(SampleFormat::I8, alsa::pcm::Format::S8),
(SampleFormat::U8, alsa::pcm::Format::U8),
(SampleFormat::I16, alsa::pcm::Format::S16LE),
Expand All @@ -501,6 +501,11 @@ impl Device {
(SampleFormat::F32, alsa::pcm::Format::FloatBE),
(SampleFormat::F64, alsa::pcm::Format::Float64LE),
(SampleFormat::F64, alsa::pcm::Format::Float64BE),
(SampleFormat::DsdU8, alsa::pcm::Format::DSDU8),
(SampleFormat::DsdU16, alsa::pcm::Format::DSDU16LE),
(SampleFormat::DsdU16, alsa::pcm::Format::DSDU16BE),
(SampleFormat::DsdU32, alsa::pcm::Format::DSDU32LE),
(SampleFormat::DsdU32, alsa::pcm::Format::DSDU32BE),
//SND_PCM_FORMAT_IEC958_SUBFRAME_LE,
//SND_PCM_FORMAT_IEC958_SUBFRAME_BE,
//SND_PCM_FORMAT_MU_LAW,
Expand Down Expand Up @@ -1284,6 +1289,9 @@ fn fill_with_equilibrium(buffer: &mut [u8], sample_format: SampleFormat) {
SampleFormat::U64 => fill_typed!(u64),
SampleFormat::F32 => fill_typed!(f32),
SampleFormat::F64 => fill_typed!(f64),
SampleFormat::DsdU8 => fill_typed!(u8),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be fill_typed!(DsdU8)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now when I removed structs I am not sure what to use here. any suggestion?

SampleFormat::DsdU16 => fill_typed!(u16),
SampleFormat::DsdU32 => fill_typed!(u32),
}
}

Expand Down Expand Up @@ -1350,6 +1358,15 @@ fn sample_format_to_alsa_format(
SampleFormat::F64 => (Format::Float64LE, Format::Float64BE),
#[cfg(target_endian = "big")]
SampleFormat::F64 => (Format::Float64BE, Format::Float64LE),
SampleFormat::DsdU8 => return Ok(Format::DSDU8),
#[cfg(target_endian = "little")]
SampleFormat::DsdU16 => (Format::DSDU16LE, Format::DSDU16BE),
#[cfg(target_endian = "big")]
SampleFormat::DsdU16 => (Format::DSDU16BE, Format::DSDU16LE),
#[cfg(target_endian = "little")]
SampleFormat::DsdU32 => (Format::DSDU32LE, Format::DSDU32BE),
#[cfg(target_endian = "big")]
SampleFormat::DsdU32 => (Format::DSDU32BE, Format::DSDU32LE),
_ => {
return Err(BackendSpecificError {
description: format!("Sample format '{sample_format}' is not supported"),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ impl From<SupportedStreamConfig> for StreamConfig {
#[allow(dead_code)]
pub(crate) const COMMON_SAMPLE_RATES: &[SampleRate] = &[
5512, 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000,
176400, 192000, 352800, 384000,
176400, 192000, 352800, 384000, 705600, 768000, 1411200, 1536000,
];

#[test]
Expand Down
21 changes: 21 additions & 0 deletions src/samples_formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ pub enum SampleFormat {

/// `f64` with a valid range of `-1.0..=1.0` with `0.0` being the origin.
F64,

/// DSD stream (U8)
DsdU8,

/// DSD stream (U16)
DsdU16,

/// DSD stream (U32)
DsdU32,
}

impl SampleFormat {
Expand All @@ -129,6 +138,9 @@ impl SampleFormat {
SampleFormat::U64 => mem::size_of::<u64>(),
SampleFormat::F32 => mem::size_of::<f32>(),
SampleFormat::F64 => mem::size_of::<f64>(),
SampleFormat::DsdU8 => mem::size_of::<u8>(),
SampleFormat::DsdU16 => mem::size_of::<u16>(),
SampleFormat::DsdU32 => mem::size_of::<u32>(),
}
}

Expand All @@ -153,6 +165,9 @@ impl SampleFormat {
SampleFormat::U64 => u64::BITS,
SampleFormat::F32 => 32,
SampleFormat::F64 => 64,
SampleFormat::DsdU8 => 1,
SampleFormat::DsdU16 => 1,
SampleFormat::DsdU32 => 1,
}
}

Expand Down Expand Up @@ -181,6 +196,9 @@ impl SampleFormat {
| SampleFormat::U32
// | SampleFormat::U48
| SampleFormat::U64
| SampleFormat::DsdU8
| SampleFormat::DsdU16
| SampleFormat::DsdU32
)
}

Expand Down Expand Up @@ -208,6 +226,9 @@ impl Display for SampleFormat {
SampleFormat::U64 => "u64",
SampleFormat::F32 => "f32",
SampleFormat::F64 => "f64",
SampleFormat::DsdU8 => "DsdU8",
SampleFormat::DsdU16 => "DsdU16",
SampleFormat::DsdU32 => "DsdU32",
}
.fmt(f)
}
Expand Down