KingNai
Posts: 3
Joined: Thu Mar 21, 2013 8:34 am

[SOLVED] ALSA/C-Media USB sound card issues

Thu Mar 21, 2013 8:42 am

Solution:
Okay, so this device wouldn't work for me: http://www.amazon.com/dp/B001MSS6CS/ref ... tringer-20

After a lot of trouble shooting, I found the issue. ALSA requires specific settings for each device. This specific device requires the format to be signed 16-bit little endian. of -f S16_LE.

First the setup: I have the USB adapter plugged directly into the pi for the least static. I have my config setup as observing states in #1 http://www.raspberrypi.org/phpBB3/viewt ... 11#p314611

Then I had to run alsamixer and set my mic volume to about 50. Anything lower seems to not pick up and much high maxes out the card(hit F5 to see the capture device) and run:

Code: Select all

sudo alsactl store
To save the settings or else it reverted back to 100% mic, which ended up recording nothing.

Then to use arecord with the setting -D plughw:0. Why? Well, using the plug interface seems to autoconfig the device as needed. This device seems to require specific setting, the S16_LE part. plughw set that for me.

And here is my full command:

Code: Select all

arecord -D plughw:0 -r 16000 test.wav
Original:
I cannot for the life of me get arecord to actually record audio with a C-Media USB adapter. The recorded sound is either static or completely silent. I know the mic works because when I turn on the mic playback in alsamixer I can hear everything just fine and it actually is really good quality.

I have set up the USB device as hw0

I've tried this and many variations of it. It complains without the -f S16_LE

Code: Select all

arecord -f S16_LE -D hw:0,0 -r 48000 test.wav
It records without complaining

And when I run it through aplay, it's full of static or completely silent.

Does anyone see what I'm missing? Or has anyone gotten it to work?

Thanks,
Ian
Last edited by KingNai on Sat Mar 23, 2013 7:17 am, edited 2 times in total.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm

Re: ALSA/C-Media USB sound card issues

Thu Mar 21, 2013 11:44 am

What is the output of:

Code: Select all

cat /proc/asound/cards
lsusb
I have a C-Media sound card too and that one works ok:

Code: Select all

cat /proc/asound/cards 
 0 [Device         ]: USB-Audio - Generic USB Audio Device
                      Generic USB Audio Device at usb-bcm2708_usb-1.2.1, full speed
...

lsusb
Bus 001 Device 005: ID 0d8c:000e C-Media Electronics, Inc. Audio Adapter (Planet UP-100, Genius G-Talk)
I did set dwc_otg.speed=1 in /boot/cmdline.txt though. More info here: http://wiki.linuxaudio.org/wiki/raspberrypi

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/

observing
Posts: 52
Joined: Mon Feb 27, 2012 12:18 pm

Re: ALSA/C-Media USB sound card issues

Thu Mar 21, 2013 1:26 pm

I also use a C-Media adapter. What I did was:
1. To configure the adapter to be card 0, I changed the following line in /etc/modprobe.d/alsa-base.conf from
options snd-usb-audio index=-2
to
options snd-usb-audio index=0

2. With /proc/asound/cards now showing the adapter as the default (card 0), I'm able to record audio from the mic input with "arecord -d 5 -r 48000 test.wav" and play it back through the headset output with "aplay test.wav." I used alsamixer to adjust the Speaker output level and the Capture input level.

I find it strange that you get errors when you don't include "-f S16_LE." You didn't say what the error message was, but I have been using the default format (U8) without any issue. I can tell you that there are some formats, which alsa claims my adapter (SYBA SD-CM-UAUD) supports, which it clearly doesn't.

KingNai
Posts: 3
Joined: Thu Mar 21, 2013 8:34 am

Re: ALSA/C-Media USB sound card issues

Fri Mar 22, 2013 6:17 am

Alrighty so:

Code: Select all

cat /proc/asound/cards 
 0 [Device         ]: USB-Audio - C-Media USB Audio Device
                      C-Media USB Audio Device at usb-bcm2708_usb-1.3, full speed

lsusb
Bus 001 Device 007: ID 0d8c:000e C-Media Electronics, Inc.
I have my speed set to 1 in cmdline.txt

It now records fine without S16_LE but the audio is completely silent.

I think I'll try a re-install of Raspian and see how that works. Are you using soft-float or hard-float?

I was trying to set this up: https://sites.google.com/site/observing ... spberry-pi

