home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
SOUNDIO.CMM
< prev
next >
Wrap
Text File
|
1995-10-12
|
2KB
|
61 lines
// SOUNDIO.CMM - Demonstration inport() and outport() functions with the
// ver.2 PORTIO.LIB routines. This generates sound by directly
// accessing the hardware port addresses.
#include <PortIO.lib>
Instructions()
{
printf("\a\n")
printf("SoundIO - Sound a specified tone on the internal speaker for specified time\n")
printf(" using hardword port I/O calls and PORTIO.LIB\n")
printf("\n")
printf("SYNTAX: SOUND Freqency Duration\n")
printf("\n")
printf("Where: Frequency Tone in hertz\n")
printf(" Duration In milliseconds, accurate to %d milliseconds\n",1000/CLOCKS_PER_SEC)
printf("\n")
printf("The following example would play middle A for 2 seconds:\n");
printf(" CENVI2 SOUNDIO 440 2000\n")
printf("\n")
}
main(argc,argv)
{
if ( argc != 3 || 0 == (frequency=atol(argv[1])) || 0 == (duration=atol(argv[2])) )
Instructions();
else
sound(frequency,duration)
}
sound(pFrequency,pDuration)
{
StartTone(pFrequency);
suspend(pDuration);
StopTone();
}
StartTone(pFrequency) // start 8253 programmable timer playing this frequency
{
// determine counter to send to the 8253 programmable timer
#define CHIP_RATE 1193180
counter = CHIP_RATE / pFrequency;
// program 8253
#define COUNTER_REGISTER 0x42
#define COMMAND_REGISTER 0x43
#define SPEAKER_REGISTER 0x61
speaker = inport(SPEAKER_REGISTER);
if ( !(speaker & 0x3) ) {
speaker |= 0x3;
outport(SPEAKER_REGISTER,speaker);
outport(COMMAND_REGISTER,0xB6);
}
outport(COUNTER_REGISTER,counter & 0xFF);
outport(COUNTER_REGISTER,(counter >> 8) & 0xFF);
}
StopTone()
{
outport(SPEAKER_REGISTER,inport(SPEAKER_REGISTER) & 0xfc);
}