Subject: kern/34647: audio(4) silence insertion is broken
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Andreas Gustafsson <gson@gson.org>
List: netbsd-bugs
Date: 09/28/2006 10:10:00
>Number:         34647
>Category:       kern
>Synopsis:       audio(4) silence insertion is broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 28 10:10:00 +0000 2006
>Originator:     Andreas Gustafsson
>Release:        NetBSD 3.99.24
>Organization:
>Environment:
System: NetBSD guava.gson.org 3.99.24 NetBSD 3.99.24 (GENERIC) #0: Fri Aug 4 13:14:16 EEST 2006 root@guru.araneus.fi:/usr/build/1005/obj/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:

The audio(4) man page states:

   If a writing process does not call write(2) frequently enough to
   provide samples at the pace the hardware consumes them silence is
   inserted. 

In actuality, random noises appear in the audio output in this
situation.  I have observed this behavior on two different machines,
one having an Ensoniq AudioPCI (eap(4)) and the other having an Acer
Labs M5451 (autri(4)), which leads me to believe that the problem is
in the generic audio(4) framework rather than in any one specific
hardware driver.

>How-To-Repeat:

Compile and run the following program, for example by saving it as
test.c and running "cc test.c -lm && ./a.out":

#include <fcntl.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
        int fd;
        char buf[4000];

        fd = open("/dev/audio", O_WRONLY);
        if (fd == -1) {
                fprintf(stderr, "could not open /dev/audio\n");
                exit(1);
        }

        memset(buf, 0, sizeof buf);
        write(fd, buf, sizeof buf);

        sleep(10);
        exit(0);
}

This should play half a second of silence followed by another ten
seconds of silence inserted by the audio driver due to lack of data;
any sound appearing appearing on the sound card output means you
are suffering from the bug.

>Fix:

None provided.