Audio input waveform distortion on some USB sound cards


14 posts
by aaknitt » Sat Feb 02, 2013 4:40 am
Hi everyone,
I'm using a Pi for audio processing and have found that some USB sound cards appear to have abrupt phase changes in the waveform. When I tried a common ebay $7 sound card like this:

Image

I got waveform distortion that looked like this when recording a single tone:

Link to larger version of picture
Image

Note the phase changes every 30 ms highlighted in yellow. These phase changes aren't terribly noticeable when recording voice, but they wreak havoc on tone detection algorithms. When I use a more expensive Sound Blaster X-Fi USB sound card I don't seem to have this issue.

Any ideas on how to make the audio input on a cheap USB sound card work? I get similar results regardless of whether I use ALSA or pulseaudio for recording, and I get the same result with different recording software.

Thanks,

Andy
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm
by Paul Webster » Sat Feb 02, 2013 6:24 am
Have you eliminated the RPi as part of the problem?
E.g. Perform same test with the device plugged into a desktop/laptop
User avatar
Posts: 669
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
by Burngate » Sat Feb 02, 2013 12:29 pm
Maybe I'm wrong, I'm no expert, but those don't look to me like phase changes - they look like missing data, about half a cycle's worth.

We know that Linux isn't very good in real time
And we know there are still unresolved problems with the USB and dropped packets
User avatar
Posts: 4826
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
by redhawk » Sat Feb 02, 2013 1:18 pm
I seem to recall someone else had this issue when recording in 48kHz mode because of missing samples, 44.1kHz was more stable.
There is also a trick to force the USB drivers to run in 1.1 compatible mode by appending dwc_otg.speed=1 to /boot/cmdline.txt perhaps that might help too.
If that doesn't help try and "nice" your recording application make it run with a higher priority that other processes.

Richard S.
User avatar
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1
by aaknitt » Sat Feb 02, 2013 1:31 pm
Paul Webster wrote:Have you eliminated the RPi as part of the problem?
E.g. Perform same test with the device plugged into a desktop/laptop


Yes the same sound card works fine under Windows for recording.
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm
by aaknitt » Sat Feb 02, 2013 1:33 pm
Burngate wrote:Maybe I'm wrong, I'm no expert, but those don't look to me like phase changes - they look like missing data, about half a cycle's worth.

We know that Linux isn't very good in real time
And we know there are still unresolved problems with the USB and dropped packets


I agree...I think it is missing data, which in the case of a pure sine wave manifests itself as phase changes.

Andy
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm
by aaknitt » Sat Feb 02, 2013 1:34 pm
redhawk wrote:I seem to recall someone else had this issue when recording in 48kHz mode because of missing samples, 44.1kHz was more stable.
There is also a trick to force the USB drivers to run in 1.1 compatible mode by appending dwc_otg.speed=1 to /boot/cmdline.txt perhaps that might help too.
If that doesn't help try and "nice" your recording application make it run with a higher priority that other processes.

Richard S.


I've tried multiple sampling rates through pulseaudio with similar results. When using ALSA I can only use a single sampling rate or I get a "sampling rate not supported" error.

I tried forcing USB to 1.1 but then my keyboard and mouse stopped working...tried a couple different keyboards with the same result.

Andy
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm
by aaknitt » Sat Feb 16, 2013 3:08 pm
Well now I'm having the same issue with the more expensive Sound Blaster X-Fi USB that had been working. I didn't change anything, but all of a sudden it's developed the same lost data issue. Any thoughts on how to fix this? It's a major problem for my application.

Thanks,

Andy
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm
by akavir » Sun Feb 17, 2013 3:00 am
In my experience with the pi(haven't used audacity which, from your screen, you appear to be using), but I have gotten JACK and Ardour working....Mostly. I was actually able to capture 4 ins of audio from my lexicon Omega. I just hooked up 2 mp3 players and played random songs. I also did a full minute of recording nothing but open line noise with all input gains maxed and nothing plugged to inputs. I get some general distortion in the recording of mp3. In the test of open inputs/no plugs, I noticed a multitude of cpu dropouts(I'm guessing because it never triggered a buffer underrun in JACK) any time I click on anything while recording. I've got a long way to go on a mini studio project I'm trying to build into a 1 RU audio rackmount computer. The Rpi seems an uphill battle at this point, but new inovations are making things easier every day. As long as all of us with similar projects share our findings, we can really help each other accomplish our own goals!

P.S.[seriously, you're asking why you're having recording issues with a $7 audio card? I'll let you know when I get my $150+$300 interfaces that work out of the box in every x86/x64 linux system.]
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am
by aaknitt » Mon Feb 18, 2013 9:22 pm
I'd be interested to know how the high-dollar sound cards work. I don't think the issue is the sound card, since it works fine on other systems and I have the same problem (to different degrees) with different sound cards. I think I need to find a USB1.1 keyboard and mouse so that I can try USB1.1 instead of 2.0 and see if that helps.

Andy
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm
by AutoStatic » Tue Feb 19, 2013 9:00 am
http://wiki.linuxaudio.org/wiki/raspberrypi
Maybe it contains some useful information that applies to your usercase.

Jeremy
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/
User avatar
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
by ski522 » Tue Feb 19, 2013 3:39 pm
I had to add "nrpacks=1" to the alsa-base.conf file under /etc/modprobe.d which improved the sound on my card. Not sure if that's the problem others are having here, but thought I'd through it out.
Code: Select all
options snd-usb-audio index=0 nrpacks=1

http://alsa.opensrc.org/Usb-audio and look for
Tuning USB devices for minimal latencies
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm
by AutoStatic » Wed Feb 20, 2013 8:46 am
ski522 wrote:I had to add "nrpacks=1" to the alsa-base.conf file under /etc/modprobe.d which improved the sound on my card. Not sure if that's the problem others are having here, but thought I'd through it out.
Code: Select all
options snd-usb-audio index=0 nrpacks=1

http://alsa.opensrc.org/Usb-audio and look for
Tuning USB devices for minimal latencies
Thanks, looked that up already. Lowering the nrpacks value could allow you to use lower latencies with your USB interface. Raising the value could apparently improve the sound quality (if I have to believe numerous audiophile sites). I've played around with some values and in my case it doesn't change anything. I can't achieve lower latencies with lower values and my interface doesn't sound better with higher values.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/
User avatar
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
by aaknitt » Sun Feb 24, 2013 3:46 am
Just as a followup, adding
Code: Select all
dwc_otg.speed=1
to /boot/cmdline.txt seemed to get things working properly with the cheap USB sound card, but the more expensive sound card won't work at all with this setting. I also had to SSH into the Pi to get things going since my keyboard and mouse won't work either with that setting.

Andy
Posts: 17
Joined: Sun Jan 20, 2013 5:14 pm