home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 390.lha / SampLibrary / samp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-01  |  12.0 KB  |  446 lines

  1. /****************************************************************************
  2.     The C Include file for the dissidents' samp.library. This library reads
  3.     and writes SAMP files. Set your editor's TAB width to 3.
  4.  
  5.     Version 1.1        April 1990
  6.  
  7.     by Jim Fiore and Jeff Glatt
  8.  
  9. ****************************************************************************/
  10.  
  11. #ifndef SAMP_H
  12. #define SAMP_H
  13.  
  14. #ifdef AZTEC_C
  15. #define NARGS
  16. #endif
  17.  
  18. /* ============ SAMP.LIB ERROR CODES ============ */
  19. #define SUCCESS            0    /* Operation successful */
  20. #define LIBINUSE            1    /* Some other task is using samp.library */
  21. #define NOOPENFILE        2    /* Cannot open the file */
  22. #define NOTSAMP            3    /* Not a SAMP file */
  23. #define BADSAMP            4    /* Bad SAMP file */
  24. #define NOSUPPORT            5    /* SAMP file not supported */
  25. #define OUTOFRANGE        6    /* Too few waves in the file */
  26. #define OUTOFMEM            7    /* No mem to load the next wave */
  27. #define NOMOREWAVES        8    /* No more waves in the file */
  28. #define USERABORT            9    /* Application Abort */
  29.  
  30.  
  31. #define MakeID(a,b,c,d) ( (LONG)(a)<<24L | (LONG)(b)<<16L | (LONG)(c)<<8L | (d) )
  32.  
  33. #define ID_SAMP MakeID('S','A','M','P')
  34. #define ID_NAME MakeID('N','A','M','E')
  35.  
  36.  
  37. /* ======================= The SAMP file MHDR chunk ===================== */
  38.  
  39. #define ID_MHDR MakeID('M','H','D','R')
  40.  
  41.     /* MHDR size is dependant on the size of the imbedded playMap. */
  42.  
  43. /* NUMCHANS is determined by your application. Redefine as needed */
  44. #define NUMCHANS  4
  45.  
  46. struct MHDRChunk {
  47.     UBYTE NumOfWaves,        /* The number of waves in this file */
  48.         Format,                /* # of ORIGINAL significant bits from 8-28 */
  49.         Flags,                /* Various bits indicate various functions */
  50.         PlayMode,            /* determines play MODE of the playMap */
  51.         NumOfChans,
  52.         Pad,
  53.         PlayMap[128][NUMCHANS];    /* a map of which wave numbers to use for
  54.                                     each of 128 possible Midi Notes. Default to 4 */
  55.    };
  56.  
  57. #define    INDEPENDENT        0
  58. #define    MULTI                1
  59. #define    STEREO            2
  60. #define    PAN                3
  61.  
  62. #define CONTINUED_FILE  0x01
  63. #define STEREO_FILE     0x02
  64.  
  65. /* ====================== The SAMP file BODY chunk ====================== */
  66.  
  67. #define ID_BODY MakeID('B','O','D','Y')
  68.  
  69. /* Every wave has an 80 byte waveHeader, followed by its data. The waveHeader
  70.    structure is as follows:  */
  71.  
  72. struct waveHeader {
  73.     ULONG  WaveSize;
  74.     USHORT MidiSampNum;
  75.     UBYTE  LoopType, InsType;
  76.     ULONG  Period, Rate, LoopStart, LoopEnd;
  77.     UBYTE  RootNote, VelStart;
  78.     USHORT VelTable[16];
  79.     ULONG  ATAKsize, RLSEsize, FATKsize, FRLSsize, USERsize;
  80.     USHORT  USERtype;
  81.     };
  82.  
  83. #define    SPECIFIC    0
  84. #define    VOLMOD    1
  85. #define    PERMOD    2
  86. #define    LOOPING    3
  87.  
  88.  
  89. /* ================ SAMPlib SampleHeader64 structure ============= */
  90. /* Used by the lib to load SAMP files */
  91.  
  92. struct SampleHeader64 {
  93.     BYTE        *OneShotAddr;
  94.     UBYTE        Flags;            /* bit 7 on = no overlay */
  95.     UBYTE        VelStart;
  96.     USHORT    VelTable[16];
  97.     BYTE        *OneShotEnd;    /* loop start, as well */
  98.     ULONG        *TransTable;    /* points to ORIGINAL_PITCH */
  99.     USHORT    RootNote;
  100.     ULONG        LoopLength;        /* in words, bit 31 cannot be set */
  101.     UBYTE        AttackRate;        /* 0 - 255 */
  102.     UBYTE        AttackInc;        /* 1 - 64 */
  103.     UBYTE        DecayRate;        /* 1 - 255 */
  104.     UBYTE        DecayDec;        /* 1 - 64 */
  105.     UBYTE        SustLevel;        /* 0 - 64 */
  106.     UBYTE        ReleaseRate;    /* 1 - 255 */
  107.     UBYTE        ReleaseDec;        /* 1 - 64 */
  108.     UBYTE        ClipNote;
  109.     ULONG        WaveSize;        /* in bytes */
  110.     };
  111.  
  112. /* ====================== For the Transpose table ==================== */
  113. /* For playback of the wave */
  114.  
  115. struct TransposeNode {
  116.     struct TransposeNode    *Next;
  117.     struct TransposeNode    *Prev;
  118.     ULONG        Period;  /* in nanoseconds */
  119.     ULONG        *Orig;
  120.     ULONG        TSize;
  121.     UBYTE        TPad, Hosts;
  122. };
  123.  
  124. #define AUDIO_HARDWARE_FUDGE .279365
  125.  
  126.  
  127. /* =================== the library's SAMPInfo structure ================ */
  128.  
  129. struct SAMPInfo {
  130.         struct FileHandle *Handle;
  131.          UBYTE TypeID[4];    /* SAMP lib writes out waves as "FORM" */
  132.         ULONG FileSize;
  133.          UBYTE SAMP[4];
  134.         UBYTE MHDR[4];
  135.         ULONG    MHDRsize;
  136.         UBYTE NumOfWaves,
  137.           SampleFormat,
  138.           Flags,
  139.           PlayMode,
  140.           NumOfChans,
  141.           Pad,
  142.           PlayMap[128][4];
  143.         ULONG ANNOChunk,    /* DOS Seek() offset from beginning of file to ANNO chunk */
  144.             BODYChunk,
  145.             NAMEChunk,
  146.             AUTHChunk,
  147.             COPYChunk;
  148.         APTR ATAK,
  149.             RLSE,
  150.             FATK,            /* Vector for the application's FATK routine */
  151.             FRLS,
  152.             USER,
  153.             EXTRA;
  154.         ULONG    SeekPos;
  155.         ULONG    MemType;        /* AllocMem() attributes of mem where sample data is loaded */
  156.         USHORT MaxChars,    /* Max # of chars in string buffer */
  157.             LowPer,
  158.             HighPer;
  159.     };
  160.  
  161. /* ======================== Instrument types ========================= */
  162. /* You can construct the InsType field by OR'ing the family with the
  163.     class. For example,
  164.  
  165.     InsType = STRING | VIOLA_BOW;
  166. */
  167.  
  168. /* Instrument Families */
  169. #define    STRING        0x10
  170. #define    WOODWIND        0x20
  171. #define    KEYBOARD        0x30
  172. #define    GUITAR        0x40
  173. #define    VOICE            0x50
  174. #define    DRUM1            0x60
  175. #define    DRUM2            0x70
  176. #define    PERCUSSION1    0x80
  177. #define    BRASS1        0x90
  178. #define    BRASS2        0xA0
  179. #define    CYMBAL        0xB0
  180. #define    EFFECT1        0xC0
  181. #define    EFFECT2        0xD0
  182. #define    SYNTH            0xE0
  183.  
  184. /* Instrument Classes */
  185.  
  186. /* For the STRING family, the high nibble is as follows: */
  187.  
  188. #define    VIOLIN_BOW        0x1
  189. #define    VIOLIN_PLUCK    0x2
  190. #define    VIOLIN_GLIS        0x3
  191. #define    VIOLIN_TREM        0x4
  192. #define    VIOLA_BOW        0x5
  193. #define    VIOLA_PLUCK        0x6
  194. #define    VIOLA_GLIS        0x7
  195. #define    VIOLA_TREM        0x8
  196. #define    CELLO_BOW        0x9
  197. #define    CELLO_PLUCK        0xA
  198. #define    CELLO_GLIS        0xB
  199. #define    CELLO_TREM        0xC
  200. #define    BASS_BOW            0xD
  201. #define    BASS_PLUCK        0xE
  202. #define    BASS_TREM        0xF
  203.  
  204. /* For the BRASS1 family, the high nibble is as follows: */
  205.  
  206. #define    BARITONE_SAX    0x1
  207. #define    BARI_GROWL        0x2
  208. #define    TENOR_SAX        0x3
  209. #define    TENOR_GROWL        0x4
  210. #define    ALTO_SAX            0x5
  211. #define    ALTO_GROWL        0x6
  212. #define    SOPRANO_SAX        0x7
  213. #define    SOPRANO_GROWL    0x8
  214. #define    TRUMPET            0x9
  215. #define    MUTED_TRUMPET    0xA
  216. #define    TRUMPET_DROP    0xB
  217. #define    TROMBONE            0xC
  218. #define    TROMBONE_SLIDE    0xD
  219. #define    TROMBONE_MUTE    0xE
  220.  
  221. /* For the BRASS2 family, the high nibble is as follows: */
  222.  
  223. #define    FRENCH_HORN        0x1
  224. #define    TUBA                0x2
  225. #define    FLUGAL_HORN        0x3
  226. #define    ENGLISH_HORN    0x4
  227.  
  228. /* For the WOODWIND family, the high nibble is as follows: */
  229.  
  230. #define    CLARINET            0x1
  231. #define    FLUTE                0x2
  232. #define    PAN_FLUTE        0x3
  233. #define    OBOE                0x4
  234. #define    PICCOLO            0x5
  235. #define    RECORDER            0x6
  236. #define    BASSOON            0x7
  237. #define    BASS_CLARINET    0x8
  238. #define    HARMONICA        0x9
  239.  
  240. /* For the KEYBOARD family, the high nibble is as follows: */
  241.  
  242. #define    GRAND_PIANO        0x1
  243. #define    ELEC_PIANO        0x2
  244. #define    HONKYTONK        0x3
  245. #define    TOY_PIANO        0x4
  246. #define    HARPSICHORD        0x5
  247. #define    CLAVINET            0x6
  248. #define    PIPE_ORGAN        0x7
  249. #define    HAMMOND_B3        0x8
  250. #define    FARFISA_ORGAN    0x9
  251. #define    HARP                0xA
  252.  
  253. /* For the DRUM1 family, the high nibble is as follows: */
  254.  
  255. #define    KICK            0x1
  256. #define    SNARE            0x2
  257. #define    TOM            0x3
  258. #define    TIMBALES        0x4
  259. #define    CONGA_HIT    0x5
  260. #define    CONGA_SLAP    0x6
  261. #define    BRUSH_SNARE    0x7
  262. #define    ELEC_SNARE    0x8
  263. #define    ELEC_KICK    0x9
  264. #define    ELEC_TOM        0xA
  265. #define    RIMSHOT        0xB
  266. #define    CROSS_STICK    0xC
  267. #define    BONGO            0xD
  268. #define    STEEL_DRUM    0xE
  269. #define    DOUBLE_TOM    0xF
  270.  
  271. /* For the DRUM2 family, the high nibble is as follows: */
  272.  
  273. #define    TIMPANI            0x1
  274. #define    TIMPANI_ROLL    0x2
  275. #define    LOG_DRUM            0x3
  276.  
  277. /* For the PERCUSSION1 family, the high nibble is as follows: */
  278.  
  279. #define    BLOCK                0x1
  280. #define    COWBELL            0x2
  281. #define    TRIANGLE            0x3
  282. #define    TAMBOURINE        0x4
  283. #define    WHISTLE            0x5
  284. #define    MARACAS            0x6
  285. #define    BELL                0x7
  286. #define    VIBES                0x8
  287. #define    MARIMBA            0x9
  288. #define    XYLOPHONE        0xA
  289. #define    TUBULAR_BELLS    0xB
  290. #define    GLOCKENSPEIL    0xC
  291.  
  292. /* For the CYMBAL family, the high nibble is as follows: */
  293.  
  294. #define    CLOSED_HIHAT    0x1
  295. #define    OPEN_HIHAT        0x2
  296. #define    STEP_HIHAT        0x3
  297. #define    RIDE                0x4
  298. #define    BELL_CYMBAL        0x5
  299. #define    CRASH                0x6
  300. #define    CHOKE_CRASH        0x7
  301. #define    GONG                0x8
  302. #define    BELL_TREE        0x9
  303. #define    CYMBAL_ROLL        0xA
  304.  
  305. /* For the GUITAR family, the high nibble is as follows: */
  306.  
  307. #define    ELECTRIC            0x1
  308. #define    MUTED_ELEC        0x2
  309. #define    DISTORTED        0x3
  310. #define    ACOUSTIC            0x4
  311. #define    STRING_12        0x5
  312. #define    NYLON_STRING    0x6
  313. #define    POWER_CHORD        0x7
  314. #define    HARMONICS        0x8
  315. #define    CHORD_STRUM        0x9
  316. #define    BANJO                0xA
  317. #define    ELEC_BASS        0xB
  318. #define    SLAPPED_BASS    0xC
  319. #define    POPPED_BASS        0xD
  320. #define    SITAR                0xE
  321. #define    MANDOLIN            0xF
  322.  
  323. /* For the VOICE family, the high nibble is as follows: */
  324.  
  325. #define    MALE_AHH        0x1
  326. #define    FEMALE_AHH    0x2
  327. #define    MALE_OOO        0x3
  328. #define    FEMALE_OOO    0x4
  329. #define    FEMALE        0x5
  330. #define    BREATHY        0x6
  331. #define    LAUGH            0x7
  332. #define    WHISTLER        0x8
  333.  
  334. /* For the EFFECTS1 family, the high nibble is as follows: */
  335.  
  336. #define    EXPLOSION        0x1
  337. #define    GUNSHOT            0x2
  338. #define    CREAKING_DOOR    0x3
  339. #define    DOOR_SLAM        0x4
  340. #define    DOOR_CLOSE        0x5
  341. #define    SPACEGUN            0x6
  342. #define    JET_ENGINE        0x7
  343. #define    PROPELLER        0x8
  344. #define    HELOCOPTER        0x9
  345. #define    BROKEN_GLASS    0xA
  346. #define    THUNDER            0xB
  347. #define    RAIN                0xC
  348. #define    BIRDS                0xD
  349. #define    JUNGLE_NOISES    0xE
  350. #define    FOOTSTEP            0xF
  351.  
  352. /* For the EFFECTS2 family, the high nibble is as follows: */
  353.  
  354. #define    MACHINE_GUN        0x1
  355. #define    TELEPHONE        0x2
  356. #define    DOG_BARK            0x3
  357. #define    DOG_GROWL        0x4
  358. #define    BOAT_WHISTLE    0x5
  359. #define    OCEAN                0x6
  360. #define    WIND                0x7
  361. #define    CROWD_BOOS        0x8
  362. #define    APPLAUSE            0x9
  363. #define    ROARING_CROWDS    0xA
  364. #define    SCREAM            0xB
  365. #define    SWORD_CLASH        0xC
  366. #define    AVALANCE            0xD
  367. #define    BOUNCING_BALL    0xE
  368. #define    BALL_ON_BAT        0xF    /* OR CLUB */
  369.  
  370. /* For the SYNTH family, the high nibble is as follows: */
  371.  
  372. #define    SYNTH_STRINGS    0x1
  373. #define    SQUARE_WAVE        0x2
  374. #define    SAWTOOTH_WAVE    0x3
  375. #define    TRI_WAVE            0x4
  376. #define    SINE_WAVE        0x5
  377. #define    NOISE                0x6
  378.  
  379. /* ======================== SAMP.LIB ROUTINES ========================= */
  380.  
  381.  
  382. #ifndef __ARGS
  383. #ifdef NARGS
  384. #define __ARGS(a) ()
  385. #else
  386. #define __ARGS(a) a
  387. #endif
  388. #endif
  389.  
  390. extern struct SAMPInfo *OpenSampWrite __ARGS(( char * ));
  391. extern struct SAMPInfo *OpenSampRead __ARGS(( char *, unsigned long ));
  392. extern BOOL    WriteWaves __ARGS(( unsigned long, unsigned long, struct SampleHeader64 *, struct TransposeNode ** ));
  393. extern BOOL    WriteNames __ARGS(( unsigned long, char * ));
  394. extern BOOL    WriteMHDR __ARGS(( unsigned long, unsigned char * ));
  395. extern BOOL    WriteSampChunk __ARGS(( unsigned long, unsigned long, char * )); 
  396. extern BOOL    WriteSampData __ARGS(( unsigned long, char * ));
  397.  
  398. extern void  CloseSamp __ARGS(( void ));
  399. extern void  LoadPlaymap __ARGS(( ULONG, ULONG, ULONG, ULONG, UBYTE * ));
  400. extern void  MixPlaymap __ARGS(( ULONG, ULONG, ULONG, ULONG, UBYTE * ));
  401. extern SHORT ReadWaves __ARGS(( ULONG, ULONG, UBYTE *, struct Sampleheader64 * ));
  402. extern ULONG *MakeTransTable __ARGS(( ULONG, ULONG, ULONG, struct TransposeNode ** ));
  403. extern ULONG *CusMakeTransTable __ARGS(( ULONG, ULONG, ULONG, struct TransposeNode ** ));
  404. extern ULONG *FindTNode __ARGS(( ULONG *, struct TransposeNode * ));
  405. extern void    RemoveTTable __ARGS(( struct SampleHeader64 *, struct TransposeNode * ));
  406. extern void    FreeTTables __ARGS(( struct TransposeNode * ));
  407. extern UBYTE *SAMPErrorMsg __ARGS(( unsigned long ));
  408.  
  409.  
  410. /* *************************************************************************** 
  411.     WARNING: it is advised that you do not use these pragmas, since
  412.    SampInterface.asm maintains the SAMPError variable. If you are really
  413.    interested in efficiency, it is possible to edit the Interface for
  414.    only the functions you need - and pragmas may be used for functions which
  415.    don't fiddle with SAMPError. DON'T include the entire SampInterface AND
  416.    all pragmas, as your code will be larger than if you just used
  417.    SampInterface, AND you will have problems with SAMPError.
  418.  
  419. #ifndef NO_PRAGMAS
  420.  
  421. #pragma libcall SAMPBase WriteWaves             24  981004
  422. #pragma libcall SAMPBase WriteNames             2a  8002
  423. #pragma libcall SAMPBase WriteMHDR                 30  8002
  424. #pragma libcall SAMPBase WriteSampChunk         36  81003
  425. #pragma libcall SAMPBase WriteSampData         3c  8302
  426. #pragma libcall SAMPBase CloseSamp              42  0
  427. #pragma libcall SAMPBase LoadPlayMap              4e  8761005
  428. #pragma libcall SAMPBase MixPlayMap              54  8761005
  429. #pragma libcall SAMPBase MakeTransTable         60  a76504
  430. #pragma libcall SAMPBase SAMPErrorMsg             66  101
  431. #pragma libcall SAMPBase CusMakeTransTable     6c  a976505
  432. #pragma libcall SAMPBase RemoveTable             72  9802
  433. #pragma libcall SAMPBase FreeTTables             78  901
  434. #pragma libcall SAMPBase FindTNode                 7e  9002
  435.  
  436. The three guys below set SAMPError, so these pragmas should NEVER be used...
  437. #pragma libcall SAMPBase OpenSampWrite         1e  101
  438. #pragma libcall SAMPBase OpenSampRead          48  8102
  439. #pragma libcall SAMPBase ReadWaves                 5a  ba7604
  440.  
  441. #endif
  442. ************************************************************************* */
  443.  
  444. #endif
  445.  
  446.