0
$\begingroup$

I posted this in stackoverflow but a poster suggested I ask the question here too...

Basically, I'm getting a USB audio stream in the form of a unsigned 8-bit integer pointer. I want to convert whatever bit rate it's using (whether 16 or 24 bit audio) and scale it up to 32 bits. Once it's scaled up to 32 bits, I'm placing it in a microcontroller's peripheral that will output the data in a 32 bit register. I would also like to do this in the reverse order (getting input from a codec in 32-bit words and then sending it to my USB Host in either 16 or 24 bit audio streams).

Just wanted to open a discussion on how people bit scale these streams and what techniques/algorithms they use.

tl;dr - I want to be able to scale up 16/24 bit audio streams to 32 bit words and vice versa for scaling down. I know the process for scaling down as such:

// For 32 to 16 bits
uint16_t adjusted_bit = uint32_bit_data >> 16;
// For 32 to 24 bits
uint32_t adjusted bit = uint32_bit_data >> 8;

Thanks!

$\endgroup$
  • $\begingroup$ Why are you wanting to do this? You can accomplish what you're looking for using simple bit shifting in either direction, but that doesn't really do anything useful to the signal itself. What's the end effect that you're looking for? $\endgroup$ – Jason R Jan 18 '17 at 15:57
  • $\begingroup$ @JasonR Hey Jason, I'm doing this because I have to get my microcontroller's peripherals be happy with the data it's receiving (they work with 32-bit words). Whenever I try to switch my audio configurations to 24 bits/correct buffer sizes, I get either nothing or a huge distorted sound. However streaming 16 bits seems to be fine. $\endgroup$ – yun Jan 18 '17 at 16:03
  • 2
    $\begingroup$ Integer audio samples are just that, a sequence of numbers. If you have a 16- or 24-bit samples that you want to pass through a 32-bit peripheral, you could do 2 things: just pass them through without modification, or scale them to fit the increased dynamic range provided by the 32-bit type. You can then just undo the scaling later if you need to convert back to the original format. The scaling can be done using bit shifts like you already described. It's not clear what your issue is; you should be able to transmit the samples losslessly to the other end using such a scheme. $\endgroup$ – Jason R Jan 18 '17 at 16:06
  • $\begingroup$ @JasonR Well I just noticed I made a mistake in my code (I didn't set one of my peripherals to accept full 32-bit words). However, when I set it, my 16-bit audio stream sounded very broken (compared to 16-bit words). The issue is that when I don't send the audio stream with the correct framing the audio quality deteriorates. I want to scale the bits because I want to match the framing as suggested by the mcu's datasheet $\endgroup$ – yun Jan 18 '17 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.