From the Mopidy website:
The Raspberry Pi’s audio quality can be sub-par through the analog output. This is known and unlikely to be fixed as including any higher-quality hardware would increase the cost of the board. If you experience crackling/hissing or skipping audio, you may want to try a USB sound card. Additionally, you could lower your default ALSA sampling rate to 22KHz, though this will lead to a substantial decrease in sound quality.
Many companies have recognized this issue though, and here is one that works quite well. The official forums have had a running discussion on the topic, and here is a link to one of the setup tutorials.
The instructions are below (Note: they were tested with the sound card linked in my answer):
Make the USB card the primary device. Type this in terminal.
sudo nano/etc/modprobe.d/alsa-base.conf
Made the following entries in the file
#options snd-usb-audio index=-2
options snd_bcm2835=-2
exit
reboot
Then, add the following line to the /boot/cmdline.txt
dwc_otg.speed=1
In your home directory create a ~/.libao
file in your home directory and enter the following:
driver=alsa
dev=default
Lastly create a ~/.asoundrc
in your home directory and enter the following:
Line here to make it so that I don't have to enter tons of code.
pcm.!default {
type asym
playback.pcm "defaultplayback"
capture.pcm "defaultrec"
hint{ show on
description "default play and rec koko"
}
}
pcm.defaultrec {
type plug
slave {
pcm "hw:0,0"
rate 48000
channels 2
format S16_LE
}
hint{ show on
description "default rec koko"
}
}
pcm.defaultplayback{
type rate
slave.pcm mix1
slave.rate 48000
#Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz:
#converter "samplerate_best" # perfect: 16%cpu, maybe overkill
#converter "samplerate_medium" # almost perfect: 6%cpu
#converter "samplerate" # good: 4%cpu, definitely usable
#converter "samplerate_linear" # bad: 2%cpu, way better than default wine resampler
#converter "samplerate_order" # very bad: 2%cpu, like the default wine resampler
converter "samplerate"
hint{ show on
description "default play koko"
}
}
pcm.mix1 {
type dmix
ipc_key 1024
slave {
pcm "hw:0,0"
rate 48000
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 65536
}
}