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++?
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...
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)
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.
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)
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.
Last edited by DougDbug; 07-08-2005 at 06:27 PM.
This code will produce a noise, probably a Windows sound. Unless the sound's off.
Code:cout << "\a";
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.