/* ========= CRE_WAVE.H  --  Waveform Playback Interface  ========= */
/* ==  Copyright (c) 1992-96 by Crystal River Engineering, Inc.  == */
/* ==      Updated 1997-2001 by AuSIM, Inc.                      == */
/* ================================================================ */

#ifndef CRE_WAVE_H
 #define CRE_WAVE_H

#ifdef WIN32
  #if		defined	AUSIM3D_EXPORTS
  #define	CRE_WAVE_API __declspec(dllexport)
  #elif	defined	USE_AUSIM3D_DLL
  #define	CRE_WAVE_API __declspec(dllimport)
  #else
  #define	CRE_WAVE_API
  #endif
#else  /* !WIN32 */
  #define CRE_WAVE_API
#endif 


/* ==  Waveform allocation limit == */
#define MAX_WAVEFORMS    512      /*  limit to < 13 bits for ATRON  */
#define MAX_WAVEBUFFERS  0x07FF   /*  limit to 12 bits for ATRON  */
#define WAVE_EnvVar     "WAVEFORM"    /* directory for all waveforms  */

/* ==  Client READ-ONLY WaveForm Structure  == */
/* Note -----------------------------------------------------------*
   Application programmer may use the wavFt::next structure member
   for their own use.  It is initially set to NULL.
   ----------------------------------------------------------------*/
typedef struct wavFs {
    const char     *fname;      /*  host soundfile filename        */
    void         *pSignal;      /*  pointer to the signal buffers  */
    void           *synch;      /*  synch's with this signal       */
    struct wavFs    *next,      /*  linked-list pointer for user   */
                 *duplist;      /*  duplicate list for multi-heads */

    float  sampleRate,        /*  in Hz; assumes 44.1kHz           */
           pitchFactor;       /*  pitch shift factor               */

    short  numChannels,       /*  1 = mono;  2 = stereo/biphonal   */
           sampleSize,        /*  in bytes: 1 = 8-bit, 2 = 16-bit  */
           frameSize,         /*  in bytes: samplesize * channels  */
           diskBased,         /*  boolean, TRUE if file still open */
           waveId,            /*  remote serial identifier         */
           sourceId,          /*  value = -1, if not attached      */
           listnrId;          /*  value = -1, if not attached      */

    unsigned long
       numFrames,       /*  total frames in file                    */
       remFrames,       /*  no. frames in selection NOT yet loaded  */
       selFrames,       /*  length of signal selection              */
       startFrame,      /*  beginning of signal selection (>= 0)    */
       loopCount;       /*  loop count and stop  (-1 == forever)    */
  } wavFt;

typedef wavFt *pwavFt;


/* ==  WaveForm control messages  == */
enum wave_ctrl {
  /* ==  commands independent of source id  == */
    WaveCTRL_RFRS, WaveCTRL_PSET, WaveCTRL_RWND, WaveCTRL_NOLP,
  /* ==  commands dependent on both wave pointer and source id  == */
    WaveCTRL_STRT, WaveCTRL_PLAY, WaveCTRL_LOOP,
  /* ==  commands independent of wave pointer  == */
    WaveCTRL_STOP,
  /* ==  commands MAY be independent of wave pointer xor source id  == */
    WaveCTRL_STAT,
  /* ==  commands independent of source id, require data  == */
    WaveCTRL_SYNC,
    WaveCTRL_PTCH,
    WaveCTRL_LPST,  /* no data used */
    WaveCTRL_WDAT,  /* ATRON command to fill wave structure, no data  */
    WaveCTRL_TRGR,
    WaveCTRL_FULL,
    WaveCTRL_CHNL,
    WaveCTRL_LAST
  };

typedef struct wavSDs {
    wavFt *  pwav;  /* pointer to wave to sync'd or triggerd */
    int      tsrc;  /* target source for sync'ing or triggering on */
    unsigned ofst;  /* offset in current waveform for sync or trigger */
    int      cmsg;  /* WaveCTRL_ message to trigger */
  } wavSDt;


 #define WaveCTRL_FSTAT  WaveCTRL_WDAT

#ifdef __cplusplus
 extern "C" {
#endif

/* ==  CRE_WAVE extension  == */
#ifndef EXCLUDE_WAVE_API
CRE_WAVE_API wavFt *cre_open_wave  (const char *wavefile, int mode);
CRE_WAVE_API int    cre_ctrl_wave  (int src, wavFt *wave, int cmd, void *data);
CRE_WAVE_API int    cre_close_wave (wavFt *wave);
#endif

#ifdef __cplusplus
 }
#endif

#endif  /* CRE_WAVE_H */


