If you are creating graphical programs in turbo c++ then adding sound to the the program makes it more compelling experience for the viewer in another sense.Adding sound in the C++ program is very easy.In this guide you will learn to use sound for your programs.
Check the installation video for Turbo C++ 3.0 on Modern Windows OS (64-bit)
Sound generation function:
The steps that involve to generate the sound in C++ are:
(1) Turning the sound on.
(2) Delay-ing for an appropriate amount of time.
(3) Turn-off the sound.
To perform these steps three standard functions are used :
sound( );
delay( );
nosound( );
Sound( ); function :-
The sound( ); function is used to set the sound generator to a specific frequency.You can specify the frequency from 15 to about 3000.
e.g. sound(100);
After execution of this function sound is turned on.So please note that sound remains on till it is specifically stopped.
delay( ); function :-
To delay the sound for perticular amount of time this function is used.
e.g. delay(1000);
This function accepts single argument,and the time specified here is in the miliseconds.You can use the value 1000 for one second.
nosound( );:-
To turn off the sound started by the sound( ); function this function is used. This immediately turns off the sound generator.
Example:
#include"dos.h" int main(void) { sound(800); delay(1500); nosound(); }
Code explaination:
#include "dos.h"
To use the sound generating function we have to specify the “dos.h” file.Â
int main(void)
If you use the void main instead of this line then sound generating function may not able to return a value.Â
sound(800); delay(1500); nosound( );
Here the sound with frequency 800 hz is delayed for one and half seconds then nosound(); is used to turn off the sound generator.
These mentioned sound generating functions can be used to suspend the excution of program for perticular time period. You can use another function called sleep( ); to suspend the execution of the program for some time.
sleep( );
This function is used to suspend the program for perticular interval.
e.g. sleep(n);
Here value n is used to specify the time interval in seconds.
I hope above information helped.If you have any questions then please post them here.Again, any suggestions are welcome.
mahesh says
You can add the *.wav files & *.mp3 files,but i’m not sure how to do it with Turbo C++ 3.0.
If you are using Borland C++ builder 6 then you can add sound in your program in terms of wav or mp3 file.Just check the HELP section with Title” Adding sound or movie clip in application” or simply search the help file for the Wave file format.
Hope this helps.
Goutam says
This produces sound from the internal speaker of cpu. I have it in my laptop as i get the post beep but i am unable to generate sound in turbo c++. Is there any way to generate sound through sound card so that it is audible through external speaker