How to play a .wav File through beep function?

Started by
4 comments, last by darookie 19 years, 4 months ago
How to play a .wav File through beep function? Anyone know it?
Advertisement
you can do that?
what is this "beep" function you speak of?

Beginner in Game Development?  Read here. And read here.

 

If you want to play wav files using the PC speaker you have to reprogram the 8254 timer chip (present on all PCs). You will need to hook to the timer interrupt (int 8), which runs at a basee frequency of 18.2Hz. Usig some counters you can trick it into ticking at higher frquencies (required for sampling), though.
I don't remember how it was done exactly (you somehow need to fiddle with the interrupt controller at port 20h and such), but it is not possible without special kernel driver anyway.
Someone wrote a linux driver for that - maybe that will help you.

Good luck,
pat.
I mean the API:
BOOL Beep(
DWORD dwFreq,
DWORD dwDuration
);

I want to know the algorithm(maybe DSP)?
I don't expect someone to explain the detail at great length and a link or an article is appreciated.
I think the answer is that you don't normally play .wav files that way.

That API tells the speaker to play a sound for a certain time and duration. A .wav file essentially tells the speaker what position it's diaphragm should be at.

You can make beeps easily with a digital sampled (.wav method) using something like:

for(j=0; j<256; ++j) {  for(i=0; i<256; ++i)    write(256);  for(i=0; i<256; ++i)    write(0);}


Going the other way is much harder - it requires high timing accuracy and probably a nice chunk of processor time (not that much on modern systems though). Unless you're looking at games on a CNC machine, I think you can assume a sound card that can play back digital audio.

Without interrupt level code, you're not going to get this to work reliably.
-- Jonathan
Quote:Original post by LucidIon
Without interrupt level code, you're not going to get this to work reliably.

Seconded. You won't even get it play something you want to hear at all - the sampling rate is at best 1KHz. The other thing is, that Beep() is not asynchronous, that is it doesn't return the control to the caller unless it finished. While it might be possible to call Beep() in a seperate thread, the required FFT calculations would surely make realtime playback impossible (since Windows isn't a real-time OS).
Just use PlaySound() instead.

This topic is closed to new replies.

Advertisement