#ifndef PCM_H
#define PCM_H

/* WAV header chunk */
struct wavheader {
  unsigned int id;
  unsigned int size;
  unsigned int format;
  unsigned int sub_id;
  unsigned int sub_size;
  unsigned short int audio_format;
  unsigned short int num_channels;
  unsigned int sample_rate;
  unsigned int byte_rate;
  unsigned short int block_align;
  unsigned short int bits_per_sample;
  unsigned int data_id;
  unsigned int data_size;
};

/* Values converted from big endian, id = RIFF, format = WAVE */
#define PCM_RIFF 0x46464952
#define PCM_FORMAT 0x45564157

/* Calculate play time of WAV file */
unsigned int calculate_time (const struct wavheader wavfile);

/* Read WAV file in buffer */
void read_wav (char **data, struct wavheader *wavfile, char *filename);

/* Write out WAV file */
void write_wav (const char *data, const struct wavheader wavfile, const char *filename);

#endif