M bqaudiostream/AudioWriteStream.h +12 -1
@@ 6,7 6,7 @@
A small library wrapping various audio file read/write
implementations in C++.
- Copyright 2007-2022 Particular Programs Ltd.
+ Copyright 2007-2024 Particular Programs Ltd.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
@@ 72,9 72,20 @@ public:
size_t getSampleRate() const { return m_target.getSampleRate(); }
/**
+ * Write some frames to the file. The frames pointer must point to
+ * (at least) frameCount * getChannelCount() samples.
+ *
* May throw FileOperationFailed if encoding fails.
*/
virtual void putInterleavedFrames(size_t frameCount, const float *frames) = 0;
+
+ /**
+ * Flush the file, normally writing any buffered samples to
+ * disc. Actual behaviour may depend on the writer. The writer may
+ * flush the file itself during writes at its own discretion, and
+ * the file will also be flushed when the writer is deleted.
+ */
+ virtual void flush() = 0;
protected:
AudioWriteStream(Target t) : m_target(t) { }
M src/CoreAudioWriteStream.cpp +5 -0
@@ 214,6 214,11 @@ CoreAudioWriteStream::putInterleavedFram
}
}
+void
+CoreAudioWriteStream::flush()
+{
+}
+
}
#endif
M src/CoreAudioWriteStream.h +1 -0
@@ 51,6 51,7 @@ public:
virtual std::string getError() const { return m_error; }
virtual void putInterleavedFrames(size_t count, const float *frames);
+ virtual void flush();
protected:
std::string m_error;
M src/OpusWriteStream.cpp +5 -0
@@ 156,6 156,11 @@ OpusWriteStream::putInterleavedFrames(si
#endif
}
+void
+OpusWriteStream::flush()
+{
+}
+
}
#endif // !HAVE_OPUS_READ_ONLY
M src/OpusWriteStream.h +1 -0
@@ 52,6 52,7 @@ public:
virtual std::string getError() const { return m_error; }
virtual void putInterleavedFrames(size_t count, const float *frames);
+ virtual void flush();
protected:
std::string m_error;
M src/SimpleWavFileWriteStream.cpp +9 -1
@@ 195,7 195,7 @@ SimpleWavFileWriteStream::writeFormatChu
putBytes(outString);
- m_file->flush();
+ flush();
}
void
@@ 236,6 236,14 @@ SimpleWavFileWriteStream::putInterleaved
m_sinceSync += count;
if (m_sinceSync > m_syncBlockSize) {
+ flush();
+ }
+}
+
+void
+SimpleWavFileWriteStream::flush()
+{
+ if (m_file) {
m_file->flush();
m_sinceSync = 0;
}
M src/SimpleWavFileWriteStream.h +1 -0
@@ 56,6 56,7 @@ public:
virtual std::string getError() const { return m_error; }
virtual void putInterleavedFrames(size_t count, const float *frames);
+ virtual void flush();
protected:
int m_bitDepth;
M src/WavFileWriteStream.cpp +8 -0
@@ 111,6 111,14 @@ WavFileWriteStream::putInterleavedFrames
m_sinceSync += count;
if (m_sinceSync > m_syncBlockSize) {
+ flush();
+ }
+}
+
+void
+WavFileWriteStream::flush()
+{
+ if (m_file) {
sf_write_sync(m_file);
m_sinceSync = 0;
}
M src/WavFileWriteStream.h +1 -0
@@ 58,6 58,7 @@ public:
virtual std::string getError() const { return m_error; }
virtual void putInterleavedFrames(size_t count, const float *frames);
+ virtual void flush();
protected:
SF_INFO m_fileInfo;