Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A simple C library for writing out 16-bit Int Stereo 44.1khz .wav files
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Easy Stereo Wave-File Header.

The easiest way to write audio files.


This library makes writing out stereo wave files very easy by populating the header with nice defaults.

I assume you are on a little-endian platform with 8-bit char, like x86/64 or ARM. (Works on iPhone.)

Here is an easy example of how to use this to write some uint16_t audio samples to disk:

int16_t left_channel[NUMBER_OF_SAMPLES]; //some mono samples as signed integers;
int16_t right_channel[NUMBER_OF_SAMPLES]; //some mono samples as signed integers;

FILE * file;
file = fopen("output.wav", "w");
waveFormatHeader_t * wh = stereo16bit44khzWaveHeaderForLength(NUMBER_OF_SAMPLES);
writeWaveHeaderToFile(wh, file);

for(int i=0;i<NUMBER_OF_SAMPLES;i++){
//write the same data to both channels if you have a mono source.
//you could make a mono file, but this is just easier =)
fwrite(left_channel[i], sizeof(int16_t), 1, file); //left channel
fwrite(right_channel[i], sizeof(int16_t), 1, file); //right channel



Rewrite writeWaveHeaderToFile to write member-by-member instead of just plopping the whole struct down on the file, to avoid potential issues with padding.


On Osx, *nix:

  • libsndfile ( offers reading and writing. Installs system-wide and is quite large. Pretty easy to use, but GPL
  • gstreamer ( ) offers a whole media graph-processing framework. On Osx:

  • ExtAudioFile, though it is annoying to use if your needs are trivial it does offer lots of flexibility.

Something went wrong with that request. Please try again.