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