Broken Pipe with SNDRV_PCM_IOCTL_WRITEI_FRAMES
Ryan McClue
re.mcclue at protonmail.com
Sun Sep 26 11:01:24 CEST 2021
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
More information about the Alsa-devel
mailing list