Hello,
the C++ app I am working on uses ALSA and usually works. However, when I s2ram
my computer while an ALSA connection is active, and the computer starts again,
the connection is broken (snd_pcm_writei returns < 0). In that case, I'd like
to reopen the connection. This raises up questions:
* Do the calls of snd_pcm_... have to match per thread? I.e. can you call
snd_pcm_open() with one thread and then call snd_pcm_close() with another
one? Is there a portable answer, i.e. one that's true for all systems?
* Do you need to init the hardware parameters again? In my case, must the
code from [1] be re-executed? Actually, if you've saved the params object
from the previous connection, I'd have said "no", However, the audio
handle was always involved in the snd_pcm_hw_params() calls, which makes
me unsure whether they could really be left out for a "reopen". In the
code from [1], I'd have simply done this:
reopenAudio();
{
// token from stopAudio()
snd_pcm_t *handle = audio.handle;
audio.handle = NULL;
snd_pcm_drain(handle);
if(snd_pcm_close(handle)) { /* error handling ... */ }
// token from openAudio(), but without lines 291-320:
int rc = 0;
/* Open PCM device for playback. */
audio.handle = NULL;
const char *device = getenv("ALSA_DEVICE");
if(device == 0)
device = "hw:0";
rc = snd_pcm_open(&audio.handle, device,
SND_PCM_STREAM_PLAYBACK, 0);
if(rc < 0) { /* error handling... */ }
/* ??? no need to re-init audio params here ??? */
/* Write the parameters to the driver */
rc = snd_pcm_hw_params(audio.handle, audio.params);
if(rc < 0) { /* error handling... */ }
}
Thanks + regards,
Johannes
[1]
https://github.com/zynaddsubfx/zynaddsubfx/blob/master/src/Nio/AlsaEngine.cpp#L291-L320
--
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user