This is the device I have: http://www.amazon.com/dp/B001MSS6CS/ref ... tringer-20

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm

Re: ALSA/C-Media USB sound card issues

Fri Mar 22, 2013 9:42 am

KingNai wrote:Alrighty so:

Code: Select all

cat /proc/asound/cards 
 0 [Device         ]: USB-Audio - C-Media USB Audio Device
                      C-Media USB Audio Device at usb-bcm2708_usb-1.3, full speed

lsusb
Bus 001 Device 007: ID 0d8c:000e C-Media Electronics, Inc.
Thanks, it's exactly the same interface I'm using so it should work.
KingNai wrote:It now records fine without S16_LE but the audio is completely silent.
You mean the recorded audio or the audio output?
KingNai wrote:I think I'll try a re-install of Raspian and see how that works.
That won't help troubleshooting this issue.
KingNai wrote:Are you using soft-float or hard-float?
Hard-float. There is no soft-float Raspbian.
KingNai wrote:This is the device I have: http://www.amazon.com/dp/B001MSS6CS/ref ... tringer-20
I have a similar device: http://dx.com/p/virtual-5-1-surround-us ... card-22475
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/

KingNai
Posts: 3
Joined: Thu Mar 21, 2013 8:34 am

Re: ALSA/C-Media USB sound card issues

Sat Mar 23, 2013 7:05 am

I have finally gotten it to work! It works with or without speed = 1.

To make it work I had to run:
arecord -D plughw:0 -r 48000 test.wav
Along with messing with alsamixer and forcing it to save my settings using alsactl store.

It was a lot of work, but it has been resolved. Editing main post.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm

Re: [SOLVED] ALSA/C-Media USB sound card issues

Sat Mar 23, 2013 1:45 pm

Ok cool! And good to know it also works without forcing the USB controller to USB1.1 mode. Have fun, even though these little USB sound cards are dead cheap they function quite well.
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/

lfchords
Posts: 13
Joined: Thu Mar 21, 2013 2:28 am

Re: [SOLVED] ALSA/C-Media USB sound card issues

Mon Apr 08, 2013 12:44 am

Hi there,

I've been racking my brain for a few days now trying to figure this out. I can only get recordings with static and pops..

I have a Rev 2 Pi, powered by a 1.5A adapter into Mains, and a powered Belkin USB hub with a 2.6A adapter.
A SYBA Cmedia card plugged into the Belkin hub.

My asoundrc is:

Code: Select all

pi@raspberrypi ~ $ cat ~/.asoundrc 
pcm.!default {
    type plug
    slave {
        pcm rate48000Hz # Direct default output to the below converter
    }
}
pcm.rate48000Hz {
    type rate
    slave {
        pcm writeFile # Direct to the plugin which will write to a file
        format S16_LE
    #    channels 2
        rate 48000
    }
    #route_policy copy
}

pcm.writeFile {
    type file
    slave {
        pcm card0 # Now write to the actual sound card
    }
    file "aplay-D_card0-t_raw-f_S16_LE-r48000-c_2.raw"
    format "raw"
}

pcm.card0 {
    type hw
    card 0
}

ctl.card0 {
    type hw
    card 0
}

Recording with these commands :

Code: Select all

pi@raspberrypi ~ $ arecord -vv -f S16_LE -D plughw:0,0 -r 48000 test2.wav
Recording WAVE 'test2.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Plug PCM: Hardware PCM card 0 'C-Media USB Audio Device' device 0 subdevice 0
Its setup is:
  stream       : CAPTURE
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 1
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 24000
  period_size  : 6000
  period_time  : 125000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 6000
  period_event : 0
  start_threshold  : 1
  stop_threshold   : 24000
  silence_threshold: 0
  silence_size : 0
  boundary     : 1572864000
  appl_ptr     : 0
  hw_ptr       : 0
##  +                                              | 06%^C
Gives me :
https://docs.google.com/file/d/0B4zhzWw ... sp=sharing


I tried, with no luck:
- different ports on my hub
- the SYBA USB directly on the Pi USB
- recording at 44.1 or 48khz - same results
- doing the 1.1 speed cmdline.txt. . this crashed my Pi, so I had to boot to safe mode and remove.. but later read it doesnt really matter at this point
- tried editing the asound.rc and changing everything to 44.1 vs 48 and rebooting

I dont have a scope, to try

