Board index » cppbuilder » making sounds

making sounds


2006-02-23 07:02:39 AM
cppbuilder108
I have a very simple program I wrote to make beeps. Well actually to
play Morse code to the user tapping on the mouse button. So while the
mouse is down it plays a tone and stops when the button is released.
The easiest way I could figure to do this was to just play a wave file
while the mouse button is down and the stop and rewind while it is up.
There has to be a more elegant solution than that. Something that would
allow me to easily change the frequency of the tone would be nice too.
Any ideas? I haven't done much C++ builder in several years now.
--
Chris W
KE5GIX
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
thewishzone.com
 
 

Re:making sounds

I have a very simple program I wrote to play Morse code to the user
tapping on the mouse button. So while the mouse is down it plays a tone
and stops when the button is released. The easiest way I could figure to
do this was to just play a wave file while the mouse button is down and
the stop and rewind while it is up.
There has to be a more elegant solution than that. Something that would
allow me to easily change the frequency of the tone would be nice too.
Any ideas? I haven't done much C++ builder in several years now.
--
Chris W
KE5GIX
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
thewishzone.com
 

Re:making sounds

"Chris W" < XXXX@XXXXX.COM >wrote in message
Quote
I have a very simple program I wrote
Please do not cross post. It is against Borland's newsgroups guidelines
(info.borland.com/newsgroups). Only post to the single most
appropriate group.
Gambit
 

{smallsort}

Re:making sounds

