home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / prg / dsik205 / dsik.dat / INCLUDE / AUDIO.H next >
C/C++ Source or Header  |  1995-04-10  |  11KB  |  385 lines

  1. /****************************************************************************
  2. *
  3. *                   Digital Sound Interface Kit (DSIK)
  4. *                            Version 2.00
  5. *
  6. *                           by Carlos Hasan
  7. *
  8. * Filename:     audio.h
  9. * Version:      Revision 1.1
  10. *
  11. * Language:     WATCOM C
  12. * Environment:  IBM PC (DOS/4GW)
  13. *
  14. * Description:  Audio Interface header file.
  15. *
  16. * Revision History:
  17. * ----------------
  18. *
  19. * Revision 1.1  94/11/05  12:13:39  chv
  20. * Added function to return the amount of free soundcard memory
  21. *
  22. * Revision 1.0  94/09/25  15:28:25  chv
  23. * Initial revision
  24. *
  25. ****************************************************************************/
  26.  
  27. #ifndef __AUDIO_H
  28. #define __AUDIO_H
  29.  
  30. /* Misc defines */
  31.  
  32. #define MAXVOICES       32
  33. #define MAXTRACKS       16
  34. #define MAXSAMPLES      256
  35. #define MAXORDERS       128
  36. #define MINPERIOD       28
  37. #define MAXPERIOD       6848
  38. #define MIDCPERIOD      428
  39. #define MIDCFREQ        8363
  40.  
  41. /* Soundcards ID values */
  42.  
  43. #define ID_NONE         0
  44. #define ID_SB           1
  45. #define ID_SB201        2
  46. #define ID_SBPRO        3
  47. #define ID_SB16         4
  48. #define ID_PAS          5
  49. #define ID_PASPLUS      6
  50. #define ID_PAS16        7
  51. #define ID_WSS          8
  52. #define ID_GUS          9
  53. #define ID_DEBUG        255
  54.  
  55. /* Soundcards capabilities bit flags */
  56.  
  57. #define AF_8BITS        0x00
  58. #define AF_16BITS       0x01
  59. #define AF_MONO         0x00
  60. #define AF_STEREO       0x02
  61. #define AF_NODRAM       0x00
  62. #define AF_DRAM         0x04
  63.  
  64. /* Stereo panning values */
  65.  
  66. #define PAN_LEFT        0x00
  67. #define PAN_MIDDLE      0x40
  68. #define PAN_RIGHT       0x80
  69. #define PAN_SURROUND    0xA4
  70.  
  71. /* Internal lowlevel audio messages bitflags */
  72.  
  73. #define AM_SAMPLE       0x01
  74. #define AM_KEYON        0x02
  75. #define AM_KEYOFF       0x04
  76. #define AM_VOLUME       0x08
  77. #define AM_BALANCE      0x10
  78. #define AM_SETCTL       0x20
  79. #define AM_GETCTL       0x40
  80. #define AM_PAUSE        0x80
  81.  
  82. /* Music playing status values */
  83.  
  84. #define PS_STOPPED      0
  85. #define PS_PLAYING      1
  86. #define PS_PAUSED       2
  87.  
  88. /* Music pattern break modes */
  89.  
  90. #define PB_NONE         0
  91. #define PB_BREAK        1
  92. #define PB_JUMP         2
  93. #define PB_HOLD         3
  94. #define PB_TRACE        4
  95.  
  96. /* RIFF/DSMF block identifier values */
  97.  
  98. #define ID_RIFF         0x46464952L
  99. #define ID_DSMF         0x464D5344L
  100. #define ID_SONG         0x474E4F53L
  101. #define ID_INST         0x54534E49L
  102. #define ID_PATT         0x54544150L
  103.  
  104. /* RIFF/WAVE block identifier values */
  105.  
  106. #define ID_WAVE         0x45564157L
  107. #define ID_FMT          0x20746D66L
  108. #define ID_DATA         0x61746164L
  109.  
  110. /* RIFF/DSMF INST digital samples bit flags */
  111.  
  112. #define SF_LOOPED       0x01
  113. #define SF_UNSIGNED     0x00
  114. #define SF_SIGNED       0x02
  115. #define SF_8BITS        0x00
  116. #define SF_16BITS       0x04
  117. #define SF_DELTA        0x40
  118. #define SF_LIBRARY      0x80
  119.  
  120. /* RIFF/WAVE sample format */
  121.  
  122. #define WAVE_FMT_PCM    1
  123.  
  124. /* Error values */
  125.  
  126. #define ERR_OK          0
  127. #define ERR_FORMAT      1
  128. #define ERR_NOFILE      2
  129. #define ERR_FILEIO      3
  130. #define ERR_NOMEM       4
  131. #define ERR_NODRAM      5
  132.  
  133. #ifdef  __cplusplus
  134. extern "C" {
  135. #endif
  136.  
  137. /* General typedefs */
  138.  
  139. typedef unsigned char   byte;
  140. typedef unsigned short  word;
  141. typedef unsigned long   dword;
  142.  
  143. /* Internal lowlevel audio drivers structure */
  144.  
  145. typedef struct {
  146.     dword   Magic;
  147.     dword   Next;
  148.     byte    ID;
  149.     byte    Modes;
  150.     char    Name[32];
  151.     word    Port;
  152.     byte    IrqLine;
  153.     byte    DmaChannel;
  154.     word    MinRate;
  155.     word    MaxRate;
  156.     word    BufferLength;
  157.     void    *ProcTablePtr;
  158.     void    *DriverPtr;
  159.     word    *ParmTablePtr;
  160. } Driver;
  161.  
  162. /* Internal soundcards configuration structure */
  163.  
  164. typedef struct {
  165.     byte    ID;
  166.     byte    Modes;
  167.     word    Port;
  168.     byte    IrqLine;
  169.     byte    DmaChannel;
  170.     word    SampleRate;
  171.     char    DriverName[16];
  172. } SoundCard;
  173.  
  174. /* RIFF file and block headers structures */
  175.  
  176. typedef struct {
  177.     dword   ID;
  178.     dword   Length;
  179.     dword   Type;
  180. } RiffHeader;
  181.  
  182. typedef struct {
  183.     dword   ID;
  184.     dword   Length;
  185. } RiffBlock;
  186.  
  187. /* RIFF/WAVE fmt block structure */
  188.  
  189. typedef struct {
  190.     word    Format;
  191.     word    Channels;
  192.     dword   SampleRate;
  193.     dword   BytesPerSecond;
  194.     word    BlockAlign;
  195.     word    BitsPerSample;
  196. } WaveFmt;
  197.  
  198. /* RIFF/DSMF SONG block structure */
  199.  
  200. typedef struct {
  201.     char    ModuleName[28];
  202.     word    FileVersion;
  203.     word    Flags;
  204.     word    OrderPos;
  205.     word    ReStart;
  206.     word    NumOrders;
  207.     word    NumSamples;
  208.     word    NumPatterns;
  209.     word    NumTracks;
  210.     byte    GlobalVolume;
  211.     byte    MasterVolume;
  212.     byte    InitTempo;
  213.     byte    InitBPM;
  214.     byte    ChanMap[MAXTRACKS];
  215.     byte    Orders[MAXORDERS];
  216. } Song;
  217.  
  218. /* RIFF/DSMF INST block structure */
  219.  
  220. typedef struct {
  221.     char    FileName[13];
  222.     word    Flags;
  223.     byte    Volume;
  224.     dword   Length;
  225.     dword   LoopStart;
  226.     dword   LoopEnd;
  227.     void    *DataPtr;
  228.     word    Rate;
  229.     word    Voice;
  230.     char    SampleName[28];
  231. } Sample;
  232.  
  233. /* RIFF/DSMF PATT block structure */
  234.  
  235. typedef struct {
  236.     word    Length;
  237.     byte    Data[1];
  238. } Pattern;
  239.  
  240. /* Internal RIFF/DSMF music module structure */
  241.  
  242. typedef struct {
  243.     Song    Header;
  244.     Sample  **Samples;
  245.     Pattern **Patterns;
  246. } DSM;
  247.  
  248. /* Internal music structures */
  249.  
  250. typedef struct {
  251.     byte    Note;                       /* note index */
  252.     byte    Sample;                     /* sample number */
  253.     byte    Volume;                     /* volume level */
  254.     byte    Balance;                    /* balance */
  255.     word    Effect;                     /* Protracker command */
  256.     word    Rate;                       /* middle-C finetune frequency */
  257.     byte    VUMeter;                    /* volume unit meter */
  258.     byte    Flags;                      /* audio message bitflags */
  259.     byte    Reserved[38];
  260. } MTrk;
  261.  
  262. typedef struct {
  263.     dword   MusicVolume;                /* music volume */
  264.     dword   SoundVolume;                /* sound effects volume */
  265.     MTrk    Tracks[MAXVOICES];          /* track structures */
  266.     byte    NumTracks;                  /* number of active tracks */
  267.     byte    NumVoices;                  /* number of active voices */
  268.     byte    OrderPos;                   /* order position */
  269.     byte    OrderLen;                   /* order length */
  270.     byte    ReStart;                    /* restart position */
  271.     byte    PattNum;                    /* pattern number */
  272.     byte    PattRow;                    /* pattern row */
  273.     byte    BreakFlag;                  /* break pattern mode */
  274.     byte    Tempo;                      /* tempo */
  275.     byte    TempoCount;                 /* tempo counter */
  276.     byte    BPM;                        /* beats per minute */
  277.     byte    SyncMark;                   /* synchronization mark */
  278.     byte    Status;                     /* music status */
  279.     byte    DriverStatus;               /* audio driver status */
  280.     void    *PattPtr;                   /* internal pattern pointer */
  281.     DSM     *SongPtr;                   /* module pointer */
  282. } MHdr;
  283.  
  284. /* External lowlevel audio drivers */
  285.  
  286. extern Driver SBDriver;
  287. extern Driver PASDriver;
  288. extern Driver WSSDriver;
  289. extern Driver GUSDriver;
  290.  
  291. #define dRegisterDrivers() { \
  292.     dRegisterDriver(&SBDriver); dRegisterDriver(&PASDriver); \
  293.     dRegisterDriver(&WSSDriver); dRegisterDriver(&GUSDriver); }
  294.  
  295. /* Global error variable */
  296.  
  297. extern int dError;
  298. extern char *dErrorMsg[];
  299.  
  300. /* Audio interface API prototypes */
  301.  
  302. void    dRegisterDriver(Driver *DriverPtr);
  303. Driver *dGetDriverStruc(int DriverId);
  304. int     dGetDriverFlags(void);
  305. int     dInit(SoundCard *SC);
  306. int     dDone(void);
  307. void    dPoll(void);
  308. void    dSetupVoices(int NumVoices, int MasterVolume);
  309. long    dMemAlloc(Sample *SampPtr);
  310. void    dMemFree(Sample *SampPtr);
  311. long    dMemAvail(void);
  312. void    dSetMusicVolume(int Volume);
  313. void    dSetSoundVolume(int Volume);
  314. int     dPlayMusic(DSM *MusicPtr);
  315. int     dPlayPatterns(DSM *MusicPtr, int OrderPos, int OrderEnd);
  316. void    dStopMusic(void);
  317. int     dPauseMusic(void);
  318. int     dResumeMusic(void);
  319. int     dGetMusicStatus(void);
  320. MHdr   *dGetMusicStruc(void);
  321. void    dPlayVoice(int Voice, Sample *SampPtr);
  322. void    dStopVoice(int Voice);
  323. void    dSetVoiceFreq(int Voice, int Freq);
  324. void    dSetVoiceVolume(int Voice, int Volume);
  325. void    dSetVoiceBalance(int Voice, int Balance);
  326. long    dGetVoicePos(int Voice);
  327. int     dGetVoiceStatus(int Voice);
  328.  
  329. int     dAutoDetect(SoundCard *SC);
  330. DSM    *dLoadModule(char *Filename);
  331. void    dFreeModule(DSM *MusicPtr);
  332. Sample *dLoadSample(char *Filename);
  333. void    dFreeSample(Sample *SampPtr);
  334. DSM    *dLoadModuleFile(int Handle, long Length);
  335. Sample *dLoadSampleFile(int Handle, long Length);
  336. int     dLoadSetup(SoundCard *SC, char *Filename);
  337. int     dSaveSetup(SoundCard *SC, char *Filename);
  338.  
  339. #ifdef  __cplusplus
  340. }
  341. #endif
  342.  
  343. /* Register calling conventions used by the API routines */
  344.  
  345. #pragma aux dRegisterDriver  "_*" parm [eax];
  346. #pragma aux dGetDriverStruc  "_*" parm [eax];
  347. #pragma aux dGetDriverFlags  "_*" parm [];
  348. #pragma aux dInit            "_*" parm [eax];
  349. #pragma aux dDone            "_*" parm [];
  350. #pragma aux dPoll            "_*" parm [];
  351. #pragma aux dSetupVoices     "_*" parm [eax] [edx];
  352. #pragma aux dMemAlloc        "_*" parm [eax] [edx];
  353. #pragma aux dMemFree         "_*" parm [eax];
  354. #pragma aux dMemAvail        "_*" parm [];
  355. #pragma aux dSetMusicVolume  "_*" parm [eax];
  356. #pragma aux dSetSoundVolume  "_*" parm [eax];
  357. #pragma aux dPlayMusic       "_*" parm [eax];
  358. #pragma aux dPlayPatterns    "_*" parm [eax] [edx] [ebx];
  359. #pragma aux dStopMusic       "_*" parm [];
  360. #pragma aux dPauseMusic      "_*" parm [];
  361. #pragma aux dResumeMusic     "_*" parm [];
  362. #pragma aux dGetMusicStatus  "_*" parm [];
  363. #pragma aux dGetMusicStruc   "_*" parm [];
  364. #pragma aux dPlayVoice       "_*" parm [eax] [edx];
  365. #pragma aux dStopVoice       "_*" parm [eax];
  366. #pragma aux dSetVoiceFreq    "_*" parm [eax] [edx];
  367. #pragma aux dSetVoiceVolume  "_*" parm [eax] [edx];
  368. #pragma aux dSetVoiceBalance "_*" parm [eax] [edx];
  369. #pragma aux dGetVoicePos     "_*" parm [eax];
  370. #pragma aux dGetVoiceStatus  "_*" parm [eax];
  371.  
  372. #pragma aux dAutoDetect      "_*" parm [eax];
  373. #pragma aux dLoadModule      "_*" parm [eax];
  374. #pragma aux dFreeModule      "_*" parm [eax];
  375. #pragma aux dLoadSample      "_*" parm [eax];
  376. #pragma aux dFreeSample      "_*" parm [eax];
  377. #pragma aux dLoadModuleFile  "_*" parm [eax] [edx];
  378. #pragma aux dLoadSampleFile  "_*" parm [eax] [edx];
  379. #pragma aux dLoadSetup       "_*" parm [eax] [edx];
  380. #pragma aux dSaveSetup       "_*" parm [eax] [edx];
  381.  
  382. #pragma library (audio);
  383.  
  384. #endif
  385.