summaryrefslogtreecommitdiff
path: root/drumgizmo/output/wavfile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'drumgizmo/output/wavfile.cc')
-rw-r--r--drumgizmo/output/wavfile.cc88
1 files changed, 46 insertions, 42 deletions
diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc
index d8b8d99..9d4deb1 100644
--- a/drumgizmo/output/wavfile.cc
+++ b/drumgizmo/output/wavfile.cc
@@ -28,10 +28,8 @@
#include "wavfile.h"
-WavfileOutputEngine::WavfileOutputEngine()
- : info{}
- , channels{}
- , file{"output"} {
+WavfileOutputEngine::WavfileOutputEngine() : info{}, channels{}, file{"output"}
+{
info.frames = 0;
info.samplerate = 44100;
info.channels = 1;
@@ -40,73 +38,79 @@ WavfileOutputEngine::WavfileOutputEngine()
info.seekable = 0;
}
-WavfileOutputEngine::~WavfileOutputEngine() {
- for (auto& ptr: channels) {
- if (ptr != nullptr) {
+WavfileOutputEngine::~WavfileOutputEngine()
+{
+ for (auto &ptr : channels)
+ {
+ if (ptr != nullptr)
+ {
sf_close(ptr);
}
}
}
-bool WavfileOutputEngine::init(Channels data) {
- channels.clear(),
- channels.resize(data.size()); // value-initialized with null
- for (auto i = 0u; i < data.size(); ++i) {
+bool WavfileOutputEngine::init(Channels data)
+{
+ channels.clear(), channels.resize(data.size()); // value-initialized with null
+ for (auto i = 0u; i < data.size(); ++i)
+ {
// write channel to file
auto fname = file + data[i].name + "-" + std::to_string(i) + ".wav";
channels[i] = sf_open(fname.c_str(), SFM_WRITE, &info);
- if (channels[i] == nullptr) {
+ if (channels[i] == nullptr)
+ {
std::cerr << "[WaffileOutputEngine] Failed to initialize "
- << "channel #" << i << "\n";
+ << "channel #" << i << "\n";
return false;
}
}
return true;
}
-void WavfileOutputEngine::setParm(std::string parm, std::string value) {
- if (parm == "file") {
+void WavfileOutputEngine::setParm(std::string parm, std::string value)
+{
+ if (parm == "file")
+ {
// apply output filename prefix
file = value;
-
- } else if (parm == "srate") {
+ }
+ else if (parm == "srate")
+ {
// try to apply samplerate
- try {
+ try
+ {
info.samplerate = std::stoi(value);
- } catch (...) {
- std::cerr << "[WavfileOutputEngine] Invalid samplerate "
- << value << "\n";
}
-
- } else {
- std::cerr << "[WavfileOutputEngine] Unsupported parameter '"
- << parm << "'\n";
+ catch (...)
+ {
+ std::cerr << "[WavfileOutputEngine] Invalid samplerate " << value << "\n";
+ }
+ }
+ else
+ {
+ std::cerr << "[WavfileOutputEngine] Unsupported parameter '" << parm
+ << "'\n";
}
}
-bool WavfileOutputEngine::start() {
- return true;
-}
+bool WavfileOutputEngine::start() { return true; }
-void WavfileOutputEngine::stop() {
-}
+void WavfileOutputEngine::stop() {}
-void WavfileOutputEngine::pre(size_t nsamples) {
-}
+void WavfileOutputEngine::pre(size_t nsamples) {}
-void WavfileOutputEngine::run(int ch, sample_t* samples, size_t nsamples) {
- if (static_cast<unsigned int>(ch) >= channels.size()) {
- std::cerr << "[WavfileOutputEngine] cannot access channel #"
- << ch << " (" << channels.size() << " channels available)\n";
+void WavfileOutputEngine::run(int ch, sample_t *samples, size_t nsamples)
+{
+ if (static_cast<unsigned int>(ch) >= channels.size())
+ {
+ std::cerr << "[WavfileOutputEngine] cannot access channel #" << ch << " ("
+ << channels.size() << " channels available)\n";
return;
}
-
+
sf_writef_float(channels[ch], samples, nsamples);
}
-void WavfileOutputEngine::post(size_t nsamples) {
-}
+void WavfileOutputEngine::post(size_t nsamples) {}
-size_t WavfileOutputEngine::samplerate() {
- return info.samplerate;
-}
+size_t WavfileOutputEngine::samplerate() { return info.samplerate; }