// // write.cpp // MUSIC256a/CS476a - Lecture 4a // ----------------------------- // Shows how to write to an audio file using libsndfile // Uses libsndfile, by Erik de Castro Lopo // // Created by Jorge Herrera on 2011-10-17. // // To compile this example you'll need libsndfile installed in your system. // Then type: // // g++ write.cpp -o write -lsndfile #include #include #include #define SAMPLE double #define MY_SRATE 44100 using namespace std; int main() { const char* outfilename="foo.wav"; // define the desired output format SF_INFO sfinfo ; sfinfo.channels = 1; sfinfo.samplerate = MY_SRATE; sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; // open to file SNDFILE * outfile = sf_open( outfilename, SFM_WRITE, &sfinfo ); if (not outfile) return -1; // prepare a 3 second long buffer (sine wave) const int size = MY_SRATE*3; double sample[size]; float current=0.; for (int i=0; i