On Wed, 25 Jun 2008 04:40:50 -0700, Tim_Mac <ti*****@gmail.comwrote:
i'm trying to create a WAV file using c# that will contain a set of
beep tones, which are only known at run time. It is a bit like morse
code except that each tone will correspond to an alphanumeric
character.
How is that different from Morse code? By "tone" do you mean frequency?
[...]
i've looked at DTMF but i'm looking for something with a complete
'alphabet' of sounds, not just the digit tones. i'm expecting to
define my own alphabet of tones, but have no idea where to start.
if someone could give me a few pointers i'd be really grateful.
It's hard to know exactly what you're asking to do. Are you having
trouble with the WAV file format itself? Or are you having trouble with
ideas for how to build a specific WAV file? In what way is your question
related to C# and/or .NET?
As far as some general answers go...
Writing a tone generator is reasonably simple, especially for sine waves.
Just output the appropriate samples based on time, using a sine function.
I think Math.Sin() is probably fast enough on modern PCs, but I suppose
for performance reasons you might want to build a table at the sampling
rate you plan to use that represents a single period of the wave, and then
just copy values from the table.
If you have just one frequency, you'd need only one table. If you wanted
to apply the same logic to other frequencies, you'd interpolate. For best
results, you'd probably want more than one table, representing tones no
more than an octave or two apart (note that each table will be of a
different length if you are making them just one period of the wave). For
frequencies not represented exactly by a given table, you'd pick the
nearest table for interpolation purposes.
You _could_ create "an alphabet of tones", I suppose. But it seems to me
that generating them on the fly should be fast enough and probably simpler
and more flexible an approach. If you've got code to generate them on the
fly, then you're halfway to a full-fledged synthesizer. :)
Then you're left writing the data to a file. For that, you simply need to
read up on the WAV file format.
Note that if you can use DirectMusic (either from unmanaged code, or using
p/invoke from C#), this might be a lot easier. It has synthesis features
built right into it and if I recall correctly can generate WAV data as
well.
Pete