Skip to content

Commit 1610b04

Browse files
jpcimapaulfd
authored andcommitted
Allow to capture EG as FLAC, to make it compact
1 parent d1333a5 commit 1610b04

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

devtools/CaptureEG.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,43 @@ void Application::saveCapture()
225225
return;
226226

227227
QString filePath = QFileDialog::getSaveFileName(
228-
_window, tr("Save data"), QString(), tr("Data files (*.dat)"));
228+
_window, tr("Save data"), QString(), tr("Sound files (*.wav *.flac);;Data files (*.dat)"));
229229
if (filePath.isEmpty())
230230
return;
231231

232-
QFile file(filePath);
232+
QString fileSuffix = QFileInfo(filePath).suffix();
233+
if (fileSuffix.compare("wav", Qt::CaseInsensitive) == 0)
234+
saveSoundFile(filePath, SF_FORMAT_WAV);
235+
else if (fileSuffix.compare("flac", Qt::CaseInsensitive) == 0)
236+
saveSoundFile(filePath, SF_FORMAT_FLAC);
237+
else
238+
savePlotData(filePath);
239+
}
240+
241+
void Application::saveSoundFile(const QString& path, int format)
242+
{
243+
const float *data = _captureBuffer.get();
244+
size_t size = _captureFill;
245+
double sampleRate = jack_get_sample_rate(_client.get());
246+
double scaleFactor = 1.0 / _ui->internalGainVal->value();
247+
248+
SndfileHandle snd(path.toUtf8().data(), SFM_WRITE, format|SF_FORMAT_PCM_16, 1, sampleRate);
249+
250+
for (size_t i = 0; i < size; ++i) {
251+
float sample = scaleFactor * data[i];
252+
sample = std::max(-1.0f, std::min(+1.0f, sample));
253+
snd.write(&sample, 1);
254+
}
255+
256+
snd.writeSync();
257+
258+
if (snd.error())
259+
QFile::remove(path);
260+
}
261+
262+
void Application::savePlotData(const QString& path)
263+
{
264+
QFile file(path);
233265
file.open(QFile::WriteOnly|QFile::Truncate);
234266
QTextStream stream(&file);
235267

devtools/CaptureEG.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Application : public QApplication {
3939
void engageCapture();
4040
void saveCapture();
4141

42+
void saveSoundFile(const QString& path, int format);
43+
void savePlotData(const QString& path);
44+
4245
void performSfzUpdate();
4346
void performIdleChecks();
4447

0 commit comments

Comments
 (0)