I've programmed in QBASIC for years but now I am learning C++ since it is quite superior.
How does one make music with the PC speaker? In BASIC it was pretty simple, is there a similar set of commands for C++?
Printable View
I've programmed in QBASIC for years but now I am learning C++ since it is quite superior.
How does one make music with the PC speaker? In BASIC it was pretty simple, is there a similar set of commands for C++?
Under DOS there were the sound (freq) and nosound () functions.
Don't know how portable they are though...
I'm using the Borland compiler under Editplus. Would those work, and if so how exactly do I use them?
I'm a C++ newb so sorry for the easy questions.
Simply call sound () with the frequency you need and call nosound to stop the sound.
I think I need some packages for this. I found sound.h but when I include it I get a bunch of errors asking for config.h and a bunch of errors in lzexpand.h
First - There is no sound in ANSI/ISO standard (i.e. portable) C++. And while we're at it, there are no graphics, mouse, or color either. :(
So, all this stuff is system & compiler specific.
In a modern MS-Windows system there is no easy way to make sounds from the PC's internal speaker. If you don't have a sound card, beep() will work. If you do have a sound card, beep() will play the Windows Default sound from the external speakers.
On an older system (i.e. Win98) you can write to the registers that control frequency and duration of sound from the speaker. Newer operating systems "protect" the hardware from direct access by your user-mode programs. (You have to write a driver.) You'll get an error if you try to run your Q-BASIC speaker-sound program in a "DOS window" on Win2000 or WinXP.
The easiest way to get sound is to use playsound() to play a wave file thru your soundcard and external speakers.
[EDIT] ---------------------------------------------
And, I have more bad news. You can't mix & match .h files from different compilers. See this FAQ.
This code will produce a noise, probably a Windows sound. Unless the sound's off.
Code:cout << "\a";