I have a program using PortAudio. Currently I'm starting it up with Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, 44100, 256, audioCB, udata)
, but when I compile and run my program it won't play sound if another program is currently running (such as a music player). The error string is PortAudio error: Device unavailable
I think I need to be running Pa_OpenStream
instead, but I'm not sure what I should be passing it to make it play nice with other programs.
for reference, I tried printing out the information on the available devices, but I'm not sure what to do with this information.
Device 0
name /dev/dsp
hostAPI 0
maxInputChannels 16
maxOutPutChannels 0
defaultLowInputLatency 0.011610
defaultLowOutputLatency -0.117208
defaultHighInputLatency 0.046440
defaultHighOutputLatency 0.000000
defaultSampleRate 44100.000000
Device 1
name /dev/dsp1
hostAPI 0
maxInputChannels 16
maxOutPutChannels 0
defaultLowInputLatency 0.011610
defaultLowOutputLatency -0.117208
defaultHighInputLatency 0.046440
defaultHighOutputLatency 0.000000
defaultSampleRate 44100.000000
Default Device -1
While writing this question, I also just noticed that the maxOutputchannels changes depending on whether or not there's another program trying to play sound. At least I think that's what made the difference. I had a paused youtube video in anther browser tab that I closed, and when I reran my program now it prints this:
Device 0
name /dev/dsp
hostAPI 0
maxInputChannels 16
maxOutPutChannels 16
defaultLowInputLatency 0.011610
defaultLowOutputLatency 0.011610
defaultHighInputLatency 0.046440
defaultHighOutputLatency 0.046440
defaultSampleRate 44100.000000
Device 1
name /dev/dsp1
hostAPI 0
maxInputChannels 16
maxOutPutChannels 0
defaultLowInputLatency 0.011610
defaultLowOutputLatency 0.011610
defaultHighInputLatency 0.046440
defaultHighOutputLatency 0.046440
defaultSampleRate 44100.000000
Default Device 0