Sunday, September 18, 2011

How to generate sound in Turbo C..

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
clrscr();
printf("sa...................\n");
sound(600);                      
delay(1000);
nosound();

printf("re...................\n");
sound(700);
delay(1000);
nosound();


printf("ga...................\n");
sound(800);
delay(1000);
nosound();

printf("ma...................\n");
sound(900);
delay(1000);
nosound();

printf("pa...................\n");
sound(1000);
delay(1000);
nosound();

printf("dha...................\n");
sound(1100);
delay(1000);
nosound();

printf("ni...................\n");
sound(1200);
delay(1000);
nosound();



getch();
}



/*

If we are creating graphical programs in turbo c then adding sound to the  program makes it more compelling experience for the viewer in another sense. Adding sound in the C++ program is very easy.
Sound generation function:
The steps  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 particular 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.
(*)To use the sound generating function we have to specify the “dos.h” file

Example: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 particular time period.
*/

1 comment:

  1. how to play mp3 in turbo c programming
    (without using windows.h)

    ReplyDelete