andrewrk / libsoundio

C library for cross-platform real-time audio input and output
http://libsound.io/
MIT License
1.92k stars 229 forks source link

Jack backend does not handle sample formats correctly #139

Open jpcima opened 7 years ago

jpcima commented 7 years ago

I am currently trying to port a synthesizer program from rtaudio to libsoundio. The synth is written largely in fixed-point integer and outputs signed 16 bit samples.

Now when I request the sample format S16NE and I also use the Jack backend, the audio output is garbage. I know Jack jack accepts only float data, but I act as if I do not know being user of the library. (previously rtaudio did automatic sample conversion from the program to Jack)

I request the format like suggested on the main page example, you can see the steps in the source linked for reference. https://gist.github.com/jpcima/96f842a1d78d643e70d4531ac2ef3acc

I tested the following scenarii:

  1. using Pulseaudio, either int16 or float sample type -> OK
  2. using Jack, float sample type, or format not specified -> OK
  3. using Jack, int16 sample type -> NOT OK

I would expect from the library either of these outcomes, but none happen.

  1. emitting an error
  2. automatic sample conversion (rtaudio behavior)
  3. change stream->format whatever is supported, and make the user is responsible for converting manually.
andrewrk commented 7 years ago

Thank you for the report. Looks like you found a bug. The intended behavior is (1) emitting an error if the backend cannot support the sample format.

One thing you can do in the mean time is check the device capabilities before opening the stream. I believe that will be correct and can be a workaround until this is fixed.

jpcima commented 7 years ago

As you have have suggested I now check the capabilities given by device->formats. According to this list I select the first one of int16/float which is available, in that order. I confirm the problem is resolved on my side. Thanks 👍