PortAudio/portaudio

Replay the same WAV file many times in a loop

Closed this issue · 9 comments

Actually, the play itself works. The issue is when replaying the same stream again. I'm writing headless D-BUS service for playing WAV files.
API is quite simple as:

  • start(path)
  • stop()

When the first play comes it runs the following steps

Pa_Initialize(...)
sf_open(...)
Pa_OpenDefaultStream(...)
Pa_SetStreamFinishedCallback(..)
Pa_StartStream(...)

And the system starts playing.
When playing finished I'm not closing the stream and waiting for the next command. If the user asks me to replay the same file again.

I'm making sf_seek to the start and calling Pa_StartStream on the same stream and getting PaError = 'Stream is not stopped'.Actually, it's stopped. I have checked it in the finished callback.
If I will close the stream and open it again everything works like a charm.

Does it mean that I need to close the stream after each file play?

Version 19.7.0

@philburk Please respond :)

Did you call Pa_StopStream? You always need to do that to stop the stream even if you return paComplete from the callback.

An easy fix is to just always call Pa_StopStream() before you call Pa_StartStream().
Let us know if that works for you?

Did you call Pa_StopStream? You always need to do that to stop the stream even if you return paComplete from the callback.

I have made Pa_CloseSteam and then Start stream it helps in this case. When I'm making Start stream and then after 1sec delay Play stream stuttering happens.

There is no need to call CloseStream, StopStream is enough.

As for stuttering, without seeing your code it's impossible to determine the cause of stuttering. Make sure you aren't doing file IO in the PortAudio callback.

General support is out of scope for our github tickets. I recommend you ask for help on the mailing list.

This page describes things that should not be done in a callback.
https://files.portaudio.com/docs/v19-doxydocs/writing_a_callback.html

Thanks