Skip to content

Commit

Permalink
Fixed bug where noise-isolated audio destabilized bitstream
Browse files Browse the repository at this point in the history
  • Loading branch information
tornupnegatives committed Dec 6, 2022
1 parent 1dc2895 commit 8457cc5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Frame_Encoding/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Frame_Encoding/Frame.h"
#include "Frame_Encoding/Tms5220CodingTable.h"
#include <algorithm>
#include <cmath>
#include <nlohmann/json.hpp>
#include <vector>

Expand All @@ -23,6 +24,14 @@ Frame::Frame(int pitchPeriod, bool isVoiced, float gainDB, std::vector<float> co
repeatFrame = false;
gain = gainDB;
reflectorCoeffs = std::move(coeffs);

// The gain may be NaN if the autocorrelation is zero, which has been observed in the following scenarios:
// 1. The Frame is completely silent (source audio is noise-isolated)
// 2. The highpass filter cutoff is too low
if (isnan(gainDB)) {
gain = 0.0f;
reflectorCoeffs.assign(reflectorCoeffs.size(), 0.0f);
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 8457cc5

Please sign in to comment.