Skip to content

24 Bit Sample Support #531

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

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy