Refactored VAD multithreading
This commit is contained in:
parent
8fa494fb77
commit
0447cbb4ff
|
@ -73,21 +73,21 @@ BoundedTimeline<void> detectVoiceActivity(std::unique_ptr<AudioStream> audioStre
|
||||||
ThreadPool threadPool;
|
ThreadPool threadPool;
|
||||||
int segmentCount = threadPool.getThreadCount();
|
int segmentCount = threadPool.getThreadCount();
|
||||||
centiseconds audioLength = audioStream->getTruncatedRange().getLength();
|
centiseconds audioLength = audioStream->getTruncatedRange().getLength();
|
||||||
ProgressMerger progressMerger(progressSink);
|
vector<TimeRange> audioSegments;
|
||||||
for (int i = 0; i < segmentCount; ++i) {
|
for (int i = 0; i < segmentCount; ++i) {
|
||||||
TimeRange segmentRange = TimeRange(i * audioLength / segmentCount, (i + 1) * audioLength / segmentCount);
|
TimeRange segmentRange = TimeRange(i * audioLength / segmentCount, (i + 1) * audioLength / segmentCount);
|
||||||
ProgressSink& segmentProgressSink = progressMerger.addSink(1.0);
|
audioSegments.push_back(segmentRange);
|
||||||
threadPool.schedule([segmentRange, &audioStream, &segmentProgressSink, &activityMutex, &activity] {
|
|
||||||
std::unique_ptr<AudioStream> audioSegment = createSegment(audioStream->clone(false), segmentRange);
|
|
||||||
BoundedTimeline<void> activitySegment = webRtcDetectVoiceActivity(*audioSegment, segmentProgressSink);
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(activityMutex);
|
|
||||||
for (auto activityRange : activitySegment) {
|
|
||||||
activityRange.getTimeRange().shift(segmentRange.getStart());
|
|
||||||
activity.set(activityRange);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
threadPool.schedule(audioSegments, [&](const TimeRange& segmentRange, ProgressSink& segmentProgressSink) {
|
||||||
|
unique_ptr<AudioStream> audioSegment = createSegment(audioStream->clone(false), segmentRange);
|
||||||
|
BoundedTimeline<void> activitySegment = webRtcDetectVoiceActivity(*audioSegment, segmentProgressSink);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(activityMutex);
|
||||||
|
for (auto activityRange : activitySegment) {
|
||||||
|
activityRange.getTimeRange().shift(segmentRange.getStart());
|
||||||
|
activity.set(activityRange);
|
||||||
|
}
|
||||||
|
}, progressSink);
|
||||||
threadPool.waitAll();
|
threadPool.waitAll();
|
||||||
|
|
||||||
// Fill small gaps in activity
|
// Fill small gaps in activity
|
||||||
|
|
Loading…
Reference in New Issue