
/* Low level veneers for PlayIt - ie direct translations of SWI to functions

   by Rick Hudson, 1999
*/


#ifndef _playit_h
#define _playit_h

/* SWI numbers (for completeness) */

#define PlayIt_Version       0x4D140
#define PlayIt_Config        0x4D141
#define PlayIt_LoadDriver    0x4D142
#define PlayIt_DriverInfo    0x4D143
#define PlayIt_SampleInfo    0x4D144
#define PlayIt_Status        0x4D145
#define PlayIt_Volume        0x4D146
#define PlayIt_Open          0x4D147
#define PlayIt_BeginEnd      0x4D148
#define PlayIt_SetPtr        0x4D149
#define PlayIt_Play          0x4D14A
#define PlayIt_Stop          0x4D14B
#define PlayIt_Pause         0x4D14C
#define PlayIt_Balance       0x4D14D
#define PlayIt_PauseAt       0x4D14E
#define PlayIt_VU            0x4D14F
#define PlayIt_ListDrivers   0x4D150
#define PlayIt_Identify      0x4D151
#define PlayIt_Queue         0x4D152
#define PlayIt_SetLoop       0x4D153
#define PlayIt_FileInfo      0x4D154
#define PlayIt_ClientOp      0x4D155

/* Map playit_error to OSLib's os_error or kernel's _kernel_oserror if either
   of them are defined. Define our own structure as last resort. */

#ifdef os_H
#define playit_error os_error
#endif

#ifdef __kernel_h
#define playit_error _kernel_oserror
#endif

#ifndef playit_error
typedef struct {
  int errnum;
  char errmess[252];
} playit_error;
#endif


/* types defined mainly for function readability purposes */

typedef int playit_frame;
typedef unsigned int playit_configbits;
typedef unsigned int playit_statusbits;
typedef unsigned int playit_textbits;
typedef unsigned int playit_eventbits;

typedef struct {
  unsigned int fmt_code:8;
  unsigned int channels:4;
  unsigned int interleaf:4;
  unsigned int file_sub:8;
  unsigned int file_code:8;
} playit_fmtstr;

typedef union {
  playit_fmtstr s;
  unsigned int i;
} playit_format;

/* structure used by xplayit_sample_info_block and xplayit_file_info_format */

typedef struct {
  playit_format format;
  int frame_rate;
  int start_ofs;
  int end_ofs;
  int aux_par;
  int num_frames;
} playit_sample_info;

typedef struct {
  char *filename;
  playit_format format;
  int framerate;
  int bstart;
  int bend;
  int auxpar;
} playit_open_block;

/* macro struct declaration for defining buffers for xplayit_file_info_text */

#define playit_TEXT(n,s) \
  struct { \
    char *list[n]; \
    char data[s]; \
  }

/* general casting structure for xplayit_file_info_text */

typedef struct {
  char *list[1];
} playit_text;


/* macros for various parameter constants */

#define PLAYIT_AUTODETECT       (playit_format)0
#define PLAYIT_NOFRAME          (playit_frame)-1
#define PLAYIT_PAUSE_OFF        PLAYIT_NOFRAME         /* Cancels pause point for xplayit_pauseat */
#define PLAYIT_MAX_VOL          127                    /* volume setting for 100% */
#define PLAYIT_ABS_MAX_VOL      255                    /* absolute maximum volume (amplify mode) */
#define PLAYIT_MAX_VU           255                    /* upper range of VU meter */
#define PLAYIT_READ_BUFF        0                      /* pass to config_buffer to read */
#define PLAYIT_READ_ECHO        0                      /* pass to config_echo to read */
#define PLAYIT_CFGMASK_NOFM     (playit_configbits)0x1
#define PLAYIT_CFGMASK_TRANSBUF (playit_configbits)0x2
#define PLAYIT_CFGMASK_SYSVOL   (playit_configbits)0x4
#define PLAYIT_CFGMASK_NOINERTP (playit_configbits)0x10
#define PLAYIT_CFGMASK_ECHOMONO (playit_configbits)0x20
#define PLAYIT_CFGMASK_EOFCLOSE (playit_configbits)0x80
#define PLAYIT_CFGMASK_DYNAREA  (playit_configbits)0x100
#define PLAYIT_STAT_PLAYING     (playit_statusbits)0x1
#define PLAYIT_STAT_PAUSED      (playit_statusbits)0x2
#define PLAYIT_STAT_OPEN        (playit_statusbits)0x4
#define PLAYIT_STAT_1ON2        (playit_statusbits)0x8
#define PLAYIT_STAT_2ON1        (playit_statusbits)0x10
#define PLAYIT_EVMASK_VOLUME    (playit_eventbits)0x01
#define PLAYIT_EVMASK_BALANCE   (playit_eventbits)0x02
#define PLAYIT_EVMASK_DRIVER    (playit_eventbits)0x04
#define PLAYIT_EVMASK_STATUS    (playit_eventbits)0x08
#define PLAYIT_EVMASK_PTR       (playit_eventbits)0x10
#define PLAYIT_EVMASK_PAUSEPT   (playit_eventbits)0x20
#define PLAYIT_EVMASK_LOOP      (playit_eventbits)0x40
#define PLAYIT_EVMASK_QUEUE     (playit_eventbits)0x80
#define PLAYIT_EVMASK_NEWFILE   (playit_eventbits)0x100
#define PLAYIT_CURRENT_FILE     (char *)0

