Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
Post subject: Make sound with C++
Anyone knows how to produce sound at pc speaker using C++?
It should be fairly common but I cannot seem to find how to do it. Turbo C / Visual C.
For a starter I need some direction or code as to how produce a sound. Any sound with C. _________________
Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
Sat Jun 26, 04 7:20 am
quantum Site Admin
Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
Post subject: making sound in PC speaker with C
I did little research about making sound in PC speaker with C. And found a sample code. Anyone interested can give this a try.
Quote:
EXTERN void DoSound( unsigned int , unsigned int );
#if defined(USE_WIN32)
void DoSound( unsigned int freq, unsigned int time )
{
Beep( freq, time );
return;
}
#elif defined(USE_DOS)
#if defined(__DJGPP__)
#undef nosound
void nosound(void)
{
sound(0);
return;
}
#define SLEEP(t) delay(t/2)
void DoSound(unsigned int freq, unsigned int time)
{
sound(freq);
SLEEP(time);
nosound();
return;
}
#elif defined(HAVE_SOUND)
void DoSound(unsigned int freq, unsigned int time)
{
sound(freq);
sleep(time);
nosound();
return;
}
#else
#ifndef LOBYTE
#define LOBYTE(w) ((BYTE) (w))
#endif