472,989 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

how to create a WAV file of different tones?

hi,
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. I've searched around the newsgroups and google and most of
what i found was about using Win32 functions to perform system beeps,
but i want to create a WAV file containing the beeps, not beep out
through the system speaker.
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.
tim
Jun 27 '08 #1
2 4391
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
Jun 27 '08 #2
hi Pete. thanks for your very informative reply.
i meant 'tone' in the general sense like a 'ring tone', technically it
should be that each letter/digit translates to a different frequency.
in terms of an alphabet, i only mean having a pre-defined mapping of
frequencies to letters/digits, that can be encoded by a server into
WAV and decoded by a client hearing the file played back. just like
the way DTMF tones are used to communicate through an automated phone
system. although the application is speaker/microphone based instead
of using any cabled medium.
the question is related to c# because .Net is the platform the
application is being developed in. in the absence of a .Net sound
newsgroup, i picked c# as a best bet. i gather the APIs in the .Net
framework don't do any sound creation or manipulation, so in that
sense you're right it isn't much to do with c#. although since there
is a Win32 function to emit a beep at a specified frequency and
duration, i thought it would not be too much to hope that a similar
function would be available (somewhere) that would output the sound to
a file rather than the outputting directly through PC sound-card or
speaker.
DirectMusic looks like exactly what i was hoping for... i'll probably
end up writing a library that could work something like this:

public void Encode(string code, string filename)
{
using(MemoryStream ms = new MemoryStream())
{
foreach(char c in code.ToCharArray())
ms.Write(TranslateCharToAudio(c));
}
writeStreamToDiskInWavFormat(filename) etc
}

thanks for pointing me in the right direction.
tim.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: nemokid | last post by:
hi all, i need to write an application that listen for DTMF tones from standard audio input (from the mic) and execute an action depending on the digit extracted from the DTMF tone. Unfortunaly i...
0
by: Rotem925 | last post by:
hello, im trying to generate and detect dtmf tones frequencies can anyone please tell me if there is ant class that handles it? or any direction where to start? i have searched the MSDN and saw...
1
by: DaniloAlmeida | last post by:
Hi everyone, How are you ? Happy new year for all !!! Well I want to know how can I find some data like a tone in a recorded wave file in WindowsPCM format in 11kHz - 8bits. This file(s)...
1
by: Florian Göttsch | last post by:
Hi, I have the following problem: I must send a DTMF tone "A" for at least 3 seconds. But i can only find solutions for sending tones with a normal length ( about 200ms ). In Details: I...
3
by: clintonG | last post by:
This article has shown me how to playing system sounds and .wav files via a web page. Very nice to know. It got me wondering if we could somehow play one or more tones of a musical scale somehow...
53
by: Jonas Smithson | last post by:
In his book "CSS: The Definitive Guide" 2nd edition (pgs. 116-117), Eric Meyer has an interesting discussion about "font-size-adjust" that was evidently dropped in CSS 2.1 due to browser...
4
by: sravan_reddy001 | last post by:
i want a sound to be generated when and event occurs. especially when a message box is displayed and when an user want to close a form(i want to include this in the form closing event) thanks... ...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: =?Utf-8?B?TG9nYW4=?= | last post by:
I have an application that plays short (2-5 seconds) sounds from resources at specific times. About 10% of the time the wav file will start playing fine and at some undetermined point during the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.