#define PLAYIT_FMT_8ULIN        0x1
#define PLAYIT_FMT_8ALAW        0x2
#define PLAYIT_FMT_8ULAW        0x3
#define PLAYIT_FMT_8VIDC        0x4
#define PLAYIT_FMT_16SLINB      0x8
#define PLAYIT_FMT_16SLINL      0x9
#define PLAYIT_FMT_16ULINB      0xA
#define PLAYIT_FMT_16ULINL      0xB
#define PLAYIT_FMT_4MSADPCM     0x10
#define PLAYIT_FMT_4DVIADPCM    0x11

#define PLAYIT_FILE_ARMADEUS    0x1
#define PLAYIT_FILE_WAVE        0x2
#define PLAYIT_FILE_AU          0x3
#define PLAYIT_FILE_AWKS        0x4
#define PLAYIT_FILE_PSION       0x5
#define PLAYIT_FILE_AIFF        0x6
#define PLAYIT_FILE_IFF         0x7
#define PLAYIT_FILE_INFOCOM     0x8
#define PLAYIT_FILE_VOC         0x9
#define PLAYIT_FILE_ARMOVIE     0xA
#define PLAYIT_FILE_DATAVOX     0xB
#define PLAYIT_FILE_CDAUDIO     0xC
#define PLAYIT_FILE_XXX         0xD         /* 1st invalid file code */

/* bit masks for the text annotation request (xplayit_file_info_text) */

#define PLAYIT_TEXT_NAME        (playit_textbits)0x1
#define PLAYIT_TEXT_ARTIST      (playit_textbits)0x2
#define PLAYIT_TEXT_COMMENT     (playit_textbits)0x4
#define PLAYIT_TEXT_CREATED     (playit_textbits)0x8
#define PLAYIT_TEXT_COPYRIGHT   (playit_textbits)0x10
#define PLAYIT_TEXT_MEDIUM      (playit_textbits)0x20
#define PLAYIT_TEXT_GENRE       (playit_textbits)0x40
#define PLAYIT_TEXT_SOFTWARE    (playit_textbits)0x80
#define PLAYIT_TEXT_SUPPLIER    (playit_textbits)0x00


/* SWI veneers

   All SWIs are called with the X bit set and return error pointers. Naming
   is similar to OSLib so that the veneer for SWI Playit_XxxxYyyy is
   xplayit_xxxx_yyyy. Veneers that split an SWI into several reason codes
   have the code name appended to this after another '_' character.

   Parameters are mapped directly to registers in the same order.
   Any return parameters (those after the 'out' comment can be NULL if you're
   not interested in it.
*/

extern playit_error *xplayit_version(/*out*/int *version);

extern playit_error *xplayit_config_bits(/*in*/playit_configbits clear, playit_configbits xor,
                    /*out*/playit_configbits *newflags, playit_configbits *oldflags);

extern playit_error *xplayit_config_discbuffer(/*in*/int size, /*out*/int *oldsize);

extern playit_error *xplayit_config_echodelay(/*in*/int ms, /*out*/int *oldms);

extern playit_error *xplayit_config_killbuffer(void);

extern playit_error *xplayit_load_driver(/*in*/const char *name);

extern playit_error *xplayit_driver_info(/*out*/char **name, char **descr, char **version,
                                         int *framerate, int *mode);

extern playit_error *xplayit_sample_info(/*out*/char **name, playit_format *format,
                    int *frame_rate, int *bstart, int *bend, int *num_frames);

extern playit_error *xplayit_status(/*out*/playit_statusbits *status, playit_frame *frame);

extern playit_error *xplayit_volume(/*in*/int volume, /*out*/int *old_volume);

extern playit_error *xplayit_open(/*in*/const char *filename, playit_format format,
                    int framerate, int bstart, int bend, int auxpar);

extern playit_error *xplayit_open_block(/*in/out*/playit_open_block *block);

extern playit_error *xplayit_open_autodetect(/*in*/const char *filename);

extern playit_error *xplayit_begin_end(/*in*/playit_frame start, playit_frame end,
                    /*out*/playit_frame *rstart, playit_frame *rend);

extern playit_error *xplayit_set_ptr(/*in*/playit_frame frame, /*out*/playit_frame *rframe);

extern playit_error *xplayit_play(void);

extern playit_error *xplayit_stop(void);

extern playit_error *xplayit_pause(void);

extern playit_error *xplayit_balance(/*in*/int balance, /*out*/int *old_balance);

extern playit_error *xplayit_pause_at(/*in*/playit_frame frame, /*out*/playit_frame *rframe);

extern playit_error *xplayit_vu(/*out*/int *left, int *right);

extern playit_error *xplayit_list_drivers(/*in*/int reason, char *dir, void *buffer, int idx,
                    int buffsize, /*out*/int *num_read, int *idx_out);

extern playit_error *xplayit_identify(/*in*/const char *filename, /*out*/playit_format *format,
                    int *framerate, int *bstart, int *bend, int *auxpar, int *numframes);

extern playit_error *xplayit_queue_add(/*in*/const char *filename);

extern playit_error *xplayit_queue_flush(void);

extern playit_error *xplayit_set_loop(/*in*/playit_frame start, playit_frame stop, int count,
                    /*out*/playit_frame *rstart, playit_frame *rstop);

extern playit_error *xplayit_file_info_format(/*in*/char *filename, /*out*/playit_sample_info *block);

extern playit_error *xplayit_file_info_text(/*in*/char *filename, playit_text *block,
                    int blocksize, playit_textbits flags, /*out*/ int *nbytes);

extern playit_error *xplayit_file_info_filename(/*out*/char **filename);

extern playit_error *xplayit_clientop_register(/*in*/int flags, playit_eventbits events,
                    /*out*/int **pollword);

extern playit_error *xplayit_clientop_deregister(/*in*/int *pollword, /*out*/int *num_registered);

#endif
