Showing posts with label audio. Show all posts
Showing posts with label audio. Show all posts

Tuesday, May 12, 2015

USB audio disconnect woes in FreeBSD with fstat: tales of a voltage-sensitive Topping TP30

I have a very nice "class T" Tripath audio amplifier: the Topping TP30 (MK I -- hopefully they fixed the MKII) with a very convenient integrated USB audio card. However, this device is VERY sensitive to line voltage. For example, when plugged into the same circuit as, say, a refrigerator, the motor spark is enough to pop the speakers and cause the device to perform a USB reset.

In the case of FreeBSD, this causes everything to come to a miserable, grinding halt. dmesg gives me repeated warnings of failure:

pcm2: unregister: mixer busy
pcm2: Waiting for sound application to exit!
pcm2: unregister: mixer busy
pcm2: Waiting for sound application to exit!
pcm2: unregister: mixer busy
pcm2: Waiting for sound application to exit!
pcm2: unregister: mixer busy
pcm2: Waiting for sound application to exit!
pcm2: unregister: channel pcm2:virtual:dsp2.vp0 busy (pid 11413)
pcm2: Waiting for sound application to exit!
pcm2: unregister: channel pcm2:virtual:dsp2.vp0 busy (pid 11413)
pcm2: Waiting for sound application to exit!
pcm2: chn_write(): pcm2:virtual:dsp2.vp0: play interrupt timeout, channel dead

Before I realized that fstat worked on character devices, I had to manually fish around for processes to kill, in order to give the USB audio subsystem the breathing room required for it to reset the audio device. Interestingly enough: if a process that was holding onto the mixer releases the corresponding /dev/mixer device, but then restarts quickly enough and grabs control of the (now defunct) mixer, the sound card still won't reset.

Below, find the one-liner script that goes out and kills every process that holds the audio devices open. I have to execute this twice in a row to kill off XFCE's mixer process until the USB audio card has time to fully reset:

fstat /dev/dsp* /dev/mixer* /dev/audio* | tail -n +2 | awk '{print $3}' | xargs sh -c 'sudo kill -9 $0 $*'

Thursday, January 23, 2014

No monitor device on USB sound card? No problem.

My USB sound card doesn't have a "monitor" mixer device. In other words, in order to listen to audio that is being recorded through my speakers or headphones, I need to record and play back that audio.

PulseAudio makes this somewhat easy using module-loopback, although the method is esoteric, so here are the applicable commands.

In order to figure out what input and output devices to use,
pactl list | grep -1 State
You should see a number of sources and sinks. The key piece of information is the Name: field, which allows us to specify which device to use in the loopback chain.

In my case, my source device is oss_input.dsp2, and my sink device is oss_output.dsp2. Therefore, I can load the appropriate module:

pactl load-module module-loopback source="oss_input.dsp2" sink="oss_output.dsp2" latency_msec=1
An ID number, corresponding to the module ID, is returned on the command line. When you want to unload the loopback module, supply this argument to This is the argument to pactl unload-module

There is a bit of latency using this method, but at least I don't have to involve a hardware mixer in my set-up.