/*

     onmempcm.h: Header file of on memory PCM stream play sample
     
                                       1998/8/3 Created
                                       1998/8/12 mod .1
*/
#ifndef __ONMEMPCM_H__
#define __ONMEMPCM_H__

typedef struct {
  Sint32   port;   /* PCM Stream Port Number */
  Sint32   *start; /* Start address          */
  Sint32   vol;    /* Volume                 */
  Sint32   pan;    /* Pan                    */
  Sint32   *baddr; /* Ring buffer address    */
  Sint32   bsize;  /* Ring buffer size       */
  SDMEMBLK memblk;
} _PortInfo_;

struct mphn {
  _PortInfo_ ch[ 2 ];    /* Port Infomation                     */
  SDPSTM      Hn;        /* PCM Stream handle for Sound Library */
  Sint32      Status;    /* Play Status                         */
  Sint32      NumOfCh;   /* Number of channels                  */
  Sint32      Size;      /* Channel data size                   */
  Sint32      Current;   /* Play size                           */
  Sint32      OctFns;    /* Oct/Fns value                       */
  Sint32      Freq;      /* Sampling rate                       */
  Sint32      Time;      /* Total time                          */
  Uint32      StartTime; /* Total time                          */
  Sint32      Bit;       /* Bit rate                            */
  Sint32      BaseVol;   /* Base Volume                         */
  Sint32      FxChn;     /* Fx input channel                    */
  Sint32      TrnsSize;  /* Transfer size to sound RAM          */
  Sint32      Prio;      /* Play priority                       */
  Sint32      LoopStart; /* Loop Start point                    */
  Sint32      LoopEnd;   /* Loop End point                      */
  Sint32      NumOfCopy; /* Number of source of mpCopyHandle    */
  Sint32      *Parent;   /* Parent Data pointer number of copy  */
  Uint32      LFOStart;  /* Pitch LFO Start timer counter       */
  void (*LFOcb)(struct mphn *); /* Pitch LFO Callback           */
  Bool        LFO;       /* Pitch LFO Flag                      */
  Bool        Loop;      /* Loop On/Off Flag                    */
  Bool        Malloc;    /* syMalloc Use/Not Use Flag           */
};

typedef struct mphn mpHn;

#define MP_STAT_IDLE    0
#define MP_STAT_RESERB  1
#define MP_STAT_STANDBY 2 
#define MP_STAT_PLAY    3
#define MP_STAT_PAUSE   4
#define MP_STAT_STOP    5
#define MP_STAT_END     6

#define MP_MAX_PORT    8
#define MP_MAX_CHANNEL 2

enum mpe_err {
  MPE_ERR_NONE = 0,
  MPE_ERR_NULL_HANDLE,
  MPE_ERR_CHANNEL_NUMBER_MISMATCH,
  MPE_ERR_UNUSED_HANDLE,
  MPE_ERR_BUFFER_ATTRIBUTE,
  MPE_ERR_BUFFER_SIZE,
  MPE_ERR_ILLEGAL_BITRATE,
  MPE_ERR_NOT_PREPARE_TO_PLAY,
  MPE_ERR_CANT_TO_TRANSFER,
  MPE_ERR_CANT_TO_PLAY,
  MPE_ERR_BUFFER_IS_USED,
  MPE_ERR_ILLEGAL_VOLUME,
  MPE_ERR_ILLEGAL_FADE,
  MPE_ERR_ILLEGAL_PAN,
  MPE_ERR_ILLEGAL_FX_CHANNEL,
  MPE_ERR_ADPCM_NOT_FOR_LOOP,
  MPE_ERR_SAMPLE_POINT_OVER,
  MPE_ERR_REGISTER_NULL_FUNCTION,
  MPE_ERR_TOO_LARGE_TRANSFER_SIZE
};

typedef enum mpe_err MPE_ERR;

/* Prototype Declares */
void mpInit( void );
mpHn *mpOpen( const char *[], Sint32 );
mpHn *mpOpenStatic( const char *[], void *[], Sint32 );
mpHn *mpCopyHandle( mpHn * );
MPE_ERR mpSetPort( mpHn *, Sint32 *, Sint32 );
MPE_ERR mpSetPrm( mpHn *, Sint32, Sint32 );
MPE_ERR mpPlay( mpHn *, Sint32 );
void mpTask( void );
MPE_ERR mpStop( mpHn * );
MPE_ERR mpClose( mpHn * );
MPE_ERR mpSetFx( mpHn *, Sint32, Sint32, Sint32 );
MPE_ERR mpSetDry( mpHn *, Sint32 );
MPE_ERR mpSetLoop( mpHn *, Bool );
MPE_ERR mpSetTransferSize( mpHn *, Sint32 );
MPE_ERR mpChangePlaySample( mpHn *, Sint32 );
MPE_ERR mpSetLoopStart( mpHn *, Sint32 );
MPE_ERR mpSetLoopEnd( mpHn *, Sint32 );
MPE_ERR mpSetLoopEndToBottom( mpHn * );
MPE_ERR mpSetLFOCallbask( mpHn *, void (*)(mpHn *) );
MPE_ERR mpSetLFO( mpHn *, Bool );
Sint32 mpGetStat( mpHn * );

#endif /* __ONMEMPCM_H__ */