-
Notifications
You must be signed in to change notification settings - Fork 469
add native dsd support #1078
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
base: master
Are you sure you want to change the base?
add native dsd support #1078
Changes from 1 commit
8d14297
2b027ec
2638bbb
7f3276b
d971024
e63c7a4
7f46481
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,16 @@ pub enum SampleFormat { | |
|
|
||
| /// `f64` with a valid range of `-1.0..=1.0` with `0.0` being the origin. | ||
| F64, | ||
|
|
||
| // DSD Formats | ||
| // ----------- | ||
|
|
||
| /// DSD stream (U8) | ||
|
||
| DsdU8, | ||
| /// DSD stream (U16) | ||
| DsdU16, | ||
| /// DSD stream (U32) | ||
| DsdU32, | ||
| } | ||
|
|
||
| impl SampleFormat { | ||
|
|
@@ -129,6 +139,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>(), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -153,6 +166,9 @@ impl SampleFormat { | |
| SampleFormat::U64 => u64::BITS, | ||
| SampleFormat::F32 => 32, | ||
| SampleFormat::F64 => 64, | ||
| SampleFormat::DsdU8 => 8, | ||
roderickvd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SampleFormat::DsdU16 => 16, | ||
| SampleFormat::DsdU32 => 32, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -181,6 +197,9 @@ impl SampleFormat { | |
| | SampleFormat::U32 | ||
| // | SampleFormat::U48 | ||
| | SampleFormat::U64 | ||
| | SampleFormat::DsdU8 | ||
| | SampleFormat::DsdU16 | ||
| | SampleFormat::DsdU32 | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -208,6 +227,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) | ||
| } | ||
|
|
@@ -286,3 +308,123 @@ impl SizedSample for f32 { | |
| impl SizedSample for f64 { | ||
| const FORMAT: SampleFormat = SampleFormat::F64; | ||
| } | ||
|
|
||
| /// DSD stream sample (U8). | ||
| #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)] | ||
| pub struct DsdU8(pub u8); | ||
|
|
||
| impl Sample for DsdU8 { | ||
| type Float = f32; | ||
| type Signed = i8; | ||
|
|
||
| const EQUILIBRIUM: Self = DsdU8(0x69); | ||
| } | ||
|
|
||
| // Conflict with blanket impl in dasp_sample | ||
| // impl FromSample<DsdU8> for DsdU8 { ... } | ||
|
|
||
| impl FromSample<f32> for DsdU8 { | ||
roderickvd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fn from_sample_(_sample: f32) -> Self { | ||
| DsdU8(0x69) | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<i8> for DsdU8 { | ||
| fn from_sample_(_sample: i8) -> Self { | ||
| DsdU8(0x69) | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<DsdU8> for i8 { | ||
| fn from_sample_(_sample: DsdU8) -> Self { | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<DsdU8> for f32 { | ||
| fn from_sample_(_sample: DsdU8) -> Self { | ||
| 0.0 | ||
| } | ||
| } | ||
|
|
||
| impl SizedSample for DsdU8 { | ||
| const FORMAT: SampleFormat = SampleFormat::DsdU8; | ||
| } | ||
|
|
||
| /// DSD stream sample (U16). | ||
| #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)] | ||
| pub struct DsdU16(pub u16); | ||
|
|
||
| impl Sample for DsdU16 { | ||
| type Float = f32; | ||
| type Signed = i16; | ||
|
|
||
| const EQUILIBRIUM: Self = DsdU16(0x6969); | ||
| } | ||
|
|
||
| impl FromSample<f32> for DsdU16 { | ||
| fn from_sample_(_sample: f32) -> Self { | ||
| DsdU16(0x6969) | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<DsdU16> for f32 { | ||
| fn from_sample_(_sample: DsdU16) -> Self { | ||
| 0.0 | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<i16> for DsdU16 { | ||
| fn from_sample_(_sample: i16) -> Self { | ||
| DsdU16(0x6969) | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<DsdU16> for i16 { | ||
| fn from_sample_(_sample: DsdU16) -> Self { | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| impl SizedSample for DsdU16 { | ||
| const FORMAT: SampleFormat = SampleFormat::DsdU16; | ||
| } | ||
|
|
||
| /// DSD stream sample (U32). | ||
| #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)] | ||
| pub struct DsdU32(pub u32); | ||
|
|
||
| impl Sample for DsdU32 { | ||
| type Float = f32; | ||
| type Signed = i32; | ||
|
|
||
| const EQUILIBRIUM: Self = DsdU32(0x69696969); | ||
| } | ||
|
|
||
| impl FromSample<f32> for DsdU32 { | ||
| fn from_sample_(_sample: f32) -> Self { | ||
| DsdU32(0x69696969) | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<DsdU32> for f32 { | ||
| fn from_sample_(_sample: DsdU32) -> Self { | ||
| 0.0 | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<i32> for DsdU32 { | ||
| fn from_sample_(_sample: i32) -> Self { | ||
| DsdU32(0x69696969) | ||
| } | ||
| } | ||
|
|
||
| impl FromSample<DsdU32> for i32 { | ||
| fn from_sample_(_sample: DsdU32) -> Self { | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| impl SizedSample for DsdU32 { | ||
| const FORMAT: SampleFormat = SampleFormat::DsdU32; | ||
| } | ||
There was a problem hiding this comment.
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)There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this?