summaryrefslogtreecommitdiff
path: root/drumgizmo/output/wavfile.cc
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-01-25 14:14:22 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-02-09 09:03:17 +0100
commit100e2d3bd46f64df730c8a375559680c577036ef (patch)
tree952e0ce0a1c5b6efb792c50617baa1484ba51e39 /drumgizmo/output/wavfile.cc
parente5a773e80bee619987aacd40cc3205acfe146e9c (diff)
applied clang-format
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; }