My goal is to take a PCM stream in Node.js that is, even for example, 44100Hz 16 bit stereo, and then resample it to 8000 Hz 8 bit mono to then be encoded into Opus and then streamed.
My thought was to try making bindings for libsndfile in C++ and using sf_open_virtual function for resampling on the stream. However:
- How can I reply to its callback function requesting a certain amount of data (found here: http://www.mega-nerd.com/libsndfile/api.html#open_virtual) if my program is still receiving data from the network? Do I just let it hang in a loop until the loop detects that the buffer is a certain percent full?
- Since the PCM data is going to be headerless, how can I specify the format type for libsndfile to expect?
Or am I over-complicating things totally?