Main Page   Data Structures   File List   Data Fields   Globals  

WaveIO

Introduction

WaveIO is a simple C library which allows for reading/writing WAV files. The file must be PCM coded, 8 or 16 bits/sample and with 1 or 2 channels.

I wrote this library for my students, in order to allow them to do experiments with audio signals. I needed a simple interface and I did not want to rely on any external libraries => I decided to write this software by myself.

Although I tested and debugged this library, I would keep it, by now, in a "beta" state. Please, let me know if you discover/correct any bugs.

What do I find in WaveIO?

WaveIO gives you

How do I use it?

  1. Put waveio.c and waveio.h in a directory searched by your C compiler
  2. Make waveio.o from waveio.c (e.g. with cc -c waveio.c)
  3. Link waveio.o with your program (e.g. with cc -o myprogram myprogram.o waveio.o)

Typical usage

 #include <errno.h>
 #include "waveio.h"

 // In case of error, print a suitable message and exit.
 void handle_error(char *msg)
 {
   waveio_perror(msg);
   exit(1);
 }


 int main(int argc, char **argv)
 {
   WAV_FILE *Output;
 
   wav_samples *buf;
   int16 data[N];

    // Read the samples of pippo.wav
   buf = slurp_wav_file("/tmp/pippo.wav");
   if (buf==NULL)  
      handle_error("Could not read pippo.wav");

    // Process the first channel of pippo.wav to obtain some other
    // audio data (which goes in data[])
   process_audio(data, buf->chan0);

    // Write the result to pluto.wav
   Output = open_output_wav("/tmp/pluto.wav", // Output file
                            1,                // mono
                  // use the same bit/sample and sampling frequency
                  // of the input file
                            buf->bit_per_samples,             
                            buf->freq);
   if (Output==NULL) 
      handle_error("Could not open pluto.wav");
 
   if (write_wav_samples(Output, data, buf->nsamples) < buf->nsamples)
      handle_error("Error while writing to pluto.wav");
 
   close_wav_file(Output);
 
   return 0;
 }


Generated at Thu Jun 10 14:01:20 2004 for WaveIO by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001