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 ()
'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(&HB0, &H11) 'Turn sound off
CALL wradlib(&HA0, note%) 'Setup the frequency of the note
CALL wradlib(&HB0, &H31) 'Turn on the sound
LOOP
CALL wradlib(&HB0, &H11) 'Turn sound off
SUB rstlib
'This SUB sets all Adlib registers to zero
FOR t% = 1 TO &H8
CALL wradlib(t%, 0)
NEXT
FOR t% = &H20 TO &H35
CALL wradlib(t%, 0)
NEXT
FOR t% = &H40 TO &H55
CALL wradlib(t%, 0)
NEXT
FOR t% = &H60 TO &H75
CALL wradlib(t%, 0)
NEXT
FOR t% = &H80 TO &H95
CALL wradlib(t%, 0)
NEXT
FOR t% = &HA0 TO &HA8
CALL wradlib(t%, 0)
NEXT
FOR t% = &HB0 TO &HB8
CALL wradlib(t%, 0)
NEXT
CALL wradlib(&HBD, 0)
FOR t% = &HC0 TO &HC8
CALL wradlib(t%, 0)
NEXT
FOR t% = &HE0 TO &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 &H388 and &H389
OUT &H388, address%
FOR t% = 1 TO 6
q% = INP(&H388) 'Delay to give Adlib time to process code
NEXT
OUT &H389, byte%
FOR t% = 1 TO 35
q% = INP(&H388) 'Delay to give Adlib time to process code
NEXT
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.