home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip: Special Sound & MIDI
/
Chip-Special_Sound-und-Midi-auf-dem-PC.bin
/
dostools
/
qbx1
/
qbxsnd11.doc
< prev
next >
Wrap
Text File
|
1991-10-21
|
23KB
|
739 lines
QBXSOUND
The AdLib/MIDI Music Player and Sound Blaster/VOC Digital Input and
Output Recorder and Player for QuickBASIC/BASIC Professional Development
System Compilers.
Version 1.01, 22-Oct-1991
(C)1991 Cornel Huth -- All Rights Reserved.
Version 1.01, released just a day after the initial release, fixes the
problem that plaqued the first version--you can now play music in the
background while in the QB4b/4.5 environment. My thanks to Mr. Sandman.
QBXSOUND is a complete sound development system for the AdLib and Sound
Blaster sound cards. It requires QuickBASIC version 4.0a or above, or
QBX/BC 7.0 PDS or above. No other software/drivers are required. The
music is played in the background allowing you to perform other tasks
while the music plays. The digital input/output routines use DMA program-
ming techniques allowing you to play music, output a digital VOC track,
and perform other tasks such as screen updating, etc., ALL AT THE SAME
TIME. You won't find this capability anywhere, for any price, except in
QBXSOUND for QB/PDS.
QBXSOUND as you have received it consists of 3 QLBs. These are for
QuickBASIC 4.0b, 4.5, and QBX 7.1. You may use these QLBs for your
personal use without registering. However, in order to create .EXE
program files you must register to get the required link libraries.
To REGISTER see the !ORDER file or use the order form included within
this document.
Most of you will probably have .ROL files rather than MIDI-compatible
files. No problem. Use the supplied ROL2MIDI.EXE converter (courtesy
AdLib, Inc.). This translates the .ROL music file and its .BNK-instrument
file into a single, MIDI-compatible format file. The instrument-change
data is put directly within the MIDI file. This means you can distribute
music files without bothering with the huge, and mostly unused, instru-
ment bank file.
To convert any .ROL file to MIDI:
C>ROL2MIDI filename /Bbankfile /Onewfile
For example, to convert MANALISH.ROL to MANALISH.MDI using the standard
instrument bankfile:
C>ROL2MIDI manalish.rol /Bstandard.bnk /Omanalish.mdi
This shareware release of QBXSOUND documents the high-level MIDI music
and VOC input/output routines. In all, just 13 routines:
MusicInit(), MusicInfo(), MusicPlay(), MusicPause(), MusicCont(), and
MusicEnd() for playing MIDI music files via the AdLib or Sound
Blaster;
VOCinit(), VOCinfo(), VOCplay(), VOCrecord(), VOCpause(), VOCcont(),
and VOCend() for playing and recording digital files via the Sound
Blaster.
There are 66 additional routines that are available in the Professional-
level package. See the included QBXSOUND.BI file for a listing sampler.
QBXSOUND v1.0 ORDER FORM
Qty Extended
QBXSOUND v1.0 Programmer version. . . $ 9.95 x _____ = __________
- link LIB for QuickBASIC 4.0a, 4.0b, 4.5 ONLY
- Programmer's edition manual, on disk
-OR-
QBXSOUND v1.0 Professional version . .$49.95 x _____ = __________
- link LIBs for QuickBASIC 4.0a, 4.0b, 4.5, and QBX/BC 7.x
- all BASIC source code included
- Professional edition printed manual, bound
Subtotal: __________
(Texas residents only add 8.25%) Sales tax: __________
SHIPPING COSTS USA CAN Foreign Shipping costs: __________
Programmer : none $1.00 $ 2.00
Professional : none 5.00 5.00 TOTAL: $
==========
Please remit TOTAL amount in US funds on US bank only, to:
Cornel Huth
6402 Ingram Rd.
San Antonio, Texas 78238 U.S.A.
Disk will be 5.25-inch 360K unless otherwise requested. Add $1.00 for
3.5-inch disk.
Name: ___________________________________________________________
Mailing address: ________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
Special instructions or comments (continue on reverse if needed):
Please indicate how you obtained QBXSND 1.0. If from a BBS please
indicate which one and its telephone number:
_________________________________________________________________
BBS:_____________________________ Tele: ( )______-___________
Routines used to control play of a MIDI music file:
DECLARE FUNCTION MusicInit (useEvent%)
DECLARE FUNCTION MusicPlay% (MBseg%, MBoff%)
DECLARE FUNCTION MusicInfo%(voice%,note%,volume%,mode%,MusicPtr&)
DECLARE SUB MusicPause ()
DECLARE SUB MusicCont ()
DECLARE SUB MusicEnd ()
Routines used to control play of a VOC digital file:
DECLARE FUNCTION VOCinit% (port%, IRQ%, DMA%)
DECLARE FUNCTION VOCinfo% (CurrBlockType%, CurrSampleRate%)
DECLARE FUNCTION VOCplay% (VBseg%, VBoff%)
DECLARE FUNCTION VOCrecord% (SampleRate%, bytes&, VBseg%, VBoff%)
DECLARE SUB VOCpause% ()
DECLARE SUB VOCcont% ()
DECLARE SUB VOCend% ()
Note that the Sound Blaster will play both music and VOC. The AdLib,
however, will only play music.
Note that the Music() routines use the UEVENT handler that is available
only in QuickBASIC versions 4.0a and above. This Microsoft routine was
not available in the initial release of QuickBASIC 4.00. To see what
version you have, run your BC compiler. If it says 'Compiler Version
4.00a' or above then your compiler is sufficient to use QBXSOUND.
Note that the Music() routines use the UEVENT handler. Since other code
may also be using the UEVENT signal, QBXSOUND first checks to make sure
that the UEVENT triggered is for QBXSOUND. If not, control can be passed
to another handler, e.g., your specialized mouse handler, or other
handler. This is available only in the Professional-level package.
It is not necessary for you to understand what UEVENT is, but you should
be aware that it is being used. When compiling, you need to include the
/V switch.
MUSICINIT
TYPE FUNCTION
SYNTAX stat = MusicInit(UseEVENT)
PARAMETERS UseEVENT - INTEGER. Determine if music is to be played in
the background.
USE If UseEVENT is non-zero then UEVENT trapping is used,
allowing the music to be played in the background. If
UseEVENT = 0 then the music is played in the foreground.
The difference is very apparent: With UseEVENT non-zero,
MusicPlay() returns immediately; with UseEVENT = 0,
MusicPlay() will not return until the music is over.
RULES This routine must be called before any other Music()
routine.
NOTES Setting UseEVENT=0 can make debugging easier, especially if
you're using CodeView.
The previous verison could not play music in the background
while in the QB 4b/4.5 environment. This has been fixed.
RETURN 0=FM music chip tests okay
1=AdLib-compatible test failed
EXAMPLE IF DEBUG THEN UseEVENT = 0 ELSE UseEVENT = 1
stat = MusicInit(UseEVENT)
IF stat THEN DoNoAdLibCard
MUSICPLAY
TYPE FUNCTION
SYNTAX stat = MusicPlay(MBseg,MBoff)
PARAMETERS MBseg - INTEGER. Segment address of music buffer.
MBoff - INTEGER. Offset address of music buffer.
USE Initiate the playing of the music data in the memory buffer
pointed to by MBseg:MBoff. MBseg and MBoff are determined
by using the BASIC functions VARSEG() and VARPTR().
RULES The music buffer must contain no more than 65,520 bytes of
data, i.e., the MIDI filesize must not be larger than 65520
bytes (about 5-20 minutes of music). It is recommended that
the buffer be created as an array. This ensures that the
offset will start at 0.
NOTES An easy way to set up a music buffer is to TYPE a variable
as STRING * 8192 and then allocate an array of from 1 to 8
of those, depending on what's required. See the example.
RETURN Always 1.
EXAMPLE TYPE BigChunkTYPE
BigChunk AS STRING * 8192
END TYPE
REDIM SHARED mbuff(1 TO 1) AS BigChunkTYPE
OPEN midifile$ FOR BINARY AS #1
length& = LOF(1)
IF length& > 65520 THEN ERROR 7
blocks = (length& \ 8192)
IF length& MOD 8192 THEN blocks = blocks + 1
REDIM mbuff(1 TO blocks) AS BigChunkTYPE
ss = 1 'read 8K of the file at a time
DO WHILE NOT EOF(1)
GET #1, , mbuff(ss).BigChunk
ss = ss + 1
LOOP
CLOSE #1
MBseg = VARSEG(mbuff(1))
MBoff = VARPTR(mbuff(1))
stat = MusicPlay(MBseg, MBoff)
MUSICINFO
TYPE FUNCTION
SYNTAX stat = MusicInfo(voice,note,volume,mode,MusicPtr&)
PARAMETERS voice - INTEGER. Determine which voice to get info on.
note - INTEGER. Returned last note output of voice (range
0-127).
volume - INTEGER. Returned last volume level of voice
(range 0-127).
mode - INTEGER. Returned current FM chip mode (0 or 1).
MusicPtr& - LONG. Returned current byte pointer into the
music data that is being played.
USE Obtain basic information on the state of the music file
being played.
RULES None.
NOTES This routine needs to be called to determine if the MIDI
data is still being played.
Mode 0 is melodic mode where there are 9 voices available
(0-8). Mode 1 is percussive mode where 6 melodic voice are
available plus 5 percussive voices (0-5 plus bass drum,
snare drum, tom-tom, top-cymbal, and hi-hat).
RETURN 0 music is done playing
1 music is still playing
-1 if voice invalid
EXAMPLE 'determine the last note and volume played by each voice
'music already started
stat = MusicInfo(voice,note,vol,mode,musicptr&)
IF mode = 0 THEN MaxVoice = 8 ELSE MaxVoice = 10
DO
FOR i = 0 TO MaxVoice
stat = MusicInfo(i,note,vol,mode,musicptr&)
PRINT "Voice:";i;" Vol:";vol;" Note:";note
NEXT
LOOP UNTIL stat = 0
'wait until the music is done before ending
END
MUSICPAUSE
TYPE SUB
SYNTAX MusicPause
PARAMETERS None.
USE Pause the music output temporarily.
RULES None.
NOTES This routine is useful if you are using any code that uses
DEF SEG =. For instance, if you are reading/writing to the
video screen using peeks and pokes with DEF SEG to point to
and from your screen buffer and the video screen, you
should first MusicPause() and then, when you're done using
DEF SEG, use MusicCont(). If you keep the time short you
may not even notice the pause.
Any time you get input via BASIC's INPUT routine the music
is automatically paused. It continues when INPUT is
received.
RETURNS Nothing.
EXAMPLE 'music is already playing
DO
a$ = INKEY$
IF a$ = "p" THEN MusicPause
IF a$ = "c" THEN MusicCont
IF a$ = "x" THEN MusicEnd
LOOP
MUSICCONT
TYPE SUB
SYNTAX MusicCont
PARAMETERS None.
USE Continue the music output if paused.
RULES None.
NOTES See MusicPause.
RETURNS Nothing.
EXAMPLE 'music is already playing
DO
a$ = INKEY$
IF a$ = "p" THEN MusicPause
IF a$ = "c" THEN MusicCont
IF a$ = "x" THEN MusicEnd
LOOP
MUSICEND
TYPE SUB
SYNTAX MusicEnd
PARAMETERS None.
USE Shut down the music player.
RULES This routine should be called before ending your program.
NOTES None.
RETURNS Nothing.
EXAMPLE 'music is already playing
DO
a$ = INKEY$
IF a$ = "p" THEN MusicPause
IF a$ = "c" THEN MusicCont
IF a$ = "x" THEN MusicEnd
LOOP
VOCINIT
TYPE FUNCTION
SYNTAX stat = VOCinit(port,IRQ,DMA)
PARAMETERS port - INTEGER. Determine what port to use, or to auto-
check Sound Blaster configuration.
IRQ - INTEGER. Determine what IRQ to use, or to auto-check
Sound Blaster configuration.
DMA - INTEGER. Determine what DMA channel to use.
USE If either port or IRQ is 0 then QBXSOUND will automatically
determine the configuration of the Sound Blaster card. If
neither is 0 then the port and IRQ supplied will be used to
determine if the Sound Blaster is installed.
Currently the Sound Blaster supports only DMA channel 1.
RULES This routine must be called before any other VOC() routine.
NOTES If you want to know the configuration of the Sound Blaster
see the example below.
RETURN 0=Sound Blaster digital I/O tests okay
1=no Sound Blaster
2=IRQ test fails
3=DMA test fails
EXAMPLE port = 0 : IRQ = 0 : DMA = 1
stat = VOCinit(port,IRQ,DMA)
IF stat = 0 THEN
PRINT "SB at port:";port;" IRQ:";IRQ
ELSE
PRINT "SB failed";stat
ENDIF
VOCPLAY
TYPE FUNCTION
SYNTAX stat = VOCplay(VBseg,VBoff)
PARAMETERS VBseg - INTEGER. Segment address of VOC buffer.
VBoff - INTEGER. Offset address of VOC buffer.
USE Initiate the playing of the digital VOC data in the memory
buffer pointed to by VBseg:MBoff. VBseg and VBoff are
determined by using the BASIC functions VARSEG() and
VARPTR().
RULES The VOC buffer may be any size available.
NOTES An easy way to set up a VOC buffer is to TYPE a variable as
STRING * 8192 and then allocate an array of those, depend-
ing on what's required. See the example. If you plan on
having a buffer larger than 64K be sure to startup QB with
the /AH switch. Same goes for BC.
The data at VBseg:VBoff should have a valid VOXKIT header,
as created by VOXKIT itself, or by the VOC-HDR program
(both came with your Sound Blaster).
RETURN 0=okay
1=voice already being output (busy)
EXAMPLE TYPE BigChunkTYPE
BigChunk AS STRING * 8192
END TYPE
OPEN vocfile$ FOR BINARY AS #1
length& = LOF(1)
blocks = (length& \ 8192)
IF length& MOD 8192 THEN blocks = blocks + 1
REDIM vbuff(1 TO blocks) AS BigChunkTYPE
ss = 1 'read 8K of the file at a time
DO WHILE NOT EOF(1)
GET #1, , vbuff(ss).BigChunk
ss = ss + 1
LOOP
CLOSE #1
VBseg = VARSEG(vbuff(1))
VBoff = VARPTR(vbuff(1))
stat = VOCplay(VBseg, VBoff)
VOCRECORD
TYPE FUNCTION
SYNTAX stat = VOCrecord(SampleRate,bytes&,VBseg,VBoff)
PARAMETERS SampleRate - INTEGER. The rate at which to sample the
recording at.
bytes& - LONG. The number of bytes& to record.
VBseg - INTEGER. Segment address of VOC buffer.
VBoff - INTEGER. Offset address of VOC buffer.
USE Initiate the recording of digital data into the memory
buffer pointed to by VBseg:MBoff for the number of bytes&.
VBseg and VBoff are determined by using the BASIC functions
VARSEG() and VARPTR().
RULES The VOC buffer may be any size available but at least the
size of bytes&.
SampleRate may be 5000 to 11000 (samples/second).
NOTES Time of recording is bytes& / SampleRate.
An easy way to set up a VOC buffer is to TYPE a variable as
STRING * 8192 and then allocate an array of those, depend-
ing on what's required. See the example. If you plan on
having a buffer larger than 64K be sure to startup QB with
the /AH switch. Same goes for BC.
QBXSOUND will place the data recorded at VBseg:VBoff. This
will be the data itself--no header is built. VOCplay() will
play this data even without the VOXKIT header.
RETURN 0=okay
1=voice already being output (busy)
EXAMPLE secs = 10 : SR = 11000 'sample at 11kHz for 10 seconds
bytes& = 1& * secs * SR '110,000 bytes
blocks = (bytes& \ 8192)
IF bytes& MOD 8192 THEN blocks = blocks + 1
REDIM vbuff(1 TO blocks) AS BigChunkTYPE
INPUT "Press <Enter> to record";a$
VBseg = VARSEG(vbuff(1)) : VBoff = VARPTR(vbuff(1))
stat = VOCrecord(SR,bytes&,VBseg, VBoff)
DO
stat = VOCinfo(CBT,CSR) 'wait until done recording
LOOP UNTIL stat = 0
INPUT "Press <Enter> to playback";a$
stat = VOCplay(VBseg,VBoff) 'play it back
DO:LOOP UNTIL VOCinfo(CBT,CSR) = 0
END
VOCINFO
TYPE FUNCTION
SYNTAX stat = VOCinfo(CurrBlockType,CurrSampleRate)
PARAMETERS CurrBlockType - INTEGER. Returned block type.
CurrSampleRate - INTEGER. Returned sample rate.
USE Obtain basic information on the state of the VOC data being
output.
RULES None.
NOTES This routine needs to be called to determine if the VOC
data is still being output.
The block type and sample rate are explained in the Profes-
sional package.
RETURN 0 VOC is over
1 VOC is being output
EXAMPLE 'determine when the VOC data is done
'VOC already started
DO
stat = VOCinfo(CBT,CSR)
IF stat THEN DoSomethingElse
LOOP UNTIL stat = 0
VOCPAUSE
TYPE SUB
SYNTAX VOCpause
PARAMETERS None.
USE Pause the VOC output temporarily.
RULES None.
NOTES None.
RETURNS Nothing.
EXAMPLE 'VOC is already playing
DO
a$ = INKEY$
IF a$ = "p" THEN VOCpause
IF a$ = "c" THEN VOCcont
IF a$ = "x" THEN VOCend
LOOP
VOCCONT
TYPE SUB
SYNTAX VOCcont
PARAMETERS None.
USE Continue the VOC output if paused.
RULES None.
NOTES See VOCpause.
RETURNS Nothing.
EXAMPLE 'VOC is already playing
DO
a$ = INKEY$
IF a$ = "p" THEN VOCpause
IF a$ = "c" THEN VOCcont
IF a$ = "x" THEN VOCend
LOOP
VOCEND
TYPE SUB
SYNTAX VOCend
PARAMETERS None.
USE Shut down the VOC player.
RULES This routine should be called before ending your program.
NOTES None.
RETURNS Nothing.
EXAMPLE 'VOC is already playing
DO
a$ = INKEY$
IF a$ = "p" THEN VOCpause
IF a$ = "c" THEN VOCcont
IF a$ = "x" THEN VOCend
LOOP
End of document, shareware edition.
QBXSOUND
Version 1.0, 21-Oct-1991
(C)1991 Cornel Huth -- All Rights Reserved.