Index of /cpp/rdaiffpp
C++ class to read AIFF files
RDAIFFPP version 0.16, december 30, 2019, a C++ class to read AIFF files.
Latest version available at https://ecomaan.nl/cpp/rdaiffpp.
Copyright (c) 2004, 2005, 2009, 2015, 2018, 2019 - 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.
Download RDAIFFPP files:
rdaiffpp-0.16.tar.gz This complete directory tarred and gzipped for
easier download.
rdaiff.hpp Headerfile specifying the RDAIFF C++ API.
rdaiff.cpp RDAIFF implementation (no need to look inside).
demo.cpp Example program that uses the RDAIFF C++ class.
test.cpp Program to test the RDAIFF C++ class.
Audio input files for test and demonstration:
a.aiff (126 bytes) 4-channel file with only 9 frames, 16-bit, 32k.
b.aiff (94850 bytes) Synthetic bells, stereo, 2.15 seconds, 8-bit.
Makefile UNIX users may use this to compile (and test),
simply type "make" on the commandline.
Users with a graphical user interface on their compilers (IDEs) can simply drop
the 2 cpp-files (demo.cpp and rdaiff.cpp) in a standard ISO/ANSI-C++ project.
How to use RDAIFFPP:
#include "rdaiff.hpp" // To use the RDAIFF C++ class (simply
// copy both rdaiff.hpp and rdaiff.cpp
const short max_channels = 8; // files to your project-directory).
const long frames_per_buffer = 64;
RDAIFF a("recordings/take0.aiff"); // Try to open an existing audiofile.
if (a.channels() > max_channels)
exit(1); // Error: too many channels.
while (a.frames_togo()) // Read all sampleframes (in chunks).
{
long buffer[frames_per_buffer // Static buffer to hold 64 octophonic
* max_channels]; // (32-bit) sampleframes at most.
long* b = buffer;
long n = frames_per_buffer;
if (a.frames_togo() < n) // Try to read 64 (or less) frames.
n = a.frames_togo();
a.read(buffer, n);
while (n--) // Process these sampleframes.
{
long long mix = 0; // Process all channels.
for (short c = a.channels(); c; c--)
{
mix += *b++; // For example mix all channels.
}
... = mix / a.channels(); // Store the result somewhere.
}
}
// No need to close the file because object a is deleted automatically and
// the RDAIFF-destructor will call a.close() for you.
Simpler examples, that, instead of reading a multiframe buffer, read only
single sampleframes, can be found in sourcefiles demo.cpp and test.cpp.
Thanks to Søren Christiansen (for sending me a patch that fixed swapped
COMM- and SSND-chunks in version 0.09). And thanks to Jerre van der Hulst (for
spotting a bug in version 0.14 that caused infinite loops when using bit depths
like 4 bits).
An equivalent C library is available at https://ecomaan.nl/c/rdaiff.
To write AIFF files, take a look at https://ecomaan.nl/cpp/wraiffpp.