4 #include <libraries/sndfile/sndfile.h>
8 template<us numChannels>
11 sndfile->write_task();
14 template<us numChannels>
18 info.samplerate = ctx->analogSampleRate;
19 info.channels = numChannels;
21 info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_32;
25 string fn = string(filename) +
".wav";
27 _file = sf_open(fn.c_str(), SFM_WRITE, &info);
30 cerr <<
"SNDFILE error: " << sf_strerror(_file) << endl;
31 throw runtime_error(
"Unable to open sndfile!");
36 _task = Bela_createAuxiliaryTask(raw_sndfile_auxtask_callback<numChannels>,
37 45,
"Write_to_sndfile_task",
this);
40 template<us numChannels>
43 for(
us i=0;i<numChannels;i++) {
44 _buf0[_buf0writeptr*numChannels+i] = samples[i];
48 else if(_buf1writeptr !=
BUFSIZE) {
49 for(
us i=0;i<numChannels;i++) {
50 _buf1[_buf1writeptr*numChannels+i] = samples[i];
55 throw std::runtime_error(
"Both buffers full");
59 Bela_scheduleAuxiliaryTask(_task);
64 template<us numChannels>
67 cerr <<
"Writing to file... " << endl;
73 else if(_buf1writeptr ==
BUFSIZE) {
77 throw std::runtime_error(
"No buffers full");
81 if(Bela_stopRequested())
return;
84 sf_count_t no = sf_writef_float(_file, buf,
BUFSIZE);
96 template<us numChannels>
99 cerr <<
"Destructor called while writing to file" << endl;