Re: [Alsa-user] snd_pcm_hw_params_set_buffer_size returns -EINVAL

2016-09-27 Thread Johannes Lorenz
On Tuesday 27 September 2016 08:28:42 Clemens Ladisch wrote:
> And you must set a buffer size that is supported by the device.

Thanks, I just found snd_pcm_hw_params_set_buffer_size_near(). However, for 
our app, it would be nice to get the preferred buffer size before any PCM 
handle and params are created. Is this possible?


--
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


[Alsa-user] snd_pcm_hw_params_set_buffer_size returns -EINVAL

2016-09-26 Thread Johannes Lorenz
Hello,

this happens in [1]. You can also call snd_pcm_hw_params_set_buffer_size() 
before snd_pcm_hw_params() (that's probably better?), it always results in (-
EINVAL).

The google-answers did not help. Any idea? In my case, the buffer size is 256, 
but it also fails is I use 32768.

Thanks on advance!
- Johannes

[1] 
https://github.com/zynaddsubfx/zynaddsubfx/blob/master/src/Nio/AlsaEngine.cpp#L331-L335


--
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Re-opening an ALSA connection

2016-09-26 Thread Johannes Lorenz
On Monday 26 September 2016 10:05:04 Clemens Ladisch wrote:
> >   * Do you need to init the hardware parameters again?
> 
> No.  When you get -ESTRPIPE, the stream was suspended, and all you have
> to do is to reinitialize it with snd_pcm_prepare() or snd_pcm_recover().

Thanks, snd_pcm_recover() worked well after s2ram.

-- 
Bitte beachten: Diese E-Mail-Adresse wird bald auslaufen. Bitte verwenden Sie 
stattdessen: johan...@lorenz-ho.me .

--
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


[Alsa-user] Re-opening an ALSA connection

2016-09-24 Thread Johannes Lorenz
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