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. http://manuals.opensound.com/developer/SNDCTL_DSP_SETFMT.html At least the following ports check requested format and would assume AFMT_FLOAT is accepted if built with sys/soundcard.h from opensound.com. devel/allegro-devel emulators/wine multimedia/audacious-plugins multimedia/mplayer multimedia/vlc Probably, only Linux accepts AFMT_FLOAT which means apps built with OSSv4 wouldn't work under linuxulator either. How-To-Repeat: # 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 =00=00=00=80=FF=FF=FF=7F=FA=FF=FF=7Fx=FF=FF=7F=E4=00=00=80=9B=FE=FF=7F # audio/oss $ ./test 0x00000010 # native $ ./test 0x00004000 $ cat test.c #include <sys/soundcard.h> #include <fcntl.h> #include <stdio.h> #ifndef AFMT_FLOAT #define AFMT_FLOAT 0x00004000 #endif 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; }
batch change: For bugs that match the following - Status Is In progress AND - Untouched since 2018-01-01. AND - Affects Base System OR Documentation DO: Reset to open status. Note: I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Hi, AFMT_FLOAT is not defined for the in-kernel OSS. If there is enough bits left we can do that. Your AFMT_FLOAT definition is actually AFMT_U32_LE, which of-course is supported when using vchans: /usr/include/sys/soundcard.h:#define AFMT_U32_LE 0x00004000 /* Little endian unsigned 32-bit */ --HPS
We are out of bits in the AFMT field in FreeBSD. So AFMT_FLOAT cannot be defined! Assume that when AFMT_FLOAT is not defined, that it is not supported. Also OSS documentation marks this feature as "not recommended". Please edit the applications in question. Thank you! --HPS
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=e1bbaa71d62c8681a576f9f5bedf475c7541bd35 commit e1bbaa71d62c8681a576f9f5bedf475c7541bd35 Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2025-03-30 17:45:38 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2025-03-30 17:45:38 +0000 sound: Implement AFMT_FLOAT support Even though the OSS manual [1] advises against using AFMT_FLOAT, there are applications that expect the sound driver to support it, and might not work properly without it. This patch adds AFMT_F32_LE|BE (as well as AFMT_FLOAT for OSS compatibility) in sys/soundcard.h and implements AFMT_F32_LE|BE <-> AFMT_S32_LE|BE conversion functions. As a result, applications can write/read floats to/from sound(4), but internally, because sound(4) works with integers, we convert floating point samples to integer ones, before doing any processing. The reason for encoding/decoding IEEE754s manually, instead of using fpu_kern(9), is that fpu_kern(9) is not supported by all architectures, and also introduces significant overhead. The IEEE754 encoding/decoding implementation has been written by Ariff Abdullah [2]. [1] http://manuals.opensound.com/developer/AFMT_FLOAT.html [2] https://people.freebsd.org/~ariff/utils/ieee754.c PR: 157050, 184380, 264973, 280612, 281390 Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D47638 sys/dev/sound/pcm/channel.c | 4 +++ sys/dev/sound/pcm/feeder_chain.c | 2 ++ sys/dev/sound/pcm/feeder_rate.c | 4 +++ sys/dev/sound/pcm/feeder_volume.c | 2 ++ sys/dev/sound/pcm/pcm.h | 67 +++++++++++++++++++++++++++++++++++++-- sys/dev/sound/pcm/sound.h | 13 +++++--- sys/sys/soundcard.h | 8 +++++ tests/sys/sound/pcm_read_write.c | 6 ++++ 8 files changed, 98 insertions(+), 8 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=1728d26682c65cb878971f55b4e87e24d0050524 commit 1728d26682c65cb878971f55b4e87e24d0050524 Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2025-03-30 17:45:38 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2025-04-06 00:28:14 +0000 sound: Implement AFMT_FLOAT support Even though the OSS manual [1] advises against using AFMT_FLOAT, there are applications that expect the sound driver to support it, and might not work properly without it. This patch adds AFMT_F32_LE|BE (as well as AFMT_FLOAT for OSS compatibility) in sys/soundcard.h and implements AFMT_F32_LE|BE <-> AFMT_S32_LE|BE conversion functions. As a result, applications can write/read floats to/from sound(4), but internally, because sound(4) works with integers, we convert floating point samples to integer ones, before doing any processing. The reason for encoding/decoding IEEE754s manually, instead of using fpu_kern(9), is that fpu_kern(9) is not supported by all architectures, and also introduces significant overhead. The IEEE754 encoding/decoding implementation has been written by Ariff Abdullah [2]. [1] http://manuals.opensound.com/developer/AFMT_FLOAT.html [2] https://people.freebsd.org/~ariff/utils/ieee754.c PR: 157050, 184380, 264973, 280612, 281390 Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D47638 (cherry picked from commit e1bbaa71d62c8681a576f9f5bedf475c7541bd35) sys/dev/sound/pcm/channel.c | 4 +++ sys/dev/sound/pcm/feeder_chain.c | 2 ++ sys/dev/sound/pcm/feeder_rate.c | 4 +++ sys/dev/sound/pcm/feeder_volume.c | 2 ++ sys/dev/sound/pcm/pcm.h | 67 +++++++++++++++++++++++++++++++++++++-- sys/dev/sound/pcm/sound.h | 13 +++++--- sys/sys/soundcard.h | 8 +++++ tests/sys/sound/pcm_read_write.c | 6 ++++ 8 files changed, 98 insertions(+), 8 deletions(-)