mindboards/ev3dev-kernel — pull request #11 by fdetro (2014-01-13 19:57:40+00:00)
Title: Alsa driver improvements and sysfs attributes for sound device

This patch changes the sample rate for the alsa driver to 22050 Hz. Unfortunately, I still see heavy crackling in the audio signal. The crackles disappear when changing the sample rate to 8KHz, but then the audio signal shows extreme aliasing.

I've experimented with lots of different PWM settings and Alsa driver improvements, but it looks like we are suffering from hardware limitations. Either the speaker amplifier / filter runs into distortion or the CPU / interrupt controller is not able to handle such a large number of IRQs in time (> 22050 per second only for PWM).

Regarding tone mode, I've applied the global alsa audio volume to the tone signal, too. Additionally I've added sysfs entries for the volume, triggering a tone and querying the current device mode:

# set volume to 50%
echo 50 >/sys/devices/platform/snd-legoev3/volume
cat /sys/devices/platform/snd-legoev3/volume 50

# play a 1 KHz tone for 10000 ms
echo 1000 10000 > /sys/devices/platform/snd-legoev3/tone

# query the current mode
cat /sys/devices/platform/snd-legoev3/mode
tone

# play a 440 Hz tone (endless mode)
echo 440 > /sys/devices/platform/snd-legoev3/tone

# stop the tone
echo 0 > /sys/devices/platform/snd-legoev3/tone