/* * audiofile.h * * Scott Wilson * rswilson@ccrma.stanford.edu * last updated: June 15, 2003 * * Defines a set of wrapper functions around the libsndfile sound file * reading and writing library. In conjunction with file.h provides * a common file info structure interface for audiofiles and codedfiles * (see file.h and codedfile.h). * * For more information on libsndfile see: * http://www.zip.com.au/~erikd/libsndfile/api.html * * Example usage: * #include "audiofile.h" * * codec_err_t err; * codec_file_t my_file_p; * err = audiofile_open(in_filename, READ, &my_file_p); * if (err != NO_ERR) // deal with error * * while(looping) * audiofile_write(&my_file_p, BLOCKSIZE, vector_set_pointer); * * err = audiofile_close(&my_file_p); * */ #include #include "codec.h" #include "vector.h" #include "file.h" typedef uint16_t audiofile_mode_t; // audiofile_open - // filename - // mode - valid modes (as defined in file.h) are AUDIOFILE_READ and AUDIOFILE_WRITE // fp - pointer to a codec_file_t struct (see file.h) codec_err_t audiofile_open(const char *filename, audiofile_mode_t mode, codec_file_p fp); // audiofile_close - critical if file is in write mode, good practice to use it regardless codec_err_t audiofile_close(codec_file_p fp); // audiofile_read - read in a block of frames // fp - pointer to the codec_file_t set up using audiofile_open // blocksize - number of FRAMES to read // vector - a codec_vector_set_p, in other words an array of channels vectors each // blocksize in length to put data in as read from the audio file. See // fp->info.channels for the number of channels in the file. See vector.h // for more info on codec_vector_set_p. codec_long_t audiofile_read(codec_file_p fp, codec_long_t blocksize, codec_vector_set_p vector); // audiofile_write - read out a block of frames // fp - pointer to the codec_file_t set up using audiofile_open // blocksize - number of FRAMES to write // vector - a codec_vector_set_p, in other words an array of channels vectors each // blocksize in length to read data from as its written to the audio file. See // fp->info.channels for the number of channels in the file. See vector.h // for more info on codec_vector_set_p. codec_long_t audiofile_write(codec_file_p fp, codec_long_t blocksize, codec_vector_set_p vector); // audiofile_rewind - reset the read pointer to the beginning of the file codec_err_t audiofile_rewind(codec_file_p fp);