I am using a USB-soundcard to record on my raspberry pi and it records fine and the recorded sound is great, however if I am playing any other sound clip (through the audio output port on the raspberry pi and not my USB) the recorded sound is very bad like chunks of it are not recorded. Any ideas where this problem is coming from and how to solve it? Maybe a power problem?
Their are two reasons for this, and only one is fixable.
Your Pi is not getting enough power. Make sure you have a short and thick cord, do not try to use a cheap thin and long one, like the phone charger cords. If you have a lot of usb devices plugged in, you may want to invest in a powered usb hub. Finally, the Pi needs about 2 amps to work comfortably, but the more things you have plugged in and the more work it has to do, the more amps it will need, personally, I use a 5.5V 5A power source, and my external sound card records while outputting fine.
Your external sound card may be the source of the problem. Make sure all of the connections are fine and nothing is blatantly broken. If Case 1 is not correct and you believe your sound card is working fine then you should purchase another card, just a cheap one, to make sure it is not the Pi's fault. I am using the one here: http://www.amazon.com/gp/product/B00M3UWE3Q?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00 it is only about $3 and for what I needed it works great.
Good luck to you!
I agree it's likley a lack of CPU cycles .. the Pi sound output is essentially 'bit banging' and USB is 'byte at a time' so both use a ton of CPU cycles = no doubt the Pi gives sound out priority over USB (USB can 'retry') so I would expect the recording to be the one to fail ..
The way to check is to 'over-clock' the Pi and see if the quality improves ..
A power problem is just possible (although sound out takes very little additional power) - and the fact that your USB device works perfectly when you are NOT outputting audio from the Pi proves it's working fine (although that's not to say it's USB 'loading' isn't 'excessive' and another device with a different driver might work better)