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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PC speaker vs SoundCard 2

Status
Not open for further replies.

JimmyK

Programmer
Sep 8, 2000
142
0
0
VN
Hi all,
My PC has 1 soundcard onboard. I want to send BEEP sound to PC speaker, not soundcard. How can i do that?

Thank a lot
Jimmy
 
It depends on your compiler. See if there is a pre-defined function that allows to to send a signal to the speaker.

Otherwise you have to check if your compiler allows you to send a value to a specific port, e.g. inport() outport().
I forgot the exact port numbers but maybe someone else can tell you. If not, reply and I will find it out.

-- ralf
 
Hi Ralf, and all
I really dont know the port number if PC speaker. please check it for me

Thank a lot

Jimmy
 
Hi Jimmy,

I found some old code snippets and put them together to an example that works with Visual C++ 6.
I am sure there is an easier way but this one works however.

#include <conio.h>

void sound(unsigned);
void nosound(void);

int main(void)
{
sound(440); // play &quot;a&quot;

for(unsigned long l=0;l<1000000;++l); // wait some time

nosound(); // stop beeping

return 0;
}

void sound(unsigned frequency) // freq = Hz
{
const long F = 0x1234dc; // clock frequency

unsigned t = F / frequency;

_outpw(0x43,0xb6);
_outpw(0x42,t & 0xff);
_outpw(0x42,t >> 8);
_outpw(0x61,_inpw(0x61) | 3);
}


void nosound(void) // turn off speaker
{
_outpw(0x61,_inpw(0x61) & ~3);
}

You may change the frequency and the pause to get better results. Hope this helps.

-- ralf

 
Ralf, thank you very much again.
Your code works beautiflly

Jimmy
 
Hi Ralf,
What document or book can i lookup PC port number?
Thank a lot

Jimmy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top