/* wraiff.h version 0.10, march 21, 2004. Tiny audiofile writing utility in C. Latest version available at http://www.hku.nl/~pieter/EDU/c/wraiff/ Include this headerfile in your .c file (as is done in example program write_aiff_files.c). Also include sourcefile wraiff.c in your project or makefile. Thanks to Eduard Aylon and Maarten de Boer for comments. Copyright (c) 2004 - Pieter Suurmond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ typedef struct WRAIFF* WRAIFFp; /* Forward declaration, the inside is hidden from */ /* the user (private implementation in wraiff.c). */ /* To open an new AIFF file, call function */ int open_wraiff (WRAIFFp* A, /* Receive pointer to WRAIFF object here. */ const char* filename, /* String will be copied into WRAIFF object. */ long samplerate, /* Number of samples per second (Hertz). */ short channels, /* Number of channels (between 1 and 128). */ short bits); /* Number of bits per channel (8, 16 or 24). */ /* It returns zero on success, non-zero on failure (like all functions in this library). It tries to create or overwrite(!) an AIFF file with the filename you specified. When it succeeded (i.e. when 0 is returned), *A receives a pointer to a newly created WRAIFF object. Otherwise NULL is written to *A. Then, when open_wraiff() succeeded, you can write data to it by (repeatedly) calling */ int write_wraiff (WRAIFFp* A, double* audio, /* Pointer to array of interleaved doubles. */ long frames); /* Number of frames (not doubles!) to write. */ /* Function write_wraiff() returns zero on success, non-zero on failure (1=wrong argument; 2=sample underflow; 3=sample overflow; 4=write error; 5=very large file). Errors 2 and 3 may be ignored by the user, the library will take care of clipping (preventing sign- swaps). The lowest audio-value that can be written without being clipped is always -1.0. The highest audio-value (that can be written without clipping), however, depends on the number of bits resolution: 8 bits --> 127 / 128 = 0.9921875 16 bits --> 32767 / 32768 = 0.999969482421875 24 bits --> 8388607 / 8388608 = 0.99999988079071044921875 Thus: underflow always occurs at the same level (-1.0), whereas overflow depends on the number of bits resolution (which is simply a consequence of the 2's complement representation of signed integers). As soon as you feel that you're done with the file, you should close and release by calling */ int close_wraiff (WRAIFFp* A); /* Closes file and sets reference (*A) to NULL. */ /* It returns zero on success, non-zero on failure. That's all. The toolkit will take care of (rewriting) the AIFF header and the exact number of sampleframes that are written to the file. Remember all functions declared here expect a handle (a ptr to a ptr) to a WRAIFF object as their first argument. Oh well, you may also want to call (just before closing the file) */ void print_wraiff (WRAIFFp* A, FILE* to); /* No problem when one or both arguments are NULL. Good luck! */