Fixed erratic progress display

This commit is contained in:
Daniel Wolf 2016-08-04 20:39:40 +02:00
parent 6888dadd04
commit 229105a965
3 changed files with 13 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#include <chrono>
#include <format.h>
#include <iostream>
#include <boost/algorithm/clamp.hpp>
using std::string;
@ -58,7 +59,7 @@ ProgressBar::~ProgressBar() {
void ProgressBar::reportProgress(double value) {
// Make sure value is in [0..1] range
value = std::max(0.0, std::min(1.0, value));
value = boost::algorithm::clamp(value, 0.0, 1.0);
currentProgress = value;
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <string>
#include <atomic>
#include <future>
#include <functional>
@ -14,6 +13,11 @@ public:
virtual void reportProgress(double value) = 0;
};
class NullProgressSink : public ProgressSink {
public:
void reportProgress(double) override {}
};
class ProgressForwarder : public ProgressSink {
public:
ProgressForwarder(std::function<void(double progress)> callback);

View File

@ -29,6 +29,10 @@ BoundedTimeline<void> webRtcDetectVoiceActivity(const AudioClip& audioClip, Prog
error = WebRtcVad_set_mode(vadHandle, aggressiveness);
if (error) throw runtime_error("Error setting WebRTC VAD aggressiveness.");
ProgressMerger progressMerger(progressSink);
ProgressSink& pass1ProgressSink = progressMerger.addSink(1.0);
ProgressSink& pass2ProgressSink = progressMerger.addSink(0.3);
// Detect activity
BoundedTimeline<void> activity(audioClip.getTruncatedRange());
centiseconds time = 0cs;
@ -46,7 +50,7 @@ BoundedTimeline<void> webRtcDetectVoiceActivity(const AudioClip& audioClip, Prog
}
time += 1cs;
};
process16bitAudioClip(audioClip, processBuffer, bufferCapacity, progressSink);
process16bitAudioClip(audioClip, processBuffer, bufferCapacity, pass1ProgressSink);
// WebRTC adapts to the audio. This means results may not be correct at the very beginning.
// It sometimes returns false activity at the very beginning, mistaking the background noise for speech.
@ -56,7 +60,7 @@ BoundedTimeline<void> webRtcDetectVoiceActivity(const AudioClip& audioClip, Prog
activity.clear(firstActivity);
unique_ptr<AudioClip> streamStart = audioClip.clone() | segment(TimeRange(0cs, firstActivity.getEnd()));
time = 0cs;
process16bitAudioClip(*streamStart, processBuffer, bufferCapacity, progressSink);
process16bitAudioClip(*streamStart, processBuffer, bufferCapacity, pass2ProgressSink);
}
return activity;