# How can I record audio?



## myshkin (Dec 30, 2019)

I have tried to record audio in many different ways. I have tried recording with obs-studio, simplescreenrecorder, and via ffmpeg. None of these methods work. Usually I tried to record from /dev/dsp3 but I also tried to record from /dev/dsp4 and all other outputs, but nothing works. Playing sound works very well, it even sounds better than on macos, windows and linux (alsa). So it's only with recording that I have a problem.


mixer 

```
Mixer vol      is currently set to 100:100
Mixer pcm      is currently set to 100:100
Mixer speaker  is currently set to 100:100
Mixer line     is currently set to   0:0
Mixer mic      is currently set to   0:0
Mixer mix      is currently set to   0:0
Mixer rec      is currently set to 100:100
Mixer igain    is currently set to 100:100
Mixer ogain    is currently set to 100:100
Recording source: speaker
```


dmesg | egrep "hda|pcm"

```
hdac0: <NVIDIA (0x0fb9) HDA Controller> mem 0xf7080000-0xf7083fff irq 17 at device 0.1 on pci1
hdac1: <Intel Cougar Point HDA Controller> mem 0xf7800000-0xf7803fff irq 22 at device 27.0 on pci0
hdacc0: <NVIDIA (0x0080) HDA CODEC> at cad 0 on hdac0
hdaa0: <NVIDIA (0x0080) Audio Function Group> at nid 1 on hdacc0
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 4 on hdaa0
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 6 on hdaa0
hdacc1: <Realtek ALC887 HDA CODEC> at cad 0 on hdac1
hdaa1: <Realtek ALC887 Audio Function Group> at nid 1 on hdacc1
pcm3: <Realtek ALC887 (Rear Analog)> at nid 20 and 24,26 on hdaa1
pcm4: <Realtek ALC887 (Front Analog)> at nid 27 and 25 on hdaa1
hdac0: <NVIDIA (0x0fb9) HDA Controller> mem 0xf7080000-0xf7083fff irq 17 at device 0.1 on pci1
hdac1: <Intel Cougar Point HDA Controller> mem 0xf7800000-0xf7803fff irq 22 at device 27.0 on pci0
hdacc0: <NVIDIA (0x0080) HDA CODEC> at cad 0 on hdac0
hdaa0: <NVIDIA (0x0080) Audio Function Group> at nid 1 on hdacc0
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 4 on hdaa0
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 6 on hdaa0
hdacc1: <Realtek ALC887 HDA CODEC> at cad 0 on hdac1
hdaa1: <Realtek ALC887 Audio Function Group> at nid 1 on hdacc1
pcm3: <Realtek ALC887 (Rear Analog)> at nid 20 and 24,26 on hdaa1
pcm4: <Realtek ALC887 (Front Analog)> at nid 27 and 25 on hdaa1
hdac0: <NVIDIA (0x0fb9) HDA Controller> mem 0xf7080000-0xf7083fff irq 17 at device 0.1 on pci1
hdac1: <Intel Cougar Point HDA Controller> mem 0xf7800000-0xf7803fff irq 22 at device 27.0 on pci0
hdacc0: <NVIDIA (0x0080) HDA CODEC> at cad 0 on hdac0
hdaa0: <NVIDIA (0x0080) Audio Function Group> at nid 1 on hdacc0
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 4 on hdaa0
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 6 on hdaa0
hdacc1: <Realtek ALC887 HDA CODEC> at cad 0 on hdac1
hdaa1: <Realtek ALC887 Audio Function Group> at nid 1 on hdacc1
pcm3: <Realtek ALC887 (Rear Analog)> at nid 20 and 24,26 on hdaa1
pcm4: <Realtek ALC887 (Front Analog)> at nid 27 and 25 on hdaa1
hdac0: <NVIDIA (0x0fb9) HDA Controller> mem 0xf7080000-0xf7083fff irq 17 at device 0.1 on pci1
hdac1: <Intel Cougar Point HDA Controller> mem 0xf7800000-0xf7803fff irq 22 at device 27.0 on pci0
hdacc0: <NVIDIA (0x0080) HDA CODEC> at cad 0 on hdac0
hdaa0: <NVIDIA (0x0080) Audio Function Group> at nid 1 on hdacc0
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 4 on hdaa0
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 6 on hdaa0
hdacc1: <Realtek ALC887 HDA CODEC> at cad 0 on hdac1
hdaa1: <Realtek ALC887 Audio Function Group> at nid 1 on hdacc1
pcm3: <Realtek ALC887 (Rear Analog)> at nid 20 and 24,26 on hdaa1
pcm4: <Realtek ALC887 (Front Analog)> at nid 27 and 25 on hdaa1
hdac0: <NVIDIA (0x0fb9) HDA Controller> mem 0xf7080000-0xf7083fff irq 17 at device 0.1 on pci1
hdac1: <Intel Cougar Point HDA Controller> mem 0xf7800000-0xf7803fff irq 22 at device 27.0 on pci0
hdacc0: <NVIDIA (0x0080) HDA CODEC> at cad 0 on hdac0
hdaa0: <NVIDIA (0x0080) Audio Function Group> at nid 1 on hdacc0
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 4 on hdaa0
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 6 on hdaa0
hdacc1: <Realtek ALC887 HDA CODEC> at cad 0 on hdac1
hdaa1: <Realtek ALC887 Audio Function Group> at nid 1 on hdacc1
pcm3: <Realtek ALC887 (Rear Analog)> at nid 20 and 24,26 on hdaa1
pcm4: <Realtek ALC887 (Front Analog)> at nid 27 and 25 on hdaa1
hdac0: <NVIDIA (0x0fb9) HDA Controller> mem 0xf7080000-0xf7083fff irq 17 at device 0.1 on pci1
hdac1: <Intel Cougar Point HDA Controller> mem 0xf7800000-0xf7803fff irq 22 at device 27.0 on pci0
hdacc0: <NVIDIA (0x0080) HDA CODEC> at cad 0 on hdac0
hdaa0: <NVIDIA (0x0080) Audio Function Group> at nid 1 on hdacc0
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 4 on hdaa0
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 5 on hdaa0
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> at nid 6 on hdaa0
hdacc1: <Realtek ALC887 HDA CODEC> at cad 0 on hdac1
hdaa1: <Realtek ALC887 Audio Function Group> at nid 1 on hdacc1
pcm3: <Realtek ALC887 (Rear Analog)> at nid 20 and 24,26 on hdaa1
pcm4: <Realtek ALC887 (Front Analog)> at nid 27 and 25 on hdaa1
```


