In Turbo C++, how do I get sound to come out of my speakers? I know how to program it, but I can't hear anything.
In Turbo C++, how do I get sound to come out of my speakers? I know how to program it, but I can't hear anything.
Whichever sound(1000) will work for. I believe it's the PC Speaker, so that one I guess.
The sound() function should work. You must then use nosound() to turn off the sound. In order for it to be useful you will need to set up some kind of timer.
An eaisy way would be to only hook the PIT timer interrupt. When the interrupt is generated and control is handed to your ISR, stop the sound. This will only work for 1 sound and not a chunk or block of sounds. If you reprogram the buffer during the timer interrupt then your sound will stop and the quality will decrease (but PC speaker quality isn't good anyways). Using this method (and more) it is possible to generate digital sounds through the PC speaker, but the timing is not nearly as easy as it is with Sound Blaster programming. The main problem is that the computer does not generate an interrupt to stop the sound (to my knowledge). If it does or did, then you would need to hook the interrupt that it generates. Upon entering the ISR, then you could fill the buffer and begin playing. Again, I'm used to programming sound cards so this may not be totally accurate.
You could also forget the ISR approach and set up a timer based on the frequency of the PIT timer similar to framerate counters. The problem here is that this is not very accurate. For accurate timing you must hook the PIT timer interrupt, interrupt 08h (PIT?), or interrupt 70h.
I'm also not sure if the PC speaker executes in the background or not. Sometimes it seems to, and others it does not. It will be very hard to find any docs on PC speaker programming as it is very old school. Castle Wolfenstein (not the 3d one), Mean Streets, and some others did use the PC speaker for digital sound, but those were programmed when the 8086, 80286, and 80386 were top of the line systems. Castle Wolfenstein was programmed for the IBM PCjr way back in 1982. I have not been able to find ANY (I never use capitals, but I stress ANY) docs on programming digital sound through the PC speaker.
Your best bet is to check out www.creative.com and go to their developer section. You do not have to log in or be a member to download their old DOS documents. Download all of their docs relating to DOS Sound Blaster programming. If you do not understand interrupt service routines, check out Randall Hyde's art of assembly language programming doc (book) on the net or go to www.programmersheaven.com and look for source concerning sound card programming. Also www.gamedev.net may have some info as well as The Programmer's Lair (they have Ethan Brodsky's code for the sound card) - forget the URL. You can link to it from programmersheaven and maybe from this board's links section.
Sorry so long, but there is a lot involved if you want to make more than bleeps and blips from the PC speaker. That might be good for pong on the Atari 2600, but not for the PC.
If you are dead set on PC speaker, you will need a formula to convert from analog to digital and back again.
I did some research and did find some PC speaker programming docs, much to my surprise. There is a doc on www.gamedev.net about the PC speaker and it explains how to send 8-bit sound through the PC speaker. It is in their articles and resources section under sound programming (non-DirectX).
Just curious, but it is possible to generate sounds using the PC speaker in Windows? It'd be nice if the speaker was listed as a multimedia device (yes, I know there are third-party drivers for it... :P)
You could also (if you have no life like me!) get down into DEBUG or something, and code an assembler function yourself. ASCII #7 is a beep in console programming, I'm not sure about Windows. That's what I always do - I guess I like being self-sufficient! (because i have no life).
So what if all I want is blips and bleeps from the PC? I'm not understanding how to achieve even that.Originally posted by Bubba
Sorry so long, but there is a lot involved if you want to make more than bleeps and blips from the PC speaker. That might be good for pong on the Atari 2600, but not for the PC.
I forgot to actually SHOW the assembler code for playing a beep in my above reply.
MOV DL,07
MOV AH,02
INT 21
INT 20
Hope this helps.
sound (freqinhertz);
delay(sometimelimit);
nosound();
If delay is not avail. just use a loop and count to a certain number. For timing either use the PIT or difftime().
Are there any libraries i need to include for those to work? Cos they're not.
They are in dos.h
If you do not have a DOS compiler, you will not be able to use these.