diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-07-13 11:25:59 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-07-13 11:25:59 +0200 |
commit | 633bac9e82aef192a803666aaf3d3dcff920ac0c (patch) | |
tree | b4b253162c0dcdbace27807e11e5915ebce1cfab /drumgizmo/output/wavfile.cc | |
parent | 7557e5d1713337f4acc3f531e5b88a1195476eec (diff) |
Use the latency reported by the engine in the jack and wavfile output modules.
Diffstat (limited to 'drumgizmo/output/wavfile.cc')
-rw-r--r-- | drumgizmo/output/wavfile.cc | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc index a9d8b0b..20b63bd 100644 --- a/drumgizmo/output/wavfile.cc +++ b/drumgizmo/output/wavfile.cc @@ -33,6 +33,7 @@ WavfileOutputEngine::WavfileOutputEngine() , info{} , channels{} , file{"output"} + , latency{0} { info.samplerate = 44100; info.channels = 1; @@ -69,7 +70,8 @@ bool WavfileOutputEngine::init(const Channels& data) return true; } -void WavfileOutputEngine::setParm(const std::string& parm, const std::string& value) +void WavfileOutputEngine::setParm(const std::string& parm, + const std::string& value) { if(parm == "file") { @@ -105,11 +107,11 @@ void WavfileOutputEngine::stop() { } -void WavfileOutputEngine::pre(size_t nsamples) +void WavfileOutputEngine::pre(std::size_t nsamples) { } -void WavfileOutputEngine::run(int ch, sample_t* samples, size_t nsamples) +void WavfileOutputEngine::run(int ch, sample_t* samples, std::size_t nsamples) { if(static_cast<unsigned int>(ch) >= channels.size()) { @@ -118,14 +120,35 @@ void WavfileOutputEngine::run(int ch, sample_t* samples, size_t nsamples) return; } - sf_writef_float(channels[ch], samples, nsamples); + // Skip the initial 'latency' samples. + if(nsamples <= latency) + { + return; + } + + nsamples -= latency; + + sf_writef_float(channels[ch], samples + latency, nsamples); } -void WavfileOutputEngine::post(size_t nsamples) +void WavfileOutputEngine::post(std::size_t nsamples) { + if(latency > nsamples) + { + latency -= nsamples; + } + else + { + latency = 0; + } } -size_t WavfileOutputEngine::getSamplerate() const +std::size_t WavfileOutputEngine::getSamplerate() const { return info.samplerate; } + +void WavfileOutputEngine::onLatencyChange(std::size_t latency) +{ + this->latency = latency; +} |