/* header file for SoundZAP v3.0 */
#define SZVER     "SoundZAP v3.0"

/* Amiga specific includes */
#include <exec/types.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>

/* Standard includes */
#include <stdio.h>
#include <time.h>

/*IFF I/O includes */
#include <iff/iff.h>
#include <iff/8svx.h>

/* Prototypes */
void GiveUsage();
void ProcessOpt(struct options *, char *);
void CleanUp(struct options *, int);
void AnalyzeData(struct options *);
void GuidoCheck(struct options *);
void ConvertRaw(struct options *);
void FixSize(struct options *, ULONG);
void WriteIFFStuff(struct options *);
void WriteAUStuff(struct options *);
void PrintIOInfo(struct options *);
void ConvertVOC(struct options *);
void ConvertWAV(struct options *);
void ConvertMAC(struct options *);
void ConvertAU(struct options *);
void ConvertIFF(struct options *);
void maketable(signed char *, int);
void maketableII(unsigned char *);
void ChangeRate(struct options *);
int  ulaw2linear(unsigned char);
int  getscale(struct options *);
UWORD GetRateFromString(struct options *, char *);
ULONG ScrewIntel(ULONG);
unsigned char st_linear_to_ulaw( signed char);
struct ChunkInfo GetChunks(ULONG *, int, struct FileHandle *);

/* Important custom defines */
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define SCREWINTEL(a) ( ((a & 0xff) << 24) + ((a & 0xff00) << 8) + ((a & 0xff0000) >> 8) + ((a & 0xff000000) >> 24) )

#define DEFAULT_SIZE 51200
#define DEFAULT_RATE 11395

#define RAW     'r'
#define AU      'u'
#define IFF     'i'
#define AIFF    'a'
#define VOC     'v'
#define WAV     'w'
#define MAC     'm'
#define UNKNOWN 'k'

#define WAVE    MakeID('W','A','V','E')
#define RIFF    MakeID('R','I','F','F')
#define FMT     MakeID('f','m','t',' ')
#define DATA    MakeID('d','a','t','a')

#define ID_TEXT MakeID('T','E','X','T')
#define ID_AIFF MakeID('A','I','F','F')
#define ID_COMM MakeID('C','O','M','M')
#define ID_SSND MakeID('S','S','N','D')

#define GOOD_FILE       0
#define ERROR_IN_FORM   1
#define WRONG_TYPE      2
#define NO_MEMORY       3

/* Custom data structures */
struct options
{
    ULONG BuffSize,
          Size;
    BOOL  InSign,
          OutSign,
          KillChunk,
          FibDeltIn,
          MuLawIn,
          MuLawOut;
    UWORD SampRate,
          NewRate;
    BYTE  *Data,
          Amp,
          Bits;
    char  InType,
          OutType,
          inname[33],
          outname[33],
          FileName[50], /*To be written to NAME chunk of IFF file*/
          *Auth,    /*Must be perserved by read/writers*/
          *Copy;    /* ditto */
};

typedef struct
{
    ULONG magic,
          hrd_size,
          data_size,
          encoding,
          sample_rate,
          channels;
} AUHeader;

typedef struct
{
    short numChannels;
    ULONG numSampleFrames;
    short sampleSize;
    UBYTE sampleRate[10]; /*Should be 'extended' but I'm not sure what that is*/
} CommonChunk;

typedef struct
{
    UWORD wFormatTag,
          wChannels;

    ULONG dwSamplesPerSec,
          dwAvgBytesperSec;

    UWORD wBlockAlign;
} WaveFmtChunk;

struct ChunkInfo
{
    struct ChunkInfo *Next;
    ULONG Name;
    LONG  Size,
          Pos;
};

/* Chunks to extract from 8SVX/AIFF files */
ULONG Get[] =
{ ID_COMM, ID_SSND, ID_VHDR,
  ID_BODY, ID_NAME, ID_TEXT,
  ID_ANNO, ID_AUTH, ID_Copyright };


/* Error Messages */
char *ErrorMessages[] = {

/*00*/    "How the hell did you get this message???\n",
/*01*/    "No filenames specified!\n",
/*02*/    "No buffer size specified!\n",
/*03*/    "No sample rate specified!\n",
/*04*/    "Invalid switch!\n",
/*05*/    "Couldn't allocate memory!\n",
/*06*/    "Input file not found!\n",
/*07*/    "Probably text, not sound.\n",
/*08*/    "Error opening output file!\n",
/*09*/    "Unsupported storage format.\n",
/*10*/    "Write error!\n",
/*11*/    "Error in IFF file!\n",
/*12*/    "Error in WAV file!\n",
/*13*/    "New sample rate must be lower than original!!!\n",
/*14*/    "Bad amplification specified!\n",
/*15*/    "Stereo WAV's not supported yet!\n"
};

/* Global variables (eeek!) */
struct FileHandle *in=NULL, *out=NULL;

LONG BodySpot;
ULONG FileLen=0;
BOOL AFlag;
