Microsoft KB Archive/57776

= PLAY and SOUND Click Speaker in QuickBasic; OUT Clicks Less =

Article ID: 57776

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q57776



SUMMARY
In QuickBasic, the PLAY and SOUND statements produce a click on the speaker noticeable at the end of a sound. Also, if an inaudible frequency is used with the SOUND statement, a click is heard before and after the PLAY or SOUND statement.

This article shows a method using the OUT statement to produce sounds where the clicking is less noticeable.



MORE INFORMATION
The following program produces the clicking noise and then shows an improvement involving programming the timer chip as explained in the following book:

&quot;The New Peter Norton Programmer's Guide to the IBM PC & PS/2,&quot; by Peter Norton and Richard Wilton (Microsoft Press, 1988). Pages 148-150.

Code Example
' The following PLAY statement demonstrates the clicking sound: FOR i% = 1 TO 3 PLAY &quot;L4 C&quot; SLEEP 1 NEXT ' The following SOUND statement demonstrates the clicking sound: FOR i% = 1 TO 3 SOUND 700, 12 SLEEP 1 NEXT ' The following OUT statements alleviate the clicking sound while ' generating tones: count1 = 1193280! / 700       ' 700 is the desired frequency count2 = 1193280! / 100000    ' 100,000 is the desired inaudible frequency lo.count1 = count1 MOD 256    ' calculate low-order byte values lo.count2 = count2 MOD 256 hi.count1 = count1 / 256      ' calculate high-order byte values hi.count2 = count2 / 256 OUT &H43, &HB6                ' get timer ready old.port = INP(&H61)          ' read the value at port 61H new.port = (old.port OR &H3)  ' set bits 0 and 1 OUT &H61, new.port            ' turn speaker on FOR i% = 1 TO 3 OUT &H42, lo.count1         ' load low-order byte for first frequency OUT &H42, hi.count1         ' load high-order byte for first frequency SLEEP 1 OUT &H42, lo.count2         ' load low-order byte for second frequency OUT &H42, hi.count2         ' load high-order byte for second frequency SLEEP 1 NEXT OUT &H61, old.port            ' turn speaker off END

Additional query words: QuickBas BasicCom

Keywords: KB57776

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.