Skip to content

Commit

Permalink
common: Fix VAD calculations
Browse files Browse the repository at this point in the history
- For ordinary VAD we iterated backwards, which is wrong.
- For retroactive VAD we muted blocks which we should not.
  • Loading branch information
werman committed Jul 28, 2022
1 parent 11573aa commit b31564e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/common/src/RnNoiseCommonPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ RnNoiseCommonPlugin::process(const float *const *in, float **out, size_t sampleF
*/
for (uint32_t blockIdx = 0; blockIdx < blocksFromRnnoise; blockIdx++) {
float maxVadProbability = 0.f;
auto getCurOut = [blockIdx](ChannelData &channel) {
return channel.rnnoiseOutput.rbegin()[blockIdx].get();
auto getCurOut = [blockIdx, blocksFromRnnoise](ChannelData &channel) {
return channel.rnnoiseOutput.rbegin()[blocksFromRnnoise - blockIdx - 1].get();
};

for (auto &channel: m_channels) {
Expand Down Expand Up @@ -152,15 +152,13 @@ RnNoiseCommonPlugin::process(const float *const *in, float **out, size_t sampleF
auto &outBlock = channel.rnnoiseOutput.rbegin()[blockIdx];
if (outBlock->maxVadProbability >= vadThreshold) {
lastBlockIdxOverVADThreshold = outBlock->idx;
} else {
} else if (outBlock->muteState == ChunkUnmuteState::MUTED) {
bool inVadPeriod = (lastBlockIdxOverVADThreshold - outBlock->idx) <= retroactiveVADGraceBlocks;
if (inVadPeriod && outBlock->muteState != ChunkUnmuteState::UNMUTED_VAD) {
if (inVadPeriod) {
outBlock->muteState = ChunkUnmuteState::UNMUTED_RETRO_VAD;
if (channel.idx == 0) {
stats.retroactiveVADGraceBlocks++;
}
} else {
outBlock->muteState = ChunkUnmuteState::MUTED;
}
}
}
Expand Down

0 comments on commit b31564e

Please sign in to comment.