Sign in to follow this  

PC Speaker

This topic is 4865 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

I know this is a rather broad question, but how would I go about playing the PC speaker at different frequencies, amplitudes and lengths of time? I've been looking all over the web for tutorials, and all the example code I've tried has not worked. I'm looking for a solution in either C++ or Java. Thanks

Share this post


Link to post
Share on other sites
I don't think its possible with java, and I'm fairly certain it is only possible in C++ using an old 16-bit compiler (Borland C++ 4.02 had a function for it). You could also use inline assembly, but I'm fairly certain it will onyl work in 16-bit mode (aka 'dos')

Share this post


Link to post
Share on other sites
With windows platform SDK, use Beep( dwFreq, dwDuration );

EDIT: Be aware that Beep is synchronous : you'll need to execute it in a different thread if you want to run something else.

Share this post


Link to post
Share on other sites
Ah ok, the beep function works.

But, now I how do I go about determining different notes.

From by limited knowledge of music it seems like one can arbitrarily pick a frequency range and divide by 8 to get the frequency of each note. (For example: I'll define my octave between 600Hz-1000Hz. Range of Octave = 400 Hz. Divide by 8 = 50. So a C = 400 Hz, D = 450 Hz, etc...)
Am i somewhat right or just completely off?
Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by python_regious
Middle C is 256Hz, from what I can remember.


The International Standard Pitch for middle C is about 282 Hz. However, there is nothing stopping one from using a different scale and defining middle C as 256 Hz, as has been done by many composers.

Share this post


Link to post
Share on other sites

This topic is 4865 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this