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

24 Bit Sample Support #531

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

julientregoat
Copy link

original issue here #414. there was also discussion in the 32 bit PR before it was split off #420

@roderickvd
Copy link

If it helps any bit, I've got a working implementation of S24 and S24_3 samples using a i24 type in librespot-org/librespot#660.

Basically:

#[derive(AsBytes, Copy, Clone, Debug)]
 #[allow(non_camel_case_types)]
 #[repr(transparent)]
 pub struct i24([u8; 3]);
 impl i24 {
     fn pcm_from_i32(sample: i32) -> Self {
         // drop the least significant byte
         let [a, b, c, _d] = (sample >> 8).to_le_bytes();
         i24([a, b, c])
     }
 }

and:

macro_rules! convert_samples_to {
     ($type: ident, $samples: expr) => {
         convert_samples_to!($type, $samples, 0)
     };
     ($type: ident, $samples: expr, $drop_bits: expr) => {
         $samples
             .iter()
             .map(|sample| {
                 (*sample as f64 * (std::$type::MAX as f64 + 0.5) - 0.5) as $type >> $drop_bits
             })
             .collect()
     };
 }

 pub struct SamplesConverter {}
 impl SamplesConverter {

// ...

     pub fn to_s24(samples: &[f32]) -> Vec<i32> {
         convert_samples_to!(i32, samples, 8)
     }

     pub fn to_s24_3(samples: &[f32]) -> Vec<i24> {
         Self::to_s32(samples)
             .iter()
             .map(|sample| i24::pcm_from_i32(*sample))
             .collect()
     }

// ...

 }

@RoccoDevs
Copy link

Is there any progress on this?

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

Successfully merging this pull request may close these issues.

3 participants