Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access the FM music chips on a Sound Blaster card

Sound effects

How to access the FM music chips on a Sound Blaster card

by  zBuilder  Posted    (Edited  )
You can pick up Blaster.zip at my site below:

http://www3.bc.sympatico.ca/Kim_Christensen/program.html

The Zip file includes source code in both Basic and C showing how to use the FM music chips on the soundblaster and compatable cards. This is NOT a demo / code example of how to play WAV files. Included is a working execuable file (For DOS) and the Jeffrey S. Lee AdLib/Sound Blaster programming FAQ.

Or, try out the code below:


DECLARE SUB wradlib (address%, byte%)
DECLARE SUB rstlib ()

CLS
PRINT "Resetting Adlib/SB Card!"
CALL rstlib
PRINT "Ready to play..."

'In this group of Calls, play around with the 2nd hex number (The byte%
' variable) for special effects.

CALL wradlib(&H1, &H20) 'Enable Waveform control
CALL wradlib(&H20, &HE0) 'Set modulator settings
CALL wradlib(&H40, &H80) 'Set the modulator's level to max and
'set scaling factor to 1.5db/8ve
CALL wradlib(&H60, &HF2) 'Set attack & decay to med-slow
CALL wradlib(&H80, &H77) 'Set sustain to min. & Release to med.
CALL wradlib(&HA0, &H0) 'Set default note (Not really neccesary)
CALL wradlib(&HC0, &H4) 'Set feedback and Algorithm.
CALL wradlib(&H23, &HC1) 'Set mod. freq. Multiple, etc. of 2nd Op.
CALL wradlib(&H43, &H0) 'Set volume of 2nd operator to max.
CALL wradlib(&H63, &HF5) 'Set attack & decay of 2nd operator
CALL wradlib(&H83, &H77) 'Set sustain to min. & Release of 2nd. Op.
CALL wradlib(&HBD, &H80) 'Set AM depth to the max.
CALL wradlib(&HE0, &H0) 'Setup waveforms for 1st. Op.
CALL wradlib(&HE3, &H0) 'Setup waveforms for 2nd. Op.
CALL wradlib(&HB0, &H22) 'Turn on the voice, set octave, etc..

' Following code will turn your keyboard into a Musical Keyboard
PRINT "Hit Escape key to stop"
DO WHILE note% <> 54
SLEEP 'Wait for next keypress
a$ = INKEY$
IF a$ = "" THEN a$ = CHR$(127)
note% = ASC(a$) * 2 'Scale the number for a wider freq. range
CALL wradlib(&amp;HB0, &amp;H11) 'Turn sound off
CALL wradlib(&amp;HA0, note%) 'Setup the frequency of the note
CALL wradlib(&amp;HB0, &amp;H31) 'Turn on the sound
LOOP
CALL wradlib(&amp;HB0, &amp;H11) 'Turn sound off

SUB rstlib

'This SUB sets all Adlib registers to zero

FOR t% = 1 TO &amp;H8
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;H20 TO &amp;H35
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;H40 TO &amp;H55
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;H60 TO &amp;H75
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;H80 TO &amp;H95
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;HA0 TO &amp;HA8
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;HB0 TO &amp;HB8
CALL wradlib(t%, 0)
NEXT

CALL wradlib(&amp;HBD, 0)

FOR t% = &amp;HC0 TO &amp;HC8
CALL wradlib(t%, 0)
NEXT

FOR t% = &amp;HE0 TO &amp;HF5
CALL wradlib(t%, 0)
NEXT

END SUB

SUB wradlib (address%, byte%)

'This SUB sends the data (byte%) to the subport specified by address%
'All subports are accessed via IO addresses &amp;H388 and &amp;H389

OUT &amp;H388, address%
FOR t% = 1 TO 6
q% = INP(&amp;H388) 'Delay to give Adlib time to process code
NEXT

OUT &amp;H389, byte%
FOR t% = 1 TO 35
q% = INP(&amp;H388) 'Delay to give Adlib time to process code
NEXT

END SUB

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top