Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PC-Speaker Control with QuickBASIC.

0 views
Skip to first unread message

g...@matityahu.com

unread,
Dec 27, 1997, 3:00:00 AM12/27/97
to

Hello People.

I'm looking for a way to address the PC-Speaker port to play sounds
higher than the QuickBASIC allowed values for example - playing sounds
in MHzs.

Thanks.
g...@matityahu.com

Judson McClendon

unread,
Dec 27, 1997, 3:00:00 AM12/27/97
to

g...@matityahu.com wrote:
>
> I'm looking for a way to address the PC-Speaker port to play sounds
> higher than the QuickBASIC allowed values for example - playing sounds
> in MHzs.

The base frequency of the timer clock is 1.19318 MHz, which is your highest
frequency, using a divisor of 1. A divisor of 2 halves it to under 600 kHz.

No human can hear sounds over ~22 kHz. Sounds in the MHz range are going to
be really boring to anybody but bats.

I don't have BASIC code handy, but the C code to make a sound using the PC
speaker is below. The code should be easy to convert to BASIC, just remember
these conversions:

C BASIC
----- -----
& AND
>> 8 \ 256
| OR

#define CLOCKFREQ ((unsigned)1193180L) /* Timer frequency */
#define SPEAKERMODE ((unsigned)0xB6) /* Set timer for speaker */
#define TIMERMODEPORT ((unsigned)0x43) /* Timer mode port */
#define FREQPORT ((unsigned)0x42) /* Frequency-control port */
#define SPEAKERPORT ((unsigned)0x61) /* Speaker port */
#define SPEAKERON ((unsigned)0x03) /* Speaker-on bits */
#define FREQ ((unsigned)400) /* Sound frequency */
#define CFREQ CLOCKFREQ / FREQ /* Division frequency */

int saveport;

outp(TIMERMODEPORT, SPEAKERMODE); /* Save current status */
saveport = inp(SPEAKERPORT);

outp(FREQPORT, CFREQ & 0xFF); /* Start tone */
outp(FREQPORT, CFREQ >> 8);
outp(SPEAKERPORT, saveport | SPEAKERON);

/* place code here to delay for duration of sound */

outp(SPEAKERPORT, saveport); /* Stop tone */
--
Judson McClendon This is a faithful saying and worthy of all
Sun Valley Systems acceptance, that Christ Jesus came into the
judm...@mindspring.com world to save sinners (1 Timothy 1:15)
(please remove zzz from email id to respond)


0 new messages