kern/184380: [pcm] SNDCTL_DSP_SETFMT accepts unsupported values

Jan Beich jbeich at
Sat Nov 30 01:20:06 UTC 2013

>Number:         184380
>Category:       kern
>Synopsis:       [pcm] SNDCTL_DSP_SETFMT accepts unsupported values
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 30 01:20:00 UTC 2013
>Originator:     Jan Beich
>Release:        FreeBSD 11.0-CURRENT amd64
According to SNDCTL_DSP_SETFMT documentation if the ioctl() succeeds
the application must check if value was accepted. Unfortunately, our
OSS implementation may return value that's not actually supported.

At least the following ports check requested format and would assume
AFMT_FLOAT is accepted if built with sys/soundcard.h from


Probably, only Linux accepts AFMT_FLOAT which means apps built with
OSSv4 wouldn't work under linuxulator either.

# kern/21073, audio/oss
$ ./dsp-record -b float
Trying    8012 Hz 1 Channel float Format
ioctl(SNDCTL_DSP_SETFMT) failed: Tried 16384, Got 16

# kern/21073, native
$ ./dsp-record -b float | head -1 | vis -m
Trying    8012 Hz 1 Channel float Format
Recording 8012 Hz 1 Channel float Format

# audio/oss
$ ./test

# native
$ ./test

$ cat test.c
#include <sys/soundcard.h>

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

#ifndef AFMT_FLOAT
#define AFMT_FLOAT 0x00004000

int main()
  int fd = open("/dev/dsp", O_RDWR, 0);

  int format = AFMT_FLOAT;
  if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0)
    return 1;

  printf("%0#10x\n", format);

  return 0;



More information about the freebsd-bugs mailing list