Hi!
I improved the pwmsound-example that was part
of the pwmdemos. Now it is called pcmsound,
since we are dealing with sound (PCM = Pulse Code
Modulation) :-)
The improvents are:
o using ulaw-decoding for a better sound quality
o volume can now be controlled by a second fifo
It shouldn't be too complicate to do a full sound driver,
so that you can even play games or hear to mp3-files
using xmms :-)
Ok, soundcards are so cheap and are giving you a much
better sound quality, but my motivation for doing this
would be to have a rather impressive demonstration for
what is possible with RTL (RTAI as well, of course) -
next CeBIT is comming soon :-)
Download:
Bernhard
Syntax:
insmod pcmsound.o [soundfifo=<number-of-soundfifo>] [\
period=<period-in-nanoseconds>] [\
oversampling=<oversampling>] [\
gain=<gain>] [\
gainfifo=<number-of-gainfifo>]
Decription:
This demo was inspired by the original "rtl-sound demo"
from Michael Barabanov, but instead of just
altnating the level of the PC-speaker according
to positive or negative waves (aka 1-Bit DA-Converter),
here we do an oversampled pulse width modulation.
As a PC-Speaker acts like a low pass filter, the
disturbing base-frequence will be unhearble.
Therory of operation:
The sound data will not only be converted to "0" or "1"
every period like it is in the original example, but
into a pulse width modulated signal (PWM):
value t_off t_on
====================
-127 100.0% 0.0%
-126 99.6% 0.4%
... ... ...
-1 50.4% 49.6%
0 50.0% 50.0%
1 49.6% 50.4%
... ... ...
+126 0.4% 99.6%
+127 0.0% 100.0%
Consequently, sound quality is (or at least: should be)
much better, maybe comparible to a DAC with 8Khz and
6 Bit - but your mealage may vary :-)
Note: with a beeper, the sound is rather bad, since
it doesn't act as a low-pass filter like a real speaker.
Installation:
Put your "rtl.mk"-file into this directory and type "make".
Then, insmod the new module and send some *.au-files
to /dev/rtf0, like you would do it with the original
PC-Speaker sound example included in RTL2.0:
cat linux.au > /dev/rtf0
BTW: "linux.au" has rather bad quality ... so try some more files
to recognice the accustical difference between /dev/audio and
/dev/rtf0 (both, (RTL2.0-)sound.o and pwmsound.o).
Be sure that you have write access to the fifo.
Before sending a *.au-file to a fifo, check if it is
in ulaw, 8KHz, mono format with "play" (is part of the
sox-package): play -V <soundfile.au>
Controling Volume:
do a
echo -ne "\040" > /dev/rtf1 # or selected gainfifo
to change the volume "\010" is nominal.
--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/