#ifndef _playbackH
#define _playbackH

/*  
 *  This file is part of abc2ps, 
 *  Copyright (C) 1996-2007  Michael Methfessel
 *  See file abc2ps.c for details.
 */

#include "abc2ps.h"

#define SAMPLES_PER_SEC       8000
/*| #define MAX_SAMPLES          64000 |*/
#define MAX_SAMPLES          400000
#define CD_SAMPLES_PER_SEC   44100


#define AU_IS_REST        9999
#define AU_IS_NONE        8888
#define AU_MAXV           50

#define AU_SINE       1
#define AU_TRIANGLE   2
#define AU_SAWTOOTH   3

#define  AU_INV_MIN   -3
#define  AU_INV_MAX    9


struct TRIPLE {
  float low, mid, hi;
};

struct AU_QUALITY {
  struct TRIPLE att;        /* time when attack envelope reaches 1/2 */ 
  struct TRIPLE dec1;       /* time when 1st decay enelope reaches 1/e */
  struct TRIPLE amp1;       /* amplitude */
  struct TRIPLE dec2;       /* 2nd decay */
  struct TRIPLE amp2;       /* 2nd amp   */
  struct TRIPLE dec3;       /* fast decay after offical end of note */
  struct TRIPLE freq;       /* low, mid, hi frequencies */
  struct TRIPLE sm;         /* smoothing for triangle or sawtooth */
  struct TRIPLE oamp;       /* frequency dependent amplitudes of overtones */
  struct TRIPLE odec;       /* decay of overtones */
  struct TRIPLE oa2;        /* relative amp of first overtone (double freq) */
  struct TRIPLE oa3;        /* relative amp of triple frequency */
  struct TRIPLE oa4;        /* next overtone */
  struct TRIPLE oa5;        /* next overtone */
  int type;                 /* type of waveform */
  int num;                  /* number used to select this set */
  char name[21];            /* string to name this set */
};

struct SBUF {
  int sps;                             /* samples per second */
  double t1;                           /* start time */
  double t2;                           /* end time   */
  double tau;                          /* time between samples */
  double g0;                           /* current AGC factor */
  double top;                          /* for averaging */
  int new;                             /* flag if nothing written */
  int n;                               /* number of samples */
  float data[MAX_SAMPLES];             /* data */
};

struct AU_FLOWCTRL {
  int repeat;
  int lrep;
  int rrep;
  int nrep;
};


void open_audio_file (char aunam[]);

void close_audio_file ();

void au_init_sbuf (struct SBUF *sb);

void au_agc_sbuf (int nb, struct SBUF *sb);

void au_write_sbuf (float t, struct SBUF *sb);

struct AU_QUALITY au_set_quality (char c);

float au_getpar (struct TRIPLE p, struct TRIPLE f, float freq);

void au_clear_atab (int atab[]);

void au_copy_atab (int atab[], int atab1[]);

void au_set_atab (int pit, int acc, int atab[]);

void au_set_atabs (int v, int k, int atab[]);

int hs_shift (int pit, int acc, int atab[], struct KEYSTR key);

void output_audio ();

void print_au_info (int job);

#endif