User r4049zt posts here
http://www.raspberrypi.org/phpBB3/viewt ... 31#p129631
about grounding the Pi, I dont have a scope, and not sure I understand what I need to do to a) confirm this is what's causing the noise, or b) to remedy...


I'm tempted to try PulseAudio, via this post :
http://dbader.org/blog/crackle-free-aud ... pulseaudio

but I feel very close.... anyone have ideas? have I missed something?

much appreciated
-s

avidhills
Posts: 1
Joined: Tue Feb 11, 2014 11:36 am

Re: [SOLVED] ALSA/C-Media USB sound card issues

Tue Feb 11, 2014 11:53 am

Hi,
We're trying to record audio using the

Code: Select all

arecord
function with an external USB audio interface. We're getting sound but keep ending up with crackles and pops at the peaks of the audio waves. Did you try using any additional software in the end?

Thanks
A

NorahOmar
Posts: 3
Joined: Mon Mar 03, 2014 7:32 pm

Re: [SOLVED] ALSA/C-Media USB sound card issues

Mon May 05, 2014 3:32 pm

Does anybody know how can I record using the USB soundcard but play through the raspi default audio output port? Thanks

loophie
Posts: 4
Joined: Wed Mar 12, 2014 7:20 pm

Re: [SOLVED] ALSA/C-Media USB sound card issues

Thu Jun 05, 2014 5:55 pm

hi, I have same problem with USB soundcard. i have DSP project using simulink and run it in Raspberry Pi.
when I playback the audio sound, it work properly. But, when I combine with audio capture, the noise is interupting the sound from mic. I use Raspbian 2013-09-25-wheezy-raspbian. My project run in the Raspberry Pi without ethernet activy. is there anyone know about my problem?
thanks..

justin522
Posts: 1
Joined: Mon Sep 15, 2014 8:07 am

Another possible solution

Mon Sep 15, 2014 8:20 am

I was having very similar issues, and found that if I didn't push the mic all the way into the jack, but left it a couple of millimeters out it worked without any hassle.

akopac
Posts: 13
Joined: Sun Oct 19, 2014 7:58 pm

Re: [SOLVED] ALSA/C-Media USB sound card issues

Mon Dec 28, 2015 5:10 am

In case anyone comes to this on a google, I had problems with this on recent versions of raspbian (Jessie), where there is a file called aliases.conf in /lib/modprobe.d which contains the line options snd-usb-audio index=-2 and overrides the etc/modprobe.d/ files, so you need to change that one. Comment out with a # the line “options snd-usb-audio index=-2”

In /usr/share/alsa/alsa.conf I un-commented “load card-specific configuration files (on request)” and I also replaced the content of .asoundrc which is a hidden file in your home folder with:
pcm.!default plughw:Device
ctl.!default plughw:Device
You will have to use Alsa mixer, the application you are usings volume control, or the physical sound level buttons on the USB sound dongle for sound control.
Removing the
References for this at: viewtopic.php?f=28&t=124016&p=857433&hi ... io#p857433 andhttp://alsa.opensrc.org/Asoundrc#Default_PCM_device.

disheet
Posts: 1
Joined: Fri Mar 17, 2017 11:39 am

Re: [SOLVED] ALSA/C-Media USB sound card issues

Fri Mar 17, 2017 11:42 am

bydefault alexa taking 16000Hz,S16_LE format but my mic is recording in 8000Hz,U8 format so how to equal it???or how to change mic bitrate and format?

caller9
Posts: 1
Joined: Thu Aug 27, 2020 2:31 am

Re: [SOLVED] ALSA/C-Media USB sound card issues

Thu Aug 27, 2020 2:53 am

This is super old, but one of the top results for me. I ran into this and none of the above fixed it. I did the modification to comment out
#options snd-usb-audio index=-2
in /lib/modprobe.d/aliases.conf which did set the card index to 0. No effect on recording.

Then I stumbled across amixer.

Code: Select all

amixer get "PCM Capture Source"
Simple mixer control 'PCM Capture Source',0
  Capabilities: enum
  Items: 'Mic' 'Line' 'IEC958 In' 'Mixer'
  Item0: 'Mic'
No amount of fiddling with alsamixer mattered, but by setting the PCM capture source it now works great.

Code: Select all

amixer set "PCM Capture Source" "Line"
sudo alsactl store
arecord -V stereo -D hw:0,0 -d 10 -f S16_LE -c 2 -r 48000 -vv test.wav
It works for me now.

Return to “Graphics, sound and multimedia”