The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes.
BOOL Beep(
DWORD dwFreq, // sound frequency, in hertz DWORD dwDuration // sound duration, in milliseconds );
--
JF Jolin
 

Re:making sounds

JF Jolin wrote:
Quote
The Beep function generates simple tones on the speaker. The function is
synchronous; it does not return control to its caller until the sound
finishes.

BOOL Beep(
DWORD dwFreq, // sound frequency, in hertz DWORD
dwDuration // sound duration, in milliseconds );


I need to control when it stops and stops by clicking on the mouse
button. Some pseudocode will explain it best.
int hz = 700;
OnMouseDown(int hz)
{
PlaySound(hz);
}
//---------------------------------------------------------------------------
OnMouseUp()
{
SoundStop();
}
//---------------------------------------------------------------------------
--
Chris W
KE5GIX
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
thewishzone.com
 

Re:making sounds

Chris W wrote:
Quote
I have a very simple program I wrote to make beeps. Well actually to play
Morse code to the user tapping on the mouse button. So while the mouse is
down it plays a tone and stops when the button is released.
There has to be a more elegant solution than that. Something that would
allow me to easily change the frequency of the tone would be nice too.
Hmm, sounds like you're going to have to use the waveOut API plus some sine
work. Something like:
// Pseudo-code
OnAppStart()
{
WaveHandle = waveOpen( WAVE_MAPPER, Handle, WINDOW_HANDLE );
}
OnPlay()
{
FGlobalBool_ShouldPlay = true;
MakeASineWaveInBuffer();
wavePrepareHeader( WaveBuffer );
wavePlay( WaveBuffer );
}
void __fastcall TForm1::WndProc( ... )
{
if( Message == WOM_DONE )
{
if( FGlobalBool_ShouldPlay )
wavePlay( Message.lParam );
else
waveUnprepare( Message.lParam );
}
}
OnStop()
{
FGlobalBool_ShouldPlay = false;
}
OnAppExit()
{
waveClose( WaveHandle );
}
I know that I've got my parameters all mixed up, but I hope that this gices
you an idea of what to look for.
Jonathan
 

Re:making sounds

Jonathan Benedicto wrote:
Quote
Chris W wrote:

>I have a very simple program I wrote to make beeps. Well actually to play
>Morse code to the user tapping on the mouse button. So while the mouse is
>down it plays a tone and stops when the button is released.
>There has to be a more elegant solution than that. Something that would
>allow me to easily change the frequency of the tone would be nice too.


Hmm, sounds like you're going to have to use the waveOut API plus some sine
work. Something like:

// Pseudo-code

OnAppStart()
{
WaveHandle = waveOpen( WAVE_MAPPER, Handle, WINDOW_HANDLE );
}

OnPlay()
{
FGlobalBool_ShouldPlay = true;
MakeASineWaveInBuffer();
wavePrepareHeader( WaveBuffer );
wavePlay( WaveBuffer );
}

void __fastcall TForm1::WndProc( ... )
{
if( Message == WOM_DONE )
{
if( FGlobalBool_ShouldPlay )
wavePlay( Message.lParam );
else
waveUnprepare( Message.lParam );
}
}

OnStop()
{
FGlobalBool_ShouldPlay = false;
}

OnAppExit()
{
waveClose( WaveHandle );
}

I know that I've got my parameters all mixed up, but I hope that this gices
you an idea of what to look for.

Jonathan


That's a heck of a lot of code to do what I could do in dos to the PC
speaker with 2 lines of code. I guess that's what you call progress.
--
Chris W
KE5GIX
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
thewishzone.com
 

Re:making sounds

Chris W wrote:
Quote
That's a heck of a lot of code to do what I could do in dos to the PC
speaker with 2 lines of code. I guess that's what you call progress.
That new sound card can do quite a lot more than the old PC speaker, so
maybe it is to be expected. :-)
Jonathan
 

Re:making sounds

Quote
There has to be a more elegant solution than that. Something
that would allow me to easily change the frequency of the tone
would be nice too. Any ideas? I haven't done much C++ builder
in several years now.
I bet you'll like this page:
www.alan-warriner.co.uk/soft.htm.
Bye,
Stefano
 

Re:making sounds

SF wrote:
Quote
>There has to be a more elegant solution than that. Something
>that would allow me to easily change the frequency of the tone
>would be nice too. Any ideas? I haven't done much C++ builder
>in several years now.


I bet you'll like this page:
www.alan-warriner.co.uk/soft.htm.

Bye,

Stefano


I found that site but when I try and compile the component for c++
builder 5 I get the following error....
[Linker Fatal Error] Fatal: Unable to open file 'DCLUSR50.LIB'
and I don't really know what to do about it.
--
Chris W
KE5GIX
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
thewishzone.com
 

Re:making sounds

Chris W wrote:
Quote
I found that site but when I try and compile the component for c++ builder
5 I get the following error....

[Linker Fatal Error] Fatal: Unable to open file 'DCLUSR50.LIB'

and I don't really know what to do about it.
What files did it come with ?
Jonathan
 

Re:making sounds

Jonathan Benedicto wrote:
Quote
Chris W wrote:

>I found that site but when I try and compile the component for c++ builder
>5 I get the following error....
>
>[Linker Fatal Error] Fatal: Unable to open file 'DCLUSR50.LIB'
>
>and I don't really know what to do about it.


What files did it come with ?

it said if I didn't have V4 to unzip the source and open the .bpk file
to compile and install the component. Since I have V5 I did that and
these are the files that were in the source zip file...
02/24/2006 02:36p <DIR>.
02/24/2006 02:36p <DIR>..
01/03/2002 09:12p 6,819 ToneGen.hpp
01/01/2002 10:48p 38,369 ToneGen.pas
03/01/2002 09:27p 5,116 TToneGen.bpk
03/01/2002 09:33p 656 TToneGen.cpp
12/31/2001 10:42p 1,976 TToneGen.res
5 File(s) 52,936 bytes
--
Chris W
KE5GIX
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
thewishzone.com
 

Re:making sounds

Quote
>>[Linker Fatal Error] Fatal: Unable to open file 'DCLUSR50.LIB'
The author of this package didn't remove unecessary packages from the
requires list. You should just create a new package. BTW, TToneGen.bpk is
not a very good name for a package. Personally, I would go with something
like ToneGenC5.bpk.
Follow these steps:
1. File | New | Package
2. Save the package wherever you have the source for the tone gen files
3. Add
4. Browse
5. Change the "files of type" to look for PAS
6. Add ToneGen.pas
7. Compile
The HPP file will be regenerated and you can use the newly created package
in your application.
HTH,
- Clayton