Jump to content
  • Advertisement
Sign in to follow this  
DvDmanDT

PC speaker

This topic is 4769 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everone... How can I use the PC speaker (in a 32 bit program)? The sound() function seems to have dissapeared years ago (no big surprise here).. I suspect I'll have to use assembly to use it, and that's ok, but I have no idea what to do in order to use it.. All I can find is VERY old delphi code to use it.. So, any help? [edit] I posted in the wrong forum before, I intended to post it in general programming

Share this post


Link to post
Share on other sites
Advertisement
The PC speaker lives at port 0x80 (or is that 0x81 ? it's been so long ago).

The problem is that the port space is protected, and can't be accessed by a 32-bit program that's not running in kernel mode. Thus, you have to write a device driver that lets you twiddle this port -- or perhaps use one that's already written.

The specifics of that depend on what OS you're targeting, of course.

Share this post


Link to post
Share on other sites
Damn, that was what I suspected.. It is avaible to 16 bit programs though.. So that 16-bit emulator functionality of the cpu must be able to use it.. Do you know if I by any chance can enter that mode in a code block inside my exe? Probably not.. Maybe I can create a 16-bit exe file and pipe it from my windows exe, and send everything needed to stdin.. :p

Share this post


Link to post
Share on other sites
Quote:
Original post by Kamikaze15
You can use the Beep function if you're using windows.


"The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes."

Don't think thats what he wants.

Share this post


Link to post
Share on other sites
Yeah, I know that... But I couldn't find any better when I needed it too...
I just did a trick, everytime I wanted to Beep away I spawned a new thread that would self-destruct when unneeded.

kinda like:

struct MYBEEPS
{
DWORD dwFreq;
DWORD dwDur;
HANDLE hThread;
};

DWORD WINAPI myBeepThread( void* pPrivateData )
{
MYBEEPS *pData = (MYBEEPS*)pPrivateData;
Beep( pData->dwFreq, pData->dwDur );
CloseHandle( pData->hThread );
delete pPrivateData;
ExitThread( 0 );
return 0;
}

void myBeep( DWORD dwFreq, DWORD dwDur )
{
MYBEEPS *pData = new MYBEEPS;
if( !pData )
return;
pData->dwFreq = dwFreq;
pData->dwDur = dwDur;
pData->hThread = CreateThread( NULL, 0, myBeepThread, (void*)pData, 0L, NULL );
if( !(pData->hThread) )
delete pData;
}


I know it's kinda ugly, but it works [smile]

[edit] Corrected some stuff
[edit2] hacked a little to fix memory leaks (hopefully it should work ok)

Share this post


Link to post
Share on other sites
In 32-bit mode you will need to write a driver to access the PC speaker. Maybe you can find a driver online that makes the PC Speaker look like a sound cards...?

I would guess that the 16-bit virtual machine in windows (2000/XP atleast) would either emulate port 0x80 with your sound card or just ignore it...

Share this post


Link to post
Share on other sites
Trust me, it doesn't.. Download borlands Turbo C(++), and try the sound function.. It'll use real PC speaker.. Guess I'll have to forget about that though (I wanted to create a ringtone/midi player, that didn't require a soundcard/speakers)..

Share this post


Link to post
Share on other sites
I wrote a PC speaker driver for Xenix/286... about 15 years ago.. Ahh good times! Sorry I had to just share that I apologize for it being non-relevant.

Share this post


Link to post
Share on other sites
Why do you want to use the PC speaker instead of, say, the audio system? Many PCs these days just redirect the 'PC Speaker' to the audio system anyways.

Edit: NVM didn't see your last post. Really, I can't see why you'd want to do such a thing when you could just go to the nearest dollar store and get some speakers for $1. I guess the novelty might be cool, especially if you didn't limit it to midi (it isn't difficult to simulate PCM sounds on the PC speaker - look at all the DOS games that did it)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!