I'm currently converting a Float32Array to an Int32Array for input to a real-time audio raw PCM to MP3 recording application.
new Int32Array([...new Float32Array(b)].map(f=>f<0?f*32768:f*32767)
The examples in the wild I've seen convert each float individually to avoid static, gaps, glitches when the audio recording is played back. I have a sense there is a way to do this without comparing each float, though I've seen no such examples in the wild for audio processing.
Looking at the I wonder is there a way to do this without comparing each float, basically, what is the shortest code to convert a Float32Array to a Int32Array or Int16Array for audio processing?
Int32Array.from(new Float32Array(b), f => f * 32768)or some such is generally more efficient than round-tripping through an intermediate array. \$\endgroup\$8**5reduces by 1 character. \$\endgroup\$f*32768orf*8**5. \$\endgroup\$