How to convert AudioBuffer<float> to correct PCM 16-bit integer

Hi, good day!

As per subject, we would like to know if there is a way to convert AudioBuffer parameter passed to the processBlock() method of the AudioProcess class (assuming that we do that via another thread) into PCM 16bitInt stream.

Thanks in advance and regards!

Well the conversion itself is just a multiplication followed by proper integer rounding. The AudioData class has some handy functions to do that, have a look at the example code in the AudioData::Pointer docs. Not sure what you mean by

Or how the conversion operation itself should be dependent on the thread you run it on :thinking:

1 Like

When I said “via another thread”, I was actually referring to another protocol – say sendFrame() and receiveFrame() calls from a websocket connection. Anyway, thanks for the tip – I actually had taken a look into that class previously but I guess I would need to put more attention to it now. Thanks again!

Alright, if you want to send/receive the samples from another thread you might also want to have a look at lock free queues in order to implement the communication thread safe and lock free (which is important for realtime audio)

1 Like

Will do, thanks!