Skip to content

Commit

Permalink
Buffer: Support for writing aif, flac
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 13, 2024
1 parent 239e26a commit 090ce50
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion source/src/buffer/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,24 @@ void Buffer::save(std::string filename)
info.frames = this->num_frames;
info.channels = this->num_channels;
info.samplerate = (int) this->sample_rate;
info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
info.format = SF_FORMAT_PCM_16;
if (filename.substr(filename.length() - 4, filename.length()) == ".wav")
{
info.format |= SF_FORMAT_WAV;
}
else if (filename.substr(filename.length() - 5, filename.length()) == ".flac")
{
info.format |= SF_FORMAT_FLAC;
}
else if (filename.substr(filename.length() - 4, filename.length()) == ".aif")
{
info.format |= SF_FORMAT_AIFF;
}
else
{
throw std::runtime_error(std::string("Cannot write output file format: " + filename));
}

SNDFILE *sndfile = sf_open(filename.c_str(), SFM_WRITE, &info);

if (!sndfile)
Expand Down

0 comments on commit 090ce50

Please sign in to comment.