home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / prg / dsik205 / dsik.dat / MANUAL.TXT < prev    next >
Text File  |  1995-04-10  |  31KB  |  734 lines

  1. -----------------------------------------------------------------------------
  2.                      Digital Sound Interface Kit (DSIK)
  3.                                 Version 2.00
  4.  
  5.                              -- User's Manual --
  6.  
  7.          Copyright (c) 1993-95 by Carlos Hasan. All Rights Reserved.
  8. -----------------------------------------------------------------------------
  9.  
  10. Table of Contents:
  11.  
  12.     1.      Introduction
  13.     1.1     What's in this Manual?
  14.     1.2     Hardware Requirements
  15.     1.3     Installing the Software
  16.     1.4     Contacting the Author
  17.  
  18.     2.      Tutorial
  19.     2.1     Initializing DSIK
  20.     2.2     Playing Digital Samples
  21.     2.3     Playing a Music Module
  22.     2.4     Playing Sound Effects over Music
  23.  
  24.     3.      Programming Guide
  25.     3.1     Initializing DSIK
  26.     3.2     Openining Voice Channels
  27.     3.3     Mixing Voices
  28.     3.4     Playing Music
  29.     3.4.1   Loading a Module
  30.     3.4.2   Playing the Module
  31.     3.4.3   Stopping the Module
  32.     3.5     Sound Effects
  33.     3.5.1   Channels
  34.     3.5.2   Available Channels
  35.     3.5.3   Playing Sounds
  36.     3.5.4   Altering the Playing Sounds
  37.     3.6     Digital Sound Module Format
  38.     3.6.1   Converting Modules
  39.     3.7     Getting Information from DSIK
  40.     3.8     Interrupts
  41.     3.9     Using Timer Services
  42.  
  43.  
  44.  
  45. Chapter 1. Introduction
  46. -----------------------------------------------------------------------------
  47.  
  48.     The Digital Sound Interface Kit (DSIK) version 2.0 is a interface
  49.     library written in 32-bit protected mode by which you can play music
  50.     modules and sound effects on IBM PCs and is currently available for
  51.     WATCOM C/C++ compiler 9.5 or later.
  52.  
  53. 1.1 What's in this Manual?
  54.  
  55.     This manual has two parts: Tutorial and Programming Guide sections.
  56.     The tutorial section of this manual will show you only the most basic
  57.     functions of DSIK. You should read the Programming Guide section to
  58.     learn more about the DSIK's capabilities. For more detailed information
  59.     about every function, structure and equates defined in DSIK you should
  60.     read the Reference Guide decument.
  61.  
  62. 1.2 Hardware and Software Requirements
  63.  
  64.     In order to work with DSIK you need at least an 80386 processor and
  65.     a soundcard device. The following soundcards are supported:
  66.  
  67.         - Sound Blaster 1.x
  68.         - Sound Blaster 2.x
  69.         - Sound Blaster Pro
  70.         - Sound Blaster 16
  71.         - Pro Audio Spectrum
  72.         - Pro Audio Spectrum+
  73.         - Pro Audio Spectrum 16
  74.         - Windows Sound System
  75.         - Gravis UltraSound
  76.  
  77.     and all cards that are 100% register compatible with any of the above
  78.     soundcards (ie. Logitech SoundMan 16, Sound Galaxy Pro, Audiotrix Pro,
  79.     Gravis UltraSound Max, Aria soundcard, etc).
  80.  
  81. 1.3 Installing the Software
  82.  
  83.     DSIK comes on a single high density diskette containing the object
  84.     libraries, C source files, example programs and document files.
  85.  
  86.     Run the INSTALL.BAT batch file on the diskette and follow it is
  87.     instructions. When it finishes installing the files, you need to
  88.     modify your WATCOM C/C++ programming environment to recognize the
  89.     DSIK sound system.
  90.  
  91.     Modify your WLSYSTEM.LNK linker initialization file to specify where
  92.     are the sound system .LIB library files, and your INCLUDE environment
  93.     variable to specify where are the sound system .H include files.
  94.  
  95.     For example, if you install the software in the C:\DSIK directory and
  96.     the WATCOM C/C++ compiler is installed in the C:\WATCOMC directory,
  97.     your AUTOEXEC.BAT startup batch file may look like:
  98.  
  99.     @echo off
  100.     prompt $p$g
  101.     path c:\dos;c:\watcomc\bin;c:\watcomc\binb
  102.     set watcom=c:\watcomc
  103.     set include=c:\watcomc\h;c:\dsik\include
  104.     set dos4gpath=c:\watcomc\bin\dos4gw.exe
  105.  
  106.     and your WLSYSTEM.LNK linker initialization file:
  107.  
  108.     # linker initialization file
  109.     system begin dos4g
  110.         option osname='Rational Systems'
  111.         libpath %WATCOM%\lib386
  112.         libpath %WATCOM%\lib386\dos
  113.         libpath c:\dsik\lib
  114.         op stub=wstub.exe
  115.         format os2 le
  116.     end
  117.  
  118.     You can also use command line options to specify the location of the
  119.     include and library files. For example, to make the EXAMPLE.C file
  120.     you can type at the DOS prompt:
  121.  
  122.     wcl386 example.c -i=c:\dsik\include -"libpath c:\dsik\lib"
  123.  
  124.     Check out the Makefile included in the EXAMPLES directory for more
  125.     information about how to compile DSIK applications.
  126.  
  127. 1.4 Contacting the Author
  128.  
  129.     If you encounter problems, find a bug in this package or want to suggest
  130.     something, use the following Internet email addresses:
  131.  
  132.         Carlos Hasan
  133.         chasan@cec.uchile.cl
  134.         chasan@dcc.uchile.cl
  135.  
  136.  
  137. Chapter 2. Tutorial
  138. -----------------------------------------------------------------------------
  139.  
  140.     This tutorial will show you how to use DSIK in your own applications
  141.     by providing some simple example programs. These example programs
  142.     will be built from scratch and new features will be added step by
  143.     step through the tutorial.
  144.  
  145. 2.1 Initializing DSIK
  146.  
  147.     Before using any of the DSIK's routines it has to be initialized. First
  148.     you need your soundcard hardware parameters. To ease things there is an
  149.     external program called SETUP which will ask to the user the soundcard
  150.     parameters and will save them into your disk. After, you can load these
  151.     hardware parameters from disk in your own programs. When you have all
  152.     the soundcard parameters, call the routine dRegisterDrivers and then
  153.     dInit to initialize the DSIK sound system.
  154.     Now the program would be able to play sounds on different channels,
  155.     and music modules of course.
  156.  
  157.     Here is an example code for initializing DSIK:
  158.  
  159.     #include <stdio.h>
  160.     #include <stdlib.h>
  161.     #include "audio.h"
  162.  
  163.     int main(void)
  164.     {
  165.         SoundCard SC;
  166.  
  167.         dRegisterDrivers();
  168.         if (dLoadSetup(&SC,"SETUP.CFG")) {
  169.             printf("Please run SETUP.EXE to configure.\n");
  170.             exit(EXIT_FAILURE);
  171.         }
  172.         if (dInit(&SC)) {
  173.             printf("Error initializing the sound system.\n");
  174.             exit(EXIT_FAILURE);
  175.         }
  176.         atexit(dDone);
  177.         :
  178.         :
  179.     }
  180.  
  181.     If everything went alright and dInit found the specified soundcard it
  182.     returns zero. After dInit has initialized the system, you must call
  183.     the deinitialization routine dDone before exiting from your program.
  184.  
  185.  
  186. 2.2 Playing Digital Samples
  187.  
  188.     DSIK is now initialized and waits for your instructions. But first you
  189.     have to setup the amount of voices you are going to use and the master
  190.     volume level (or amplification factor) for all these voices:
  191.  
  192.     dSetupVoices(4,96);
  193.  
  194.     Now you have four independant channels to play sounds. To play a digital
  195.     sample (or instrument) you have to load the sample from disk, then pass
  196.     it to dPlayVoice to start playing the sample. DSIK currently supports
  197.     many sound sample file formats which can be loaded from disk using
  198.     the import routine dImportSample. Also, you can use dLoadSample to
  199.     load RIFF/WAVE sample files:
  200.  
  201.     #include <stdio.h>
  202.     #include <stdlib.h>
  203.     #include <conio.h>
  204.     #include "audio.h"
  205.  
  206.     int main(void)
  207.     {
  208.         SoundCard SC;
  209.         Sample *Drum;
  210.  
  211.         dRegisterDrivers();
  212.         if (dLoadSetup(&SC,"SETUP.CFG") || dInit(&SC))
  213.             exit(EXIT_FAILURE);
  214.         atexit(dDone);
  215.         dSetupVoices(4,96);
  216.         if (!(Drum = dLoadSample("DRUM.WAV")))
  217.             exit(EXIT_FAILURE);
  218.         dPlayVoice(0,Drum);
  219.         while (!kbhit()) dPoll();
  220.         dStopVoice(0);
  221.         dFreeSample(Drum);
  222.     }
  223.  
  224.     The previous code loads a digital instrument from disk and plays it on
  225.     the first audio channel at the default frequency and volume.
  226.  
  227. 2.3 Playing a Music Module
  228.  
  229.     Module is a music file format first used in the Amiga computer. There
  230.     are many music formats around like: ProTracker, FastTracker, Scream
  231.     Tracker, Composer 669, and MultiTracker file formats.
  232.     The DSIK sound system supports the RIFF/DSMF file format. You can use
  233.     the M2DSM.EXE utility to convert other files formats to RIFF/DSMF or
  234.     you can use the dImportModule import routine to load other module file
  235.     formats from your own program at runtime.
  236.     Here is an simple example program to play an RIFF/DSMF module file:
  237.  
  238.     #include <stdio.h>
  239.     #include <stdlib.h>
  240.     #include <conio.h>
  241.     #include "audio.h"
  242.  
  243.     int main(void)
  244.     {
  245.         SoundCard SC;
  246.         DSM *M;
  247.  
  248.         dRegisterDrivers();
  249.         if (dLoadSetup(&SC,"SETUP.CFG") || dInit(&SC))
  250.             exit(EXIT_FAILURE);
  251.         atexit(dDone);
  252.         if (!(M = dLoadModule("SONG.DSM")))
  253.             exit(EXIT_FAILURE);
  254.         dSetupVoices(M->Header.NumTracks,M->Header.MasterVolume);
  255.         dPlayMusic(M);
  256.         while (!kbhit()) dPoll();
  257.         dStopMusic();
  258.         dFreeModule(M);
  259.     }
  260.  
  261.     When running the program it should play the SONG.DSM module. If there
  262.     are problems, check that the module exists in the current directory.
  263.  
  264. 2.4 Playing Sound Effects over Music
  265.  
  266.     With DSIK it's possible to play sound effects over the music. All you
  267.     have to do is to open more voices than your module needs. The extra
  268.     voices can be used to play sound effects. Remember that DSIK always
  269.     uses the first voices to play the music.
  270.     For example, if you open 8 voices using dSetupVoices and then you
  271.     start playing a 4-track module file, the voices 4-7 can be used to
  272.     play your own sound effects over the music.
  273.  
  274.  
  275. Chapter 3. Programming Guide
  276. -----------------------------------------------------------------------------
  277.  
  278.     In this section you will learn more about all the DSIK's capabilities.
  279.     It describes not only what DSIK can do, but also how. For more details
  280.     about every function and structures defined in DSIK you should read the
  281.     Reference Guide document.
  282.  
  283. 3.1 Initializing DSIK
  284.  
  285.     The first thing you should do to initialize DSIK is to get the soundcard
  286.     hardware parameters: base port address, IRQ interrupt line, DMA channel,
  287.     sampling rate, etc. The structure SoundCard holds this information:
  288.  
  289.     typedef struct {
  290.         byte    ID;                 /* soundcard identifier value       */
  291.         byte    Modes;              /* output mode (ie. 16-bit stereo)  */
  292.         word    Port;               /* base I/O port address            */
  293.         byte    IrqLine;            /* IRQ interrupt line               */
  294.         byte    DmaChannel;         /* output DMA channel               */
  295.         word    SampleRate;         /* sampling rate (in hertz)         */
  296.         char    DriverName[16];     /* DLL driver file name             */
  297.     } SoundCard;
  298.  
  299.     The identification number ID is unique for each soundcard. The currently
  300.     supported soundcard identifier values are the following:
  301.  
  302.     #define ID_NONE         0       /* no sound                 */
  303.     #define ID_SB           1       /* Sound Blaster            */
  304.     #define ID_SB201        2       /* Sound Blaster 2.01       */
  305.     #define ID_SBPRO        3       /* Sound Blaster Pro        */
  306.     #define ID_SB16         4       /* Sound Blaster 16         */
  307.     #define ID_PAS          5       /* Pro Audio Spectrum       */
  308.     #define ID_PASPLUS      6       /* Pro Audio Spectrum+      */
  309.     #define ID_PAS16        7       /* Pro Audio Spectrum 16    */
  310.     #define ID_WSS          8       /* Windows Sound System     */
  311.     #define ID_GUS          9       /* Gravis UltraSound        */
  312.  
  313.     There are parameters which are unused for some soundcards (for example,
  314.     the GUS soundcard does not requires the sample rate). Also, the virtual
  315.     soundcard ID_NONE is useful for users without any sound device, because
  316.     your program can use all the DSIK functions without problems, but no
  317.     sound will be heard though.
  318.  
  319.     The Modes field specifies the output format used. For example, you can
  320.     specify 8-bit mono, 8-bit stereo, 16-bit mono or 16-bit stereo output
  321.     mode. Notice that some soundcards may not support all these formats;
  322.     monophonic cards can not play in stereo, and 8-bit cards can not play
  323.     at 16-bits of resolution. The following equates are defined:
  324.  
  325.     #define AF_8BITS        0x00    /* 8-bits per sample    */
  326.     #define AF_16BITS       0x01    /* 16-bits per sample   */
  327.     #define AF_MONO         0x00    /* mono output          */
  328.     #define AF_STEREO       0x02    /* stereo output        */
  329.  
  330.     When the SoundCard structure is filled call dInit routine to initialize
  331.     the sound system. If everything went alright this routine will return
  332.     a zero value. Notice that the specified sound driver must be registered
  333.     before calling dInit, because the sound system only knows registered
  334.     sound drivers. Here is an example:
  335.  
  336.     #include <stdio.h>
  337.     #include <stdlib.h>
  338.     #include "audio.h"
  339.  
  340.     int main(void)
  341.     {
  342.         SoundCard SC;
  343.  
  344.         SC.ID = ID_SB16;
  345.         SC.Modes = AF_16BITS | AF_STEREO;
  346.         SC.Port = 0x220;
  347.         SC.IrqLine = 5;
  348.         SC.DmaChannel = 5;
  349.         SC.SampleRate = 44100;
  350.  
  351.         dRegisterDrivers();
  352.         if (dInit(&SC)) {
  353.             printf("Error initializing the sound system.\n");
  354.             exit(EXIT_FAILURE);
  355.         }
  356.         atexit(dDone);
  357.         :
  358.         :
  359.     }
  360.  
  361.     The above example will initialize the system using a Sound Blaster 16
  362.     playing at 16-bit stereo 44100 Hz configured at Port 0x220, IRQ 5 and
  363.     DMA channel 5 (the driver filename field is not required here).
  364.  
  365.     I suggest to use dLoadSetup to fill the SoundCard structure, or you
  366.     can use the dAutoDetect soundcard autodetection routine to fill out
  367.     this structure. However, the current autodetection routine is not
  368.     perfect, so I highly suggest to use dLoadSetup and SETUP.EXE to get
  369.     your soundcard parameters.
  370.  
  371.     After initializing DSIK you should make sure that dDone is called upon
  372.     exit. The easiest way to do it is to use the atexit machanism.
  373.  
  374. 3.2 Opening Voice Channels
  375.  
  376.     Now DSIK is initialized, but you can't play any sound with it yet. First
  377.     you will have to call dSetupVoices to specify the amount of voices that
  378.     your program needs and the master volume level:
  379.  
  380.     dSetupVoices(8,96);
  381.  
  382.     The above line will open 8 voices and set the master volume level. The
  383.     master volume (or amplification factor) is used only for 8-bit output
  384.     modes. It is very useful to make the sound much more dynamic and clean
  385.     on 8-bit soundcards. This value specifies the dynamic range of every
  386.     digital voice. A suggested value for this parameter is:
  387.  
  388.     MasterVolume = min(255,768/NumVoices);
  389.  
  390.     When you change the amount of open voices in your programs, be sure
  391.     to turn off all the currently active voices and the music module before
  392.     you call dSetupVoices. You can use dStopVoice and dStopMusic for it.
  393.  
  394. 3.3 Mixing Voices
  395.  
  396.     When everything is initialized it's time to start playing some sounds.
  397.     Before any sound can be heard it has to be loaded from disk. Because
  398.     DSIK supports many more channels than your soundcard supports (except
  399.     for the GUS), DSIK has to combine many channels into a single channel,
  400.     this process is called digital mixing or waveform synthesis.
  401.  
  402.     DSIK lets you do the mixing whenever you want to do it. It does not
  403.     force you to use the timer interrupt, all that DSIK requires is to call
  404.     the function dPoll frequently. Actually this is not required if you are
  405.     using the GUS soundcard which uses his own interrupt service to poll the
  406.     sound system.
  407.  
  408.     To play music and sound effects in background, you only need to call
  409.     dPoll regularly at least 50 times per second. You can call it at any
  410.     rate greater than 50 times per second, and even at irregular intervals
  411.     if required by your application.
  412.     If you hear small cracks and the music sounds like a broken record, it
  413.     means that you need to call dPoll much more frequently.
  414.  
  415.     If you want a timer interrupt to handle all the mixing, you can easily
  416.     hook the dPoll into the timer interrupt service:
  417.  
  418.     #include <stdio.h>
  419.     #include <stdlib.h>
  420.     #include "audio.h"
  421.     #include "timer.h"
  422.  
  423.     int main(void)
  424.     {
  425.         SoundCard SC;
  426.  
  427.         dRegisterDrivers();
  428.         if (dLoadSetup(&SC,"SETUP.CFG") || dInit(&SC))
  429.             exit(EXIT_FAILURE);
  430.         atexit(dDone);
  431.         dInitTimer();
  432.         atexit(dDoneTimer);
  433.         dStartTimer(dPoll,TICKS(70));
  434.         :
  435.         :
  436.     }
  437.  
  438.     The previous code will use the timer interrupt to call dPoll 70 times
  439.     per second. Notice that the BIOS clock will be updated while using the
  440.     timer services.
  441.  
  442.  
  443. 3.4 Playing Music
  444.  
  445.     After DSIK has been setup to play sounds, you are allowed to play music
  446.     modules. As DSIK uses his own music module format, it's necessary to use
  447.     the utility M2DSM.EXE to convert standard MODs, STMs, 669s, S3Ms and MTMs
  448.     to RIFF/DSMF file format or you can use the import routines to load
  449.     other file formats directly from your programs at runtime.
  450.  
  451. 3.4.1 Loading a Module
  452.  
  453.     Before any music can be played it has to be loaded from the disk into
  454.     system memory (and soundcard memory for the GUS driver). The module
  455.     loader is called as follows:
  456.  
  457.     Module = dLoadModule(Filename);
  458.  
  459.     If you want to load other module file formats:
  460.  
  461.     Module = dImportModule(Filename,Format);
  462.  
  463.     The Filename parameter is the full path name of the module file, and
  464.     the Format parameter for the import routine specifies the module file
  465.     format of the file:
  466.  
  467.     #define FORM_DSM    0x00        /* RIFF/DSMF module file        */
  468.     #define FORM_MOD    0x01        /* Protracker modules           */
  469.     #define FORM_S3M    0x02        /* Scream Tracker 3.0 modules   */
  470.     #define FORM_MTM    0x03        /* Multitracker 1.0 modules     */
  471.     #define FORM_669    0x04        /* Composer 669 modules         */
  472.     #define FORM_STM    0x05        /* Scream Tracker 2.0 modules   */
  473.  
  474.     The loader returns a pointer to a DSM structure. If something went wrong,
  475.     NULL is returned and the global variable dError is set to one of the
  476.     following values to indicate the error occurred:
  477.  
  478.     #define ERR_OK          0       /* no error                     */
  479.     #define ERR_FORMAT      1       /* invalid/unsupported format   */
  480.     #define ERR_NOFILE      2       /* file not found               */
  481.     #define ERR_FILEIO      3       /* error reading file           */
  482.     #define ERR_NOMEM       4       /* not enough system memory     */
  483.     #define ERR_NODRAM      5       /* not enough soundcard memory  */
  484.  
  485.     The DSM structure contains all the information about the module, so it
  486.     is totally possible to load multiple modules into memory.
  487.  
  488. 3.4.2 Playing the Module
  489.  
  490.     When the module has been loaded into memory it can be played with a
  491.     single function call:
  492.  
  493.     dPlayMusic(Module);
  494.  
  495.     The parameter is a pointer to a variable of type DSM. If you have set up
  496.     DSIK correctly and mixing routines are called frequently, you should hear
  497.     the music playing in background. If you don't hear any music and no error
  498.     was detected, then something went wrong during initialization (probably
  499.     the soundcard hardware parameters are wrong).
  500.  
  501. 3.4.3 Stopping the Module
  502.  
  503.     If you want to stop the module which is currently being played, call the
  504.     routine dStopMusic. If the module looping is enabled, the module will
  505.     not stop playing until dStopMusic is called. If you want to enable the
  506.     looping for a module, you can do the following:
  507.  
  508.     Module->Header.ReStart = 0;
  509.  
  510.     The above line will tell to the sound system to restart playing the
  511.     song at the first order position in the sequence list.
  512.  
  513. 3.5 Sound effects
  514.  
  515.     Playing modules in the background is a thing that can be achieved with
  516.     DSIK, but also you can play sound effects simultaneous with music.
  517.  
  518. 3.5.1 Channels
  519.  
  520.     First you need to know the amount of voices that your program will
  521.     need to play the music and sound effects. For example, if you are going
  522.     to play a 4-track module and also you want stereo sound effects, you
  523.     need to open 6 channels (four for music and two for the sound effect
  524.     channels). To open the desired amount of channels you does:
  525.  
  526.     dSetupVoices(NumChannels,MasterVolume);
  527.  
  528.     The first parameter is the number of channels you want, and the second
  529.     parameter is the master volume level (or amplification factor).
  530.     You can open upto 32 digital voices, every voice can be referenced by
  531.     numbers starting from 0 upto 31. The first voices are enabled when you
  532.     use dSetupVoices. For example, if you open 4 voices for playback the
  533.     channels 0-3 will be enabled.
  534.     You can call dSetupVoices multiple times. However, it can't be called
  535.     while music or sound effects are being played. So be sure to stop all
  536.     the channels before changing the amount of voices (you must use the
  537.     routine dStopMusic to stop the music and dStopVoice to stop sound
  538.     effect channels).
  539.  
  540.  
  541. 3.5.2 Available Channels
  542.  
  543.     You have opened six channels and DSIK is playing a four channel module,
  544.     so the channels four and five are available for your own sound effects.
  545.     DSIK always uses the first channels starting from zero, so you can be
  546.     sure that playing a sample on channel four or five will not interfere
  547.     with the music.
  548.  
  549. 3.5.3 Playing Sounds
  550.  
  551.     When you want to play a sample, you must load it from disk. The function
  552.     dLoadSample load RIFF/WAVE sound files from disk:
  553.  
  554.     Guitar = dLoadSample("GUITAR.WAV");
  555.  
  556.     If you want to load samples in other file formats, you can use the import
  557.     routine to load VOC, IFF/8SVX, or RAW sound files:
  558.  
  559.     Speech = dImportSample("SPEECH.VOC",FORM_VOC);
  560.  
  561.     The second parameter specifies the sound file format. The following file
  562.     formats are currently supported:
  563.  
  564.     #define FORM_WAV    0x80        /* Windows WAVE PCM files       */
  565.     #define FORM_VOC    0x81        /* Creative Labs Voice Files    */
  566.     #define FORM_IFF    0x82        /* Amiga IFF/8SVX sample files  */
  567.     #define FORM_RAW    0x83        /* 8-bit mono RAW sample files  */
  568.  
  569.     To learn more about how to load samples into memory, look at the example
  570.     source files and at the module/sample loading routines.
  571.  
  572.     After the sample has been loaded in memory, you can play it calling
  573.     the dPlayVoice function:
  574.  
  575.     dPlayVoice(Voice,Drum);
  576.  
  577.     where Voice is the channel number and Drum is a pointer to a Sample
  578.     structure. This function will play the sample at the default frequency
  579.     and volume specified in the Sample structure.
  580.  
  581.     The Volume and Rate fields of the Sample structure specifies the default
  582.     volume and the playback frequency. The volume level goes from 0 to 64,
  583.     and the frequency is given in hertz.
  584.  
  585.  
  586. 3.5.4 Altering the Playing Sounds
  587.  
  588.     Now that the sample is being played, it would be nice to change the
  589.     frequency and the volume of the sample. DSIK has functions to make it
  590.     possible. Changing the frequency and volume is as simple as calling:
  591.  
  592.     dSetVoiceFreq(Voice,Freq);
  593.     dSetVoiceVolume(Voice,Volume);
  594.  
  595.     Also you can change the channel panning (or balance):
  596.  
  597.     dSetVoiceBalance(Voice,Balance);
  598.  
  599.     where Balance is a number between 0 (left panned) and 128 (right panned),
  600.     also you can use stereo surround setting the balance to 228. There are
  601.     some useful equates which you can use to set the balance or panning:
  602.  
  603.     #define PAN_LEFT        0x00    /* left balance     */
  604.     #define PAN_MIDDLE      0x40    /* middle balance   */
  605.     #define PAN_RIGHT       0x80    /* right balance    */
  606.     #define PAN_SURROUND    0xA4    /* stereo surround  */
  607.  
  608.     You can also interpole these values to do smooth pannings. Notice that
  609.     this routine only works in stereo cards, and the surround does not work
  610.     for Gravis UltraSound cards.
  611.  
  612. 3.6 Digital Sound Module Format (RIFF/DSMF)
  613.  
  614.     DSIK uses his own music module file format. It was designed to cope with
  615.     a variety of different module formats like MOD, STM, 669, S3M, and MTM.
  616.     It would have been very hard to write a system that supports all those
  617.     module formats, so I have made a system that supports just one format,
  618.     but with a utility and import routines to convert other module formats
  619.     into this RIFF/DSMF module format.
  620.  
  621. 3.6.1 Converting Modules
  622.  
  623.     As DSIK only supports the RIFF/DSMF format, you need to convert MODs,
  624.     STMs, 669s, S3Ms and MTMs into DSMs before playing. You can do this
  625.     manually using the M2DSM.EXE utility. For example, you can type at
  626.     the DOS prompt:
  627.  
  628.     M2DSM NOWWHAT3.MOD
  629.  
  630.     The above line will convert the Protracker/Fastracker module file
  631.     named NOWWHAT3.MOD to a RIFF/DSMF module file.
  632.     Also, you can use the built-in import routines to load other module
  633.     file formats at runtime from your own programs. For example,
  634.  
  635.     Module = dImportModule("NOWWHAT3.MOD",FORM_MOD);
  636.  
  637.     The above line will load the Protracker module file without need to
  638.     previouly translate it to the RIFF/DSMF file format. However, I suggest
  639.     to use RIFF/DSMF module files in your programs, because these files are
  640.     loaded faster and the M2DSM.EXE utility will remove any problem that
  641.     other module files may have. For example, I have seen lots of buggy
  642.     S3M module files created by Scream Tracker 3.0 BETA version.
  643.  
  644. 3.7 Getting Information from DSIK
  645.  
  646.     DSIK can give you information about what is going on. There is a routine
  647.     called dGetMusicStruc which returns a pointer to the following structure
  648.     which hold a lot of useful runtime information:
  649.  
  650.     typedef struct {
  651.         dword   MusicVolume;        /* music volume             */
  652.         dword   SoundVolume;        /* sound effects volume     */
  653.         MTrk    Tracks[MAXVOICES];  /* track structures         */
  654.         byte    NumTracks;          /* number of active tracks  */
  655.         byte    NumVoices;          /* number of active voices  */
  656.         byte    OrderPos;           /* order position           */
  657.         byte    OrderLen;           /* order length             */
  658.         byte    ReStart;            /* restart position         */
  659.         byte    PattNum;            /* pattern number           */
  660.         byte    PattRow;            /* pattern row              */
  661.         byte    BreakFlag;          /* break pattern mode       */
  662.         byte    Tempo;              /* tempo (or speed)         */
  663.         byte    TempoCount;         /* tempo counter            */
  664.         byte    BPM;                /* beats per minute         */
  665.         byte    SyncMark;           /* synchronization mark     */
  666.         byte    Status;             /* music status             */
  667.         byte    DriverStatus;       /* audio driver status      */
  668.         void    *PattPtr;           /* internal pattern pointer */
  669.         DSM     *SongPtr;           /* module pointer           */
  670.     } MHdr;
  671.  
  672.     For synchronization with music you can use the SyncMark field. You need
  673.     to place special synchronization marks in your modules. You can use
  674.     Scream Tracker 3.0 command Z to put these marks. The command parameter
  675.     should be a byte value between 0 and 127. When DSIK encounters this
  676.     command, it sets the internal variable SyncMark with the value of the
  677.     command parameter. So the variable SyncMark always have the previous
  678.     synchronization mark value.
  679.  
  680.     With the Tracks array you get everything you need to know about what is
  681.     currently playing. The structure of each Track is defined as:
  682.  
  683.     typedef struct {
  684.         byte    Note;               /* note index                   */
  685.         byte    Sample;             /* sample number                */
  686.         byte    Volume;             /* volume level                 */
  687.         byte    Balance;            /* balance                      */
  688.         word    Effect;             /* Protracker command           */
  689.         word    Rate;               /* middle-C finetune frequency  */
  690.         byte    VUMeter;            /* volume unit meter            */
  691.         byte    Flags;              /* audio message bitflags       */
  692.         byte    Reserved[38];       /* reserved                     */
  693.     } MTrk;
  694.  
  695.     The first field is the current note playing on the track. The following
  696.     field is the current instrument number. For example, if you need to know
  697.     the name of the current instrument being played in the track, you can use
  698.     the following code:
  699.  
  700.     Name = Module->Samples[TrackPtr->Sample-1]->SampleName;
  701.  
  702.     The Volume field is self explaining, and the Effect field is the current
  703.     standard Protracker command which is being interpreted.
  704.  
  705. 3.8 Interrupts
  706.  
  707.     DSIK doesn't require interrupts. Normally you would poll DSIK in an
  708.     interrupt occuring about 50-70 times per second, which will decrease
  709.     the overhead caused by the interrupt service.
  710.  
  711. 3.9 Using Timer Services
  712.  
  713.     The Timer Service (TS) library was designed for easy handling of the
  714.     timer interrupt service. This library was included because DSIK doesn't
  715.     give you any routine to easily play music and sounds in background.
  716.     With this library you can hook your own routines to be called by the
  717.     timer interrupt service at the specified rates. For example, you can
  718.     hook the dPoll routine to be called 70 times per second.
  719.  
  720.     When the TS services are installed the previous BIOS service is called
  721.     at 18.2 Hz, so the BIOS clock time and date are updated normally.
  722.  
  723.     First, to initialize the TS routines you must call dInitTimer and be
  724.     sure to call dDoneTimer to deinitialize the routines upon exit.
  725.     Now you can hook your own service routine doing:
  726.  
  727.     dStartTimer(MyTimer,TICKS(70));
  728.  
  729.     The above line will setup the timer interrupt service to call MyTimer
  730.     at 70 hertz (or times per second). The speed value is given in clock
  731.     ticks, but you can use the macro TICKS to translate frequencies in
  732.     hertz to clock ticks.
  733.  
  734.