Re: Generation of sound
- From: Bernhard Agthe <dark2star@xxxxxxx>
- Date: Tue, 15 Dec 2009 09:11:37 +0100
I tested 'cat /dev/urandom > /dev/audio': It sounded like white noise.
It's supposed to be.
I wrote a program whose output is a sine wave table:
(At least what I thought Jasen Betts meant by this)
I executed: ./sine-wave <param1> <param2> <param3> > /dev/audio
It generates a sine-wave like sound.
Good, you're almost there.
I testet several parameter combinations and found out that the sound
changes it's frequency sometimes but I couldn't figure out why. mult
determines the duration of the sound. But freq1 and freq2 seem to have
no effect. It looks like I don't completely understand how what's
written to /dev/audio defines its sound output.
Well, the frequency isn't set in your program - basically you feed the output into /dev/audio as fast as the program generates the table - you need to do some timing. For example a short delay between outputting samples?
But then you'll get intermittent sound because the program may not wake up in time - producing a small break.
If I were you, I'd record a sound for the dot and the line into *.ogg files. Load them upon your program's startup and play them as needed. That's the technique I used for a talking calculator - just play pre-recorded samples (numbers in my case). Use the libSDL for the purpose, it has a sound section. Check out <http://www.libsdl.org/>
How can I change the pitch and the volume?
Volume should be simple, just turn the button ;-) It should be in the libSDL, really.
And about the console speaker:
You'll find that some terminals don't have a console speaker, you'll actually find the console speaker emulated via sound card... Forget about changing your console settings, but rather look into your terminal application's configuration menu, you'll find options for "console beeb", including flashing the screen instead of beep. But really, forget about using it for the morse program, rather enjoy having a real sound card. The times of listening to music on the PC speaker are long gone, thankfully...