cpal icon indicating copy to clipboard operation
cpal copied to clipboard

ALSA: Provide info wether HW provides pause/play

Open Chief-Detektor opened this issue 8 years ago • 5 comments

Hi! Thanks for this great library! :) I was a little bit confused that a call to event_loop.pause and event_loop.pause had no effect on my system because I obviously does not have this capability on my HW. This is not a big deal but I thought I would be nice if cpal notifies the users that this feature is not available when calling it in debug mode. It could prevent others from being confused or even open a bug ticket.

Chief-Detektor avatar Feb 01 '18 15:02 Chief-Detektor

I agree that there should definitely be a way to report that. Probably one method for the capability, plus make the pause function return a result.

tomaka avatar Feb 02 '18 12:02 tomaka

Switched my HW and now everything works as expected. But I recognized that in some situations play and pause (alsa::snd_pcm_pause) might fail returning -77 c_int as error code. It might be desirable to pass the error to the user to indicate if the call failed or succeeded.

Chief-Detektor avatar Feb 02 '18 17:02 Chief-Detektor

@Chief-Detektor I'm currently thinking a bit about pause behaviour and I'm curious about your case. What device were you using that did not support pause?

I wonder what the effective difference is between creating and destroying the stream vs playing and pausing it. I also can't help but wonder how common it is that devices support "pause" and relative to how often they do not. In downstream projects that require playing/pausing streams frequently (e.g. in a DAW), is it simply up to the user to check for hw pause capabilities, pause if possible, otherwise just destroy their stream and then recreate it when they need to play again? Or perhaps they swap out the callback with one that just writes silence instead?

What got me wondering about this was how to handle streams that are still playing before returning from EventLoop::run #245. It's not super clear to me yet what the expected behaviour across all platforms.

It could be worth checking how JACK, PortAudio and others handle pausing.

The ALSA functions for reference:

mitchmindtree avatar Oct 21 '18 12:10 mitchmindtree

There would be snd_pcm_drop/prepare.
But the 1st question is, why pause() returns successful result when it doesn't pause and uses ~100% CPU in thread.

I got a problem with this, because dropping and creating new streams in cpal is no option when using pipewire-alsa.
The stream setup is so slow with pipewire in its graph.

kolbma avatar Feb 07 '26 19:02 kolbma

Another advantage is that pausable streams can pause and resume the DMA audio transfer mid-period. So resuming is instant and position-exact.

I'm considering to add StreamTrait::stop() to differentiate between tearing down the stream and pause() indeed pausing the stream.

Next to that, a way to query whether a stream is pausable. I actually think that's device-specific and not stream-specific, so it could be one of the following:

  • DeviceTrait::pausable()
  • Devicetrait::is_pausable()
  • DeviceTrait::can_pause()

Or similar on DeviceDescription instead of DeviceTrait.

roderickvd avatar Apr 22 '26 19:04 roderickvd