cat /dev/sndstat

```
Installed devices:
pcm0: <NVIDIA (0x0080) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x0080) (HDMI/DP 8ch)> (play)
pcm2: <NVIDIA (0x0080) (HDMI/DP 8ch)> (play)
pcm3: <Realtek ALC887 (Rear Analog)> (play/rec) default
pcm4: <Realtek ALC887 (Front Analog)> (play/rec)
No devices installed from userspace.
```

Any help would be greatly appreciated.


----------



## obsigna (Dec 31, 2019)

In case you got a microphone pluged into the pink Mic rear connector for recording, do:

`mixer mic 67:67`
`ffmpeg -thread_queue_size 1024 -f oss -i /dev/dsp3 test.m4a`

In case you got a audio device plugged into the blue Line-in rear connector for recording, do:
`mixer line 67:67`
`ffmpeg -thread_queue_size 1024 -f oss -i /dev/dsp3 test.m4a`


----------



## myshkin (Dec 31, 2019)

obsigna said:


> In case you got a microphone pluged into the pink Mic rear connector for recording, do:
> 
> `mixer mic 67:67`
> `ffmpeg -thread_queue_size 1024 -f oss -i /dev/dsp3 test.m4a`
> ...



In principle, nothing is connected to the blue and pink connections. My speakers are connected to the green connection.

I have followed your instructions and connected my micro to the pink connection, but it has recorded an audio file with no audio, although cmus played music. This was the output of the command: https://i.imgur.com/2omOad1.png


----------



## PMc (Jan 4, 2020)

Long long ago I found a port named audio/xwave, which was tested to be basically able to do recording. That was not pursued further, and the port is now very outdated.
Then, recently I found a port called ardour, which actually appears to dwarf my 11" openreel machine and seems to almost play in the realm of the Digidesign desks... thats now postponed for study when I'm in the mood... It doesn't make things easier, it built upon just another layer of indirection.

There  are two basic layers: 
1. the "nid" stuff, done in /boot/device.hints. That configures the wiring between the physical plugs and the audio chip(s). There is a color code for the meaning of the physical plugs, but that doesn't mean much, because the wiring on the board can be arbitrarily changed.
2. The "dsp" stuff, controlled with the mixer command(s). That seems to control what the dsp(s) do with the signals. The mixer(8) command has switches to select which source to use for recording, see the rec and recsrc option.

Both may be more or less hardware dependent. Both are not perfectly good documented. It can be quite a session to systematically figure out what might work.


----------



## shkhln (Jan 4, 2020)

What's the exact use case?

OSS doesn't allow output capture. You need to either use a physical loop or try your luck with virtual_oss, which effectively emulates dsp devices in userspace.


----------



## Kiiski (Jan 4, 2020)

Sometime ago in similar situation I used exmples from snd_hda() to get correct configuration.
If you have not yet looked at those, they might give some help.


----------



## sidetone (Jan 4, 2020)

audio/audacity is made for recording, but if other applications don't work, this may have the same issues. I'm not certain if audio/sox can record from the command line.
As others have mentioned, your `mixer`: mic, record or igain, settings need to be higher than 0, for it to record. Igain usually works at a setting of 1, while other variables need to be much higher. You may also have to use the microphone input in the back.


```
No devices installed from userspace.
```
 I've seen this warning before, but don't remember about it. Installing something from ports seems to fix it, that gets installed with larger applications.


----------



## myshkin (Jan 12, 2020)

shkhln said:


> What's the exact use case?



Suppose I want to record both what I see on my screen and the audio that is played on my speakers. Simplescreenrecorder can normally do this, but on FreeBSD I am unable to record the audio played on my speakers in a file. The file being recorded has only video, not audio.



Kiiski said:


> Sometime ago in similar situation I used exmples from snd_hda() to get correct configuration.
> If you have not yet looked at those, they might give some help.


I also think that there may be the solution. By changing these types of settings: hint.hdac.0.cad0.nid21.config="as=2"
But I do not understand how it works.


sidetone said:


> I'm not certain if audio/sox can record from the command line.
> As others have mentioned, your `mixer`: mic, record or igain, settings need to be higher than 0, for it to record. Igain usually works at a setting of 1, while other variables need to be much higher. You may also have to use the microphone input in the back.


I don't think my mixer settings are the problem.
I tried to record with sox via this command: sox -c 2 -r 32000 -t ossdsp /dev/dsp3 -t ossdsp -r 32000 /dev/dsp3 
And then I get this output:

```
/dev/dsp3: (ossdsp)
 File Size: 0         
  Encoding: Signed PCM   
  Channels: 2 @ 16-bit   
Samplerate: 32000Hz     
Replaygain: off         
  Duration: unknown     
In:0.00% 00:03:14.05 [00:00:00.00] Out:6.21M [      |      ]        Clip:0
```
The ascending megabyte indication gives the impression that the sound is being recorded to a file but I cannot find this file anywhere.


----------

