home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Sound / SoX / Source / st.h < prev    next >
C/C++ Source or Header  |  1999-09-16  |  9KB  |  309 lines

  1. #ifndef ST_H
  2. #define ST_H
  3.  
  4. /*
  5.  * July 5, 1991
  6.  * Copyright 1991 Lance Norskog And Sundry Contributors
  7.  * This source code is freely redistributable and may be used for
  8.  * any purpose.  This copyright notice must be maintained. 
  9.  * Lance Norskog And Sundry Contributors are not responsible for 
  10.  * the consequences of using this software.
  11.  */
  12.  
  13. #ifdef VAXC
  14. #define IMPORT  globalref
  15. #define EXPORT  globaldef
  16. /*
  17.  * use the VAX C optimized functions 
  18.  */ 
  19. #define calloc  VAXC$CALLOC_OPT
  20. #define cfree   VAXC$CFREE_OPT
  21. #define free    VAXC$FREE_OPT
  22. #define malloc  VAXC$MALLOC_OPT
  23. #define realloc VAXC$REALLOC_OPT
  24. #else
  25. #define IMPORT  extern
  26. #define EXPORT 
  27. #endif
  28.  
  29.  
  30. /*
  31.  * Sound Tools sources header file.
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include <string.h>
  36.  
  37. #ifdef __alpha__
  38. #include <sys/types.h>   /* To get defines for 32-bit integers */
  39. #define    LONG    int32_t
  40. #define ULONG    u_int32_t
  41. #else
  42. #define    LONG    long
  43. #define ULONG    unsigned long
  44. #endif
  45.  
  46. /*
  47.  * Handler structure for each format.
  48.  */
  49.  
  50. typedef struct format {
  51.     char    **names;    /* file type names */
  52.     int    flags;        /* details about file type */
  53.     void    (*startread)();            
  54.     LONG    (*read)();            
  55.     void    (*stopread)();        
  56.     void    (*startwrite)();            
  57.     void    (*write)();
  58.     void    (*stopwrite)();        
  59. } format_t;
  60.  
  61. IMPORT format_t formats[];
  62.  
  63. /* Signal parameters */
  64.  
  65. struct  signalinfo {
  66.     LONG        rate;        /* sampling rate */
  67.     int        size;        /* word length of data */
  68.     int        style;        /* format of sample numbers */
  69.     int        channels;    /* number of sound channels */
  70. };
  71.  
  72. /* Loop parameters */
  73.  
  74. struct  loopinfo {
  75.     int        start;        /* first sample */
  76.     int        length;        /* length */
  77.     int        count;        /* number of repeats, 0=forever */
  78.     int        type;        /* 0=no, 1=forward, 2=forward/back */
  79. };
  80.  
  81. /* Instrument parameters */
  82.  
  83. /* vague attempt at generic information for sampler-specific info */
  84.  
  85. struct  instrinfo {
  86.     char         MIDInote;    /* for unity pitch playback */
  87.     char        MIDIlow, MIDIhi;/* MIDI pitch-bend range */
  88.     char        loopmode;    /* semantics of loop data */
  89.     char        nloops;        /* number of active loops */
  90.     unsigned char    smpte[4];    /* SMPTE offset (hour:min:sec:frame) */
  91.                     /* this is a film audio thing */
  92. };
  93.  
  94.  
  95. #define MIDI_UNITY 60        /* MIDI note number to play sample at unity */
  96.  
  97. /* Loop modes, upper 4 bits mask the loop blass, lower 4 bits describe */
  98. /* the loop behaviour, ie. single shot, bidirectional etc. */
  99. #define LOOP_NONE          0    
  100. #define LOOP_8             32    /* 8 loops: don't know ?? */
  101. #define LOOP_SUSTAIN_DECAY 64    /* AIFF style: one sustain & one decay loop */
  102.  
  103. /*
  104.  * File buffer info.  Holds info so that data can be read in blocks.
  105.  */
  106.  
  107. struct fileinfo {
  108.     char    *buf;            /* Pointer to data buffer */
  109.     int    size;            /* Size of buffer */
  110.     int    count;            /* Count read in to buffer */
  111.     int    pos;            /* Position in buffer */
  112.     int    eof;            /* Marker that EOF has been reached */
  113. };
  114.  
  115.  
  116. /*
  117.  *  Format information for input and output files.
  118.  */
  119.  
  120. #define    PRIVSIZE    330
  121.  
  122. #define NLOOPS        8
  123.  
  124. struct soundstream {
  125.     struct    signalinfo info;    /* signal specifications */
  126.     struct  instrinfo instr;    /* instrument specification */
  127.     struct  loopinfo loops[NLOOPS];    /* Looping specification */
  128.     char    swap;            /* do byte- or word-swap */
  129.     char    seekable;        /* can seek on this file */
  130.     char    *filename;        /* file name */
  131.     char    *filetype;        /* type of file */
  132.     char    *comment;        /* comment string */
  133.     FILE    *fp;            /* File stream pointer */
  134.     struct    fileinfo file;        /* File data block */
  135.     format_t *h;            /* format struct for this file */
  136.     double    priv[PRIVSIZE/8];    /* format's private data area */
  137. };
  138.  
  139. IMPORT struct soundstream informat, outformat;
  140. typedef struct soundstream *ft_t;
  141.  
  142. /* flags field */
  143. #define FILE_STEREO    1    /* does file format support stereo? */
  144. #define FILE_LOOPS    2    /* does file format support loops? */
  145. #define FILE_INSTR    4    /* does file format support instrument specificications? */
  146.  
  147. /* Size field */
  148. #define    BYTE    1
  149. #define    WORD    2
  150. #define    DWORD    4
  151. #define    FLOAT    5
  152. #define DOUBLE    6
  153. #define IEEE    7        /* IEEE 80-bit floats.  Is it necessary? */
  154.  
  155. /* Style field */
  156. #define UNSIGNED    1    /* unsigned linear: Sound Blaster */
  157. #define SIGN2        2    /* signed linear 2's comp: Mac */
  158. #define    ULAW        3    /* U-law signed logs: US telephony, SPARC */
  159. #define ALAW        4    /* A-law signed logs: non-US telephony */
  160. #define ADPCM        5    /* Compressed PCM */
  161. #define GSM        6    /* GSM 6.10 33-byte frame lossy compression */
  162.  
  163. IMPORT char *sizes[], *styles[];
  164.  
  165. /*
  166.  * Handler structure for each effect.
  167.  */
  168.  
  169. typedef struct {
  170.     char    *name;            /* effect name */
  171.     int    flags;            /* this and that */
  172.     void    (*getopts)();        /* process arguments */
  173.     void    (*start)();        /* start off effect */
  174.     void    (*flow)();        /* do a buffer */
  175.     void    (*drain)();        /* drain out at end */
  176.     void    (*stop)();        /* finish up effect */
  177. } effect_t;
  178.  
  179. IMPORT effect_t effects[];
  180.  
  181. #define    EFF_CHAN    1        /* Effect can mix channels up/down */
  182. #define EFF_RATE    2        /* Effect can alter data rate */
  183. #define EFF_MCHAN    4        /* Effect can handle multi-channel */
  184. #define EFF_REPORT    8        /* Effect does nothing */
  185.  
  186. struct effect {
  187.     char        *name;        /* effect name */
  188.     struct signalinfo ininfo;    /* input signal specifications */
  189.     struct loopinfo   loops[8];    /* input loops  specifications */
  190.     struct instrinfo  instr;    /* input instrument  specifications */
  191.     struct signalinfo outinfo;    /* output signal specifications */
  192.     effect_t     *h;        /* effects driver */
  193.     LONG        *obuf;        /* output buffer */
  194.     LONG        odone, olen;    /* consumed, total length */
  195.     double        priv[PRIVSIZE];    /* private area for effect */
  196. };
  197.  
  198. typedef struct effect *eff_t;
  199.  
  200. #if    defined(__STDC__)
  201. #define    P1(a) a
  202. #define    P2(a,b) a, b
  203. #define    P3(a,b,c) a, b, c
  204. #define    P4(a,b,c,d) a, b, c, d
  205. #define    P5(a,b,c,d,e) a, b, c, d, e
  206. #define    P6(a,b,c,d,e,f) a, b, c, d, e, f
  207. #define    P7(a,b,c,d,e,f,g) a, b, c, d, e, f, g
  208. #define    P8(a,b,c,d,e,f,g,h) a, b, c, d, e, f, g, h
  209. #define    P9(a,b,c,d,e,f,g,h,i) a, b, c, d, e, f, g, h, i
  210. #define    P10(a,b,c,d,e,f,g,h,i,j) a, b, c, d, e, f, g, h, i, j
  211. #else
  212. #define    P1(a)
  213. #define    P2(a,b)
  214. #define    P3(a,b,c)
  215. #define    P4(a,b,c,d)
  216. #define    P5(a,b,c,d,e)
  217. #define    P6(a,b,c,d,e,f)
  218. #define    P7(a,b,c,d,e,f,g)
  219. #define    P8(a,b,c,d,e,f,g,h)
  220. #define    P9(a,b,c,d,e,f,g,h,i)
  221. #define    P10(a,b,c,d,e,f,g,h,i,j)
  222. #endif
  223.  
  224. /* Utilities to read and write shorts and longs little-endian and big-endian */
  225. unsigned short rlshort(P1(ft_t ft));            /* short little-end */
  226. unsigned short rbshort(P1(ft_t ft));            /* short big-end    */
  227. unsigned short wlshort(P2(ft_t ft, unsigned short us));    /* short little-end */
  228. unsigned short wbshort(P2(ft_t ft, unsigned short us));    /* short big-end    */
  229. ULONG rllong(P1(ft_t ft));            /* long little-end  */
  230. ULONG rblong(P1(ft_t ft));            /* long big-end     */
  231. ULONG wllong(P2(ft_t ft, ULONG ul));        /* long little-end  */
  232. ULONG wblong(P2(ft_t ft, ULONG ul));        /* long big-end     */
  233. /* Read and write words and longs in "machine format".  Swap if indicated.  */
  234. unsigned short rshort(P1(ft_t ft));            
  235. unsigned short wshort(P2(ft_t ft, unsigned short us));
  236. ULONG rlong(P1(ft_t ft));        
  237. ULONG wlong(P2(ft_t ft, ULONG ul));
  238. float          rfloat(P1(ft_t ft));
  239. void           wfloat(P2(ft_t ft, double f));
  240. double         rdouble(P1(ft_t ft));
  241. void           wdouble(P2(ft_t ft, double d));
  242.  
  243. /* raw routines are used by so many people their prototypes are defined
  244.  * here for convience.
  245.  */
  246. void rawstartread(P1(ft_t ft));
  247. void rawstartwrite(P1(ft_t ft));
  248. void rawstopread(P1(ft_t ft));
  249. void rawstopwrite(P1(ft_t ft));
  250.  
  251. /* Utilities to byte-swap values */
  252. unsigned short swapw(P1(unsigned short us));        /* Swap short */
  253. ULONG             swapl(P1(ULONG ul));            /* Swap long */
  254. float             swapf(P1(float f));            /* Swap float */
  255. double            swapd(P1(double d));            /* Swap double */
  256.  
  257. IMPORT void report(P2(char *, ...)),  warn(P2(char *, ...)),
  258.      fail(P2(char *, ...));
  259.  
  260. /* util.c */
  261. IMPORT void geteffect(P1(eff_t));
  262. IMPORT void gettype(P1(ft_t));
  263. IMPORT void checkformat(P1(ft_t));
  264. IMPORT void copyformat(P2(ft_t, ft_t));
  265. IMPORT void cmpformats(P2(ft_t, ft_t));
  266. IMPORT void sigintreg(P1(ft_t));
  267.  
  268. typedef    unsigned int u_i;
  269. typedef    ULONG u_l;
  270. typedef    unsigned short u_s;
  271.  
  272. IMPORT float volume;    /* expansion coefficient */
  273. IMPORT int dovolume;
  274.  
  275. IMPORT float amplitude;    /* Largest sample so far */
  276.  
  277. IMPORT int writing;    /* are we writing to a file? */
  278.  
  279. /* export flags */
  280. IMPORT int verbose;    /* be noisy on stderr */
  281. IMPORT int summary;    /* just print summary of information */
  282.  
  283. IMPORT char *myname;
  284.  
  285. IMPORT int soxpreview;    /* Preview mode: be fast and ugly */
  286.  
  287. #define    MAXRATE    50L * 1024            /* maximum sample rate */
  288.  
  289. #define RIGHT(datum, bits)    ((datum) >> bits)
  290. #define LEFT(datum, bits)    ((datum) << bits)
  291.  
  292. #ifndef    M_PI
  293. #define M_PI    3.14159265358979323846
  294. #endif
  295.  
  296. #ifdef    VMS
  297. #define READBINARY      "r", "mbf=16", "ctx=stm" 
  298. #define WRITEBINARY     "w", "ctx=stm"
  299. #else
  300. #define READBINARY    "rb"
  301. #define WRITEBINARY    "wb"
  302. #endif
  303.  
  304. #define REMOVE unlink
  305.  
  306. char *version();            /* return version number */
  307.  
  308. #endif
  309.