1

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:

  1. 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?
  2. 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?

Mikey A. Leonetti
  • 2,834
  • 3
  • 22
  • 36
  • I don't know anything about node.js, but I can tell you that `sf_open_virtual()` will not work, because it needs to know the length of the whole file *when opening*. If you manage to get a file descriptor or a named pipe where your PCM data is written to, it should work fine, though. Then you can simply open the file descriptor/pipe with the major type "RAW" and the subtype "PCM_16" and you will be able to read data even if new data is still coming in. – Matthias May 06 '15 at 14:24
  • 1
    everything without a header will fail... SF_INFO sfinfo; sfinfo.channels = 1; sfinfo.samplerate = 44100; sfinfo.format = SF_FORMAT_PCM_32 | SF_FORMAT_RAW; Pass &sfinfo in open and libsndfile will read headerless raw data – relascope May 20 '15 at 14:49

0 Answers0