Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making sounds in Borland C++

Status
Not open for further replies.

arcane0virus

Programmer
Sep 19, 2005
5
US
How would I go about this subject? I only now how to make one sound, and that is the sound using the alert function. But I want to know if there is any other way I can make different beeps or sounds so I could make like a mini song program.
 
I'm assuming you are talking about doing this via DOS. Borland used to have a DOS.h that included a sound function. It plays a frequency on the PC's speaker.
Code:
#include <dos.h>

int main(void)
{
    sound(440); // Plays 440 Hz tone
    delay(1000); // Makes the sound for 1 second (1000 milliseconds)
    nosound(); // Turns sound off
    return 0;
}

Note: this may not work with Win-NT, 2000, or XP.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
2ffat: I have tried this with your code sample, but it does not recognize any of the procs that you made in your code. What happened?
 
As I mentioned, this may (will?) not work with the newer OS's. What OS and what version of Borland are you using. I don't even know if DOS.h is included with the compiler anymore.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
And what is the target of your application? As I remember, Borland C++ 5.0 can produce both DOS & Windows applications.
 
B00gyeMan is right, that version of Borland should have the DOS commands. The problem may be XP. Since NT, 2000 and XP are full 32-bit OS, they may not have the correct latches that DOS.h used to use. See if the program will work on a Win9X machine, e.g., Win 98SE.

I don't even know it the program will compile properly on XP. You may have to look at the compiler options to see if something needs to be turned on or off.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
How do I get into the compiler options and how do I know what to turn on or off? (And if you couldn't tell by now, I am a complete n00b. I just got into a class that shows us how to code with this.)
 
I don't remember about Borland 5.01. If you compile from the command line, it is just options preceeded with a minus (-). If you use the IDE, there are compiler options somewhere.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Oh, what you are looking for is 16-bit vs. 32-bit options. Sorry I can't be of more help.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Alright! I got it working now. I used the Turbo C++ IDE and got it working in a jiffy. Thank you 2ffat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top