A simple header-only C++ library for reading and writing audio files.
Current supported formats:
- WAV
- AIFF
Author
AudioFile is written and maintained by Adam Stark.
Usage
Create an AudioFile object:
#include "AudioFile.h"
AudioFile<double> audioFile;
Load an audio file:
audioFile.load ("/path/to/my/audiofile.wav");
Get some information about the loaded audio:
int sampleRate = audioFile.getSampleRate();
int bitDepth = audioFile.getBitDepth();
int numSamples = audioFile.getNumSamplesPerChannel();
double lengthInSeconds = audioFile.getLengthInSeconds();
int numChannels = audioFile.getNumChannels();
bool isMono = audioFile.isMono();
bool isStereo = audioFile.isStereo();
// or, just use this quick shortcut to print a summary to the console
audioFile.printSummary();
Access the samples directly:
int channel = 0;
int numSamples = audioFile.getNumSamplesPerChannel();
for (int i = 0; i < numSamples; i++)
{
double currentSample = audioFile.samples[channel][i];
}
Replace the AudioFile audio buffer with another
"// 1. Create an AudioBuffer
// (BTW, AudioBuffer is just a vector of vectors)
AudioFile ::AudioBuffer buffer;
// 2. Set to (e.g.) two channels
buffer.resize (2);
// 3. Set number of samples per channel
buffer[0].resize (100000);
buffer[1].resize (100000);
// 4. do something here to fill the buffer with samples, e.g.
#include