Format of captured data from /dev/dsp?.?

The following sequence captures audio from the microphone (if mixer has been configured to do so) and then playbacks to the speakers:

cat /dev/dsp0.0 > rawaudio
cat rawaudio > /dev/dsp0.0

I would like to understand which format is used. Is there any specific place where I could look for further information?

Note: this is not a practical question, so I am not looking for an audio command line utility such as sox. What I would like to understand is in which format FreeBSD delivers and receives data in dsp device files.

Thanks
 
It might help to not visualise any one format in this context.

From <https://news.ycombinator.com/item?id=28055096> (2021-08-03), with added emphasis:

… enlightenment … you can just cat a wav file into /dev/audio (or /dev/dsp? forget the exact name). And that you can produce white noise by catting /dev/random to the same destination. With no barrier to the sound card like that, I was free to experiment with programming different noise algorithms and figuring out how digital audio works. I eventually did things the proper way with OSS and finally sndio on OpenBSD, but direct, universal interfaces like files invite that initial exploration …

audio - Playing, recording, and streaming sound with cat and /dev/dsp - Unix & Linux Stack Exchange (2021-08-22)

2010: any port use /dev/dsp directly? - Gary Kline - org.freebsd.freebsd-questions - MarkMail



More advanced (beyond me), from Goran Mekić:

<https://old.reddit.com/r/freebsd/comments/q7aari/-/>FreeBSD Audio (2021-10-12) ◀ <https://news.ycombinator.com/item?id=28850513>

PS welcome to FreeBSD Forums!
 
Thanks grahamperrin, after posting my question I read Goran's post -which is very good-. I also found this one useful to have an idea on how audio generally works in Linux and FreeBSD -it covers more Linux than FreeBSD though-.

Goran actually kindly pointed me to the right place in FreeBSD source code where I can find some examples on how the device file /dev/dsp is opened and how to configure it via ioctl. A basic example can be found here.

I have started playing a bit with the examples -just because I am curious on interacting directly with the FreeBSD sound layer- but I still think I do not have all the documentation on how this is properly arranged.

For example, something I have noticed is that when you restart FreeBSD the /dev/dsp files are simply not there. If you load firefox and watch a video on youtube -so the system actually plays sound- then /dev/dsp0.0 appears. If I change the channel to the front jacks -I am testing with a desktop computer that has both rear and front audio connectors- with sysctl hw.snd.default_unit=1 and I open a youtube tab and play audio then /dev/dsp1.0 appears.

So it seems to me that at the application level you generate those /dev/dsp device files if they are not there, but I can not match that creation on the examples in the source code.

I wonder if somebody could either point to further documentation where this is explained or explain a bit in more detail how to create the /dev/dsp files -which is a question directly related to the post but not entirely the same-.
 
I wonder if somebody could either point to further documentation where this is explained or explain a bit in more detail how to create the /dev/dsp files -which is a question directly related to the post but not entirely the same-.
dsp devices are automatically created by kernel on use (if corresponding hardware exist). To convince you, these two simple examples

Code:
file /dev/dsp*
/dev/dsp0.0: character special (0/123)
/dev/dsp0.1: character special (0/129)
/dev/dsp1.0: character special (0/128)
/dev/dsp2.0: character special (0/130)

ls -l /dev/dsp*   
crw-rw-rw-  1 root  wheel  0x7b Jun 26 15:30 /dev/dsp0.0
crw-rw-rw-  1 root  wheel  0x81 Jun 26 15:30 /dev/dsp0.1
crw-rw-rw-  1 root  wheel  0x80 Jun 26 15:30 /dev/dsp1.0
crw-rw-rw-  1 root  wheel  0x82 Jun 26 15:30 /dev/dsp2.0


Before running either of these commands, the device nodes were not present under /dev.
 
Last edited by a moderator:
Back
Top