32 m_sampleRate(sampleRate),
40 fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
46 SFM_WRITE, &fileInfo);
48 cerr <<
"WavFileWriter: Failed to open file (" 49 << sf_strerror(
m_file) <<
")" << endl;
50 m_error = QString(
"Failed to open audio file '%1' for writing")
54 m_file = sf_open(
m_path.toLocal8Bit(), SFM_WRITE, &fileInfo);
56 cerr <<
"WavFileWriter: Failed to open file (" 57 << sf_strerror(
m_file) <<
")" << endl;
58 m_error = QString(
"Failed to open audio file '%1' for writing")
101 SVDEBUG <<
"WavFileWriter::writeModel: Wrong number of channels (" 104 m_error = QString(
"Failed to write model to audio file '%1'")
110 m_error = QString(
"Failed to write model to audio file '%1': File not open")
115 bool ownSelection =
false;
124 float *ub =
new float[bs];
127 for (MultiSelection::SelectionList::iterator i =
131 int f0(i->getStartFrame()), f1(i->getEndFrame());
133 for (
int f = f0; f < f1; f += bs) {
135 int n = std::min(bs, f1 - f);
139 for (
int i = 0; i < n; ++i) {
144 sf_count_t written = sf_writef_float(
m_file, ib, n);
147 m_error = QString(
"Only wrote %1 of %2 frames at file frame %3")
148 .arg(written).arg(n).arg(f);
156 if (ownSelection)
delete selection;
165 m_error = QString(
"Failed to write model to audio file '%1': File not open")
171 for (
int i = 0; i < int(count); ++i) {
177 sf_count_t written = sf_writef_float(
m_file, b, count);
181 if (written <
int(count)) {
182 m_error = QString(
"Only wrote %1 of %2 frames")
183 .arg(written).arg(count);
virtual int getChannelCount() const =0
Return the number of distinct channels for this model.
void setSelection(const Selection &selection)
A selection object simply represents a range in time, via start and end frame.
virtual int getStartFrame() const =0
Return the first audio frame spanned by the model.
virtual int getData(int channel, int start, int count, float *buffer) const =0
Get the specified set of samples from the given channel of the model in single-precision floating-poi...
bool writeModel(DenseTimeValueModel *source, MultiSelection *selection=0)
QString getWriteFilename() const
A class that manages the creation of a temporary file with a given prefix and the renaming of that fi...
virtual const char * what() const
FileWriteMode
Specify the method used to open the destination file.
void moveToTarget()
Rename the temporary file to the target filename.
virtual QString getError() const
Base class for models containing dense two-dimensional data (value against time).
const SelectionList & getSelections() const
virtual int getEndFrame() const =0
Return the last audio frame spanned by the model.
bool writeSamples(float **samples, int count)
QString getTemporaryFilename()
Return the name of the temporary file.
WavFileWriter(QString path, int sampleRate, int channels, FileWriteMode mode)