Click here to Skip to main content
Click here to Skip to main content

Morse code. Some examples of how to produce sounds.

By , 3 Apr 2001
 

This program demonstrates how to use the waveOut APIs to produce sounds of different frequencies. Two classes can play sounds asynchronously (with some differences in implementation), and one show works in plain synchronous mode.

The sample program takes a string you supply, converts it into Morse code, and then plays this code. You can customize the frequency and duration of the sounds produced.

 [Sample Image - 33K]

Using the asynchronous classes, it is possible to change frequency smoothly when sounds are playing, but sound quality is not very good.

This code was tested only on VC++ 6.0 and Windows 98.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Alexander Fedorov
Web Developer SEO
Ukraine Ukraine
Member
AlexF's Blog in Russian
Owner Spy competition analysis
Rating Burner Rating of blogs

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralGreat article!memberDrABELL16 Sep '09 - 15:31 
Hi Alexander,
 
I've enjoyed reading your article! Rather unusual and creative approach...
Kudos to the author and 5*.
 
My Best,
 
Alex
GeneralSir, I want to change a existed wav's frequency, can you give me some advice or some code? Thank you.memberwangmike51816 Jan '08 - 3:31 
Smile | :)
Generalmultichannel rather than stereomemberwalkerjiao2 Dec '03 - 14:10 
Can I play multichannel( 4 channels) sound using waveout APIs?
if(Yes)
{
How?
}
else
{
what can I do?
}
Thank you;
 
haha

QuestionHow to Store 16 Bit PCM WavememberMaria Jothi5 May '02 - 19:41 
Hello Sir,

My Query is Regarding PCM wave of 16 bits.

After Recording , lpData of WAVEHDR contains the data.

I had copied the lpData to char *buffer.

Now , I need to store the data in a file.
After writing Header information , I stored the data in the file as char (bytes by bytes).

This works fine for 8 bit (both mono & stereo).

I followed the same method for 16 bit .When I play the stored file ,noise also comes along with the recorded data .

I read from some articles related to WAVE and came to know that 16 bit should be stored as short..
If so , How can i store it ???

Else , If you have someother idea,Please throw light on it.
 
Thanks
Maria

 
Maria Jothi (Software Engineer)
MAIL-ID:maria_jothi@hotmail.com

GeneralAwesomememberMark Robert Strange12 Jul '01 - 3:37 
I had written a C program that created morse wave tones in memory, each with an artificial file header, and used sndPlaySound to execute them asynchronously. Since each wave was in it's own section of an array, the patterns for the tones only needed to be created once and could be replayed infinately without having to recalculate them each cycle, except when parameters changed, of course. This worked extremely well and seemed like THE solution.
 
This example is far better! Big Grin | :-D The memory used by this is far less and I have found that the latency factors that plague other morse examples (such as other processes in the background) are non-existant here.
 
Also, this code sheds light on the waveOutPrepareHeader, waveOutWrite, etc API calls and their use, along with creating threads and ensuring critical timed processes work properly. There is also a lot of examples put into practice on maintaining "clean" memory and how memory leaks are avoided. This code is also well structured and fairly easy to trace through.
 
What else can I say, except thank you! Smile | :) Smile | :) Smile | :)
GeneralMuch staticmemberMichael S. Scherotter14 May '01 - 9:58 
I have tried using these classes in my application where I need to produce single short tones based on what the mouse is over. It works, but will a large amount of "static" sound. Any suggestions?
 
Michael S. Scherotter
Lead Software Architect
Tartus Development, Inc.
GeneralTimed EventmemberUkJay13 May '01 - 13:32 
Hi,
 
Any ideas How to do a timed event with MFC?
 
say for example have a MessageBox say Hello, and play a tune every 15 mins...
 
Looking for thread and WM_ help...
 
Cheers
 
Blush | :O
 
UkJay
GeneralRe: Timed EventmemberBaFM22 Jun '01 - 2:59 
To do a timer event use the function 'SetTimer' which created a WM_TIMER message a the time interval you have specified.
With this function, Windows place only one WM_TIMER message in message list of the program for the ID which identify the Timer event.
You also have to create a 'TimerProc' wich receive an int as parametre which is ID of timer event.
If you work with MFC you can create the TimerProc with ClassWizard by select the message WM_TIMER.
In this case, you don't have to specify a TimerProc in the call.
To kill a timer event use 'KillTimer(int nIDEvent)' for class and 'KillTimer(HWND hWnd,int nIDEvent)' for global.
 
SetTimer exist in these class (parameters) :
'global' UINT( HWND hWnd,// handle of window for timer messages
UINT nIDEvent,// timer identifier
UINT nElapse,// time-out value
TIMERPROC lpTimerFunction)// address of timer procedure
CWnd UINT( UINT nIDEvent,
UINT nElapse,
void(CALLBACK EXPORT* lpfnTimer)(HWND,UINT,UINT,DWORD));//NULL if message is handled by CWnd Object
CWindow UINT(UINT nIDEvent,UINT nElapse)
& the child class...
 
TIMERPROC have these parametres : ( HWND hWnd,// handle of window for timer messages
UINT uMsg,/*=WM_TIMER*/
UINT idEvent,// timer identifier
DWORD dwTime)/*current system time*/ TIMERPROC;
GeneralPhone TonesmemberAnonymous22 Jan '01 - 22:19 
If any body is interested I have Phone Tones in 'wav' format.
 
Norm
GeneralRe: Phone TonesmemberCarsten Groen29 Jan '01 - 9:50 
I can recommend Cooledit from Syntrillium, it comes in a demo version. It can generate (among many things !) DTMF, do filtering etc etc.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 4 Apr 2001
Article Copyright 2001 by Alexander Fedorov
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid