Re: Broken Pipe with SNDRV_PCM_IOCTL_WRITEI_FRAMES

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ryan,

I realize this is probably not the answer you are waiting and hoping for, but why do you use the ioctl interface directly in the first place?
People on this list will likely be more alarmed if you had problems with audio I/O, when done as explained on
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html <https://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html>
and illustrated in the examples.

Best,

Philippe.


> On 27 Sep 2021, at 01:21, Ryan McClue <re.mcclue@xxxxxxxxxxxxxx> wrote:
> 
> I've update my loop to:
> 
> struct
> 
> snd_xferi
> 
> transfer
> 
> =
> 
> {};
>  transfer.buf = (u8 *)buffer;
>  transfer.frames = num_base_samples;
> 
> int
> 
> res = ioctl(fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &transfer);
> 
> if
> 
> (res == -EPIPE) {
>    ioctl(fd, SNDRV_PCM_IOCTL_PREPARE);
> 
> This removes the Broken Pipe, however no sound is heard.
> --
> Ryan McClue, Sydney
> 
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Sunday, September 26th, 2021 at 7:01 PM, Ryan McClue <re.mcclue@xxxxxxxxxxxxxx> wrote:
> 
>> Hello again.
>> I'm using alsa-kernel.
>> My configuration:
>> SNDRV_PCM_HW_PARAM_ACCESS = SNDRV_PCM_ACCESS_RW_INTERLEAVED
>> SNDRV_PCM_HW_PARAM_FORMAT = SNDRV_PCM_FORMAT_S16_LE
>> SNDRV_PCM_HW_PARAM_SUBFORMAT = SNDRV_PCM_SUBFORMAT_STD
>> SNDRV_PCM_HW_PARAM_CHANNELS = 2
>> SNDRV_PCM_HW_PARAM_RATE = 48000
>> 
>> I have a vsynced game loop that is running at 60fps:
>> 
>>> int num_base_samples = 48000 * (1 / 60);
>>> int num_samples =  num_base_samples * 2;
>>> int16_t buffer[num_samples] = {};
>>> 
>>> while (true) {
>>>  int16_t *samples = buffer;
>>>  for (int sample_i = 0; sample_i < num_base_samples; sample_i++) {
>>>    *samples++ = 0x33;
>>>    *samples++ = 0x33;
>>>  }
>>> 
>>>  struct snd_xferi transfer = {};
>>>  transfer.buf = buffer;
>>>  transfer.frames = num_base_samples;
>>>  ioctl(fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &transfer);
>>> 
>>>  // ioctl(fd, SNDRV_PCM_IOCTL_DRAIN);  --> NECESSARY???
>>>  // ioctl(fd, SNDRV_PCM_IOCTL_PREPARE);  --> NECESSARY???
>>> }
>> 
>> On the first iteration of SNDRV_PCM_IOCTL_WRITEI_FRAMES I get no error.
>> All subsequent iterations, I get Broken Pipe error.
>> So, to counteract this at the end of each frame I call SNDRV_PCM_IOCTL_DRAIN and SNDRV_PCM_IOCTL_PREPARE.
>> This removes the Broken Pipe error however slows the program down by half and no sound is heard.
>> How best to solve this issue?
>> 
>> Thanks again
>> --
>> Ryan McClue, Sydney





[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux