24bit to float issue


#1

Im using this function straight out the Juce lib

inline int32_t littleEndian24Bit  (const void* bytes) noexcept    { return (int32_t) ((((uint32_t) static_cast<const uint8_t*> (bytes)[2]) << 16) | (((uint32_t) static_cast<const uint8_t*> (bytes)[1]) << 8) | ((uint32_t) static_cast<const uint8_t*> (bytes)[0])); }

To extract 24bit audio data from a web assembly project. Problem is everything less than zero is exploding. I know there are some funny quirks converting to and from PCM just wondering what I’m doing wrong

I’m applying it the same way as in juce lib aswell

const float scale = 1.0f / (float)0x7fffff;
int32_t temp = DSP::Math::littleEndian24Bit(ptr);
float sample = (scale * (float)temp);
data[c][s] = sample;

#2

Figured it… needed to make the most sig byte signed

  inline int32_t littleEndian24Bit  (const void* bytes) noexcept    { return (int32_t) ((((int32_t) static_cast<const int8_t*> (bytes)[2]) << 16) | (((uint32_t) static_cast<const uint8_t*> (bytes)[1]) << 8) | ((uint32_t) static_cast<const uint8_t*> (bytes)[0])); }

#3

If anyone is interested I got this all working
https://boowm.com