25 changed files with 3132 additions and 107 deletions
@ -0,0 +1,673 @@
@@ -0,0 +1,673 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// Some code by AI //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <algorithm> |
||||
#include <cmath> |
||||
|
||||
#include "dsp/dspengine.h" |
||||
#include "dsp/fftengine.h" |
||||
#include "dsp/fftfactory.h" |
||||
|
||||
#include "atvcolourdecoder.h" |
||||
|
||||
ATVVSBFrontEnd::ATVVSBFrontEnd() : |
||||
m_upsampling(0), |
||||
m_fft(nullptr), |
||||
m_fftSequence(0), |
||||
m_ifft(nullptr), |
||||
m_ifftSequence(0), |
||||
m_inCount(0), |
||||
m_skipBlocks(0) |
||||
{ |
||||
FFTFactory *fftFactory = DSPEngine::instance()->getFFTFactory(); |
||||
m_fftSequence = fftFactory->getEngine(m_fftLen, false, &m_fft); |
||||
m_fftIn = m_fft->in(); |
||||
m_response.resize(m_fftLen); |
||||
configure(1000000, 0.0f, 3579545.0f, true, 1); |
||||
} |
||||
|
||||
ATVVSBFrontEnd::~ATVVSBFrontEnd() |
||||
{ |
||||
FFTFactory *fftFactory = DSPEngine::instance()->getFFTFactory(); |
||||
fftFactory->releaseEngine(m_fftLen, false, m_fftSequence); |
||||
|
||||
if (m_ifft) { |
||||
fftFactory->releaseEngine(m_fftLen * m_upsampling, true, m_ifftSequence); |
||||
} |
||||
} |
||||
|
||||
void ATVVSBFrontEnd::configure(int sampleRate, float carrierOffset, float videoBandwidth, bool usb, int upsampling) |
||||
{ |
||||
if (upsampling != m_upsampling) |
||||
{ |
||||
FFTFactory *fftFactory = DSPEngine::instance()->getFFTFactory(); |
||||
|
||||
if (m_ifft) { |
||||
fftFactory->releaseEngine(m_fftLen * m_upsampling, true, m_ifftSequence); |
||||
} |
||||
|
||||
m_upsampling = upsampling; |
||||
m_ifftSequence = fftFactory->getEngine(m_fftLen * m_upsampling, true, &m_ifft); |
||||
m_overlap.resize(m_blockLen * m_upsampling); |
||||
m_out.resize(m_blockLen * m_upsampling); |
||||
} |
||||
|
||||
const float slope = 0.3e6f; // Half width of the Nyquist slope
|
||||
const float videoTop = videoBandwidth; |
||||
const float stopTop = videoBandwidth + 0.2e6f; |
||||
const float guard = 0.02f * sampleRate; // Taper to zero before the band edges, so upsampling has no discontinuity at Nyquist
|
||||
|
||||
auto response = [&](float f) -> float |
||||
{ |
||||
float fr = usb ? f - carrierOffset : carrierOffset - f; // Frequency relative to the vision carrier, video side positive
|
||||
float h; |
||||
|
||||
if (fr <= -slope) { |
||||
return 0.0f; |
||||
} else if (fr >= slope) { |
||||
h = 1.0f; |
||||
} else { |
||||
h = 0.5f + fr / (2.0f * slope); |
||||
} |
||||
|
||||
if (fr >= stopTop) { |
||||
return 0.0f; |
||||
} else if (fr > videoTop) { |
||||
h *= 0.5f * (1.0f + std::cos((float) M_PI * (fr - videoTop) / (stopTop - videoTop))); |
||||
} |
||||
|
||||
float edge = 0.5f * sampleRate - std::fabs(f); |
||||
|
||||
if (edge <= 0.0f) { |
||||
return 0.0f; |
||||
} else if (edge < guard) { |
||||
h *= 0.5f * (1.0f - std::cos((float) M_PI * edge / guard)); |
||||
} |
||||
|
||||
return h; |
||||
}; |
||||
|
||||
// Frequency sampling design: impulse response of m_blockLen taps, centred and windowed,
|
||||
// so the linear convolution of a block still fits in the FFT
|
||||
const int len = m_blockLen; |
||||
std::vector<float> desired(len); |
||||
|
||||
for (int k = 0; k < len; k++) |
||||
{ |
||||
float f = (k < len / 2 ? k : k - len) * (float) sampleRate / (float) len; |
||||
desired[k] = response(f); |
||||
} |
||||
|
||||
std::fill(m_fftIn, m_fftIn + m_fftLen, Complex{0.0f, 0.0f}); |
||||
|
||||
for (int n = 0; n < len; n++) |
||||
{ |
||||
std::complex<double> acc = 0.0; |
||||
|
||||
for (int k = 0; k < len; k++) { |
||||
acc += (double) desired[k] * std::polar(1.0, 2.0 * M_PI * k * (n - len / 2) / (double) len); |
||||
} |
||||
|
||||
// Window, and scale by 1 / m_fftLen so the unnormalised FFT pair has unity gain
|
||||
double window = 0.42 - 0.5 * std::cos(2.0 * M_PI * n / len) + 0.08 * std::cos(4.0 * M_PI * n / len); |
||||
m_fftIn[n] = Complex(acc * (window / ((double) len * m_fftLen))); |
||||
} |
||||
|
||||
m_fft->transform(); |
||||
std::copy(m_fft->out(), m_fft->out() + m_fftLen, m_response.begin()); |
||||
|
||||
std::fill(m_fftIn, m_fftIn + m_fftLen, Complex{0.0f, 0.0f}); |
||||
std::fill(m_overlap.begin(), m_overlap.end(), Complex{0.0f, 0.0f}); |
||||
m_inCount = 0; |
||||
m_skipBlocks = 2; |
||||
} |
||||
|
||||
int ATVVSBFrontEnd::processBlock(Complex **out) |
||||
{ |
||||
const int outFFTLen = m_fftLen * m_upsampling; |
||||
const int outLen = m_blockLen * m_upsampling; |
||||
|
||||
m_fft->transform(); |
||||
const Complex *spectrum = m_fft->out(); |
||||
Complex *upsampled = m_ifft->in(); |
||||
|
||||
// Filter, and upsample by zero padding the middle of the spectrum
|
||||
std::fill(upsampled, upsampled + outFFTLen, Complex{0.0f, 0.0f}); |
||||
|
||||
for (int i = 0; i < m_fftLen / 2; i++) { |
||||
upsampled[i] = spectrum[i] * m_response[i]; |
||||
} |
||||
|
||||
for (int i = 1; i < m_fftLen / 2; i++) { |
||||
upsampled[outFFTLen - i] = spectrum[m_fftLen - i] * m_response[m_fftLen - i]; |
||||
} |
||||
|
||||
m_ifft->transform(); |
||||
const Complex *filtered = m_ifft->out(); |
||||
|
||||
// Overlap and add
|
||||
for (int i = 0; i < outLen; i++) |
||||
{ |
||||
m_out[i] = m_overlap[i] + filtered[i]; |
||||
m_overlap[i] = filtered[outLen + i]; |
||||
} |
||||
|
||||
// The second half of the input is zero padding, so it only needs clearing in case the FFT overwrote it
|
||||
std::fill(m_fftIn + m_blockLen, m_fftIn + m_fftLen, Complex{0.0f, 0.0f}); |
||||
|
||||
*out = m_out.data(); |
||||
return outLen; |
||||
} |
||||
|
||||
ATVSynchronousDetector::ATVSynchronousDetector() : |
||||
m_ghostOn(false), |
||||
m_ghostBuffer(m_ghostBufferSize), |
||||
m_ghostIndex(0) |
||||
{ |
||||
configure(10000000.0f, 0.0f, 15625.0f); |
||||
} |
||||
|
||||
void ATVSynchronousDetector::configure(float sampleRate, float carrierFrequency, float lineFrequency) |
||||
{ |
||||
m_sampleRate = sampleRate; |
||||
m_blockLength = std::max(2, (int) std::round(sampleRate / 1.0e6f)); |
||||
m_linePeriod = sampleRate / lineFrequency; |
||||
m_nominalStep = -2.0 * M_PI * carrierFrequency / sampleRate; |
||||
m_frequency = 0.0; |
||||
m_rotation = 1.0f; |
||||
m_step = std::polar(1.0f, (float) m_nominalStep); |
||||
m_phaseCarrier = 0.0f; |
||||
m_carrierUnit = 1.0f; |
||||
m_phaseLowPassAlpha = 1.0f - std::exp(-2.0f * (float) M_PI * 5.0e3f / sampleRate); // 5 kHz
|
||||
m_count = 0; |
||||
m_block = 0.0f; |
||||
m_blockIndex = 0; |
||||
m_tipLevel = 0.0f; |
||||
m_keyLevel = 0.0f; |
||||
m_run.clear(); |
||||
m_run.reserve(m_maxRunBlocks); |
||||
m_runStart = 0; |
||||
m_runOverflow = false; |
||||
m_prevRunSum = 0.0f; |
||||
m_prevRunLength = 0; |
||||
m_prevRunStart = 0; |
||||
m_coarseSum = 0.0f; |
||||
m_coarseCount = 0; |
||||
setGhost(1.0f, 0.0f); |
||||
m_ghostInput = 0.0f; |
||||
} |
||||
|
||||
void ATVSynchronousDetector::setGhost(float delay, std::complex<float> gain) |
||||
{ |
||||
delay = std::max(1.0f, std::min(delay, (float) (m_ghostBufferSize - 2))); |
||||
m_ghostDelay = (int) delay; |
||||
m_ghostFrac = delay - m_ghostDelay; |
||||
m_ghostGain = gain; |
||||
|
||||
if ((gain != 0.0f) != m_ghostOn) |
||||
{ |
||||
m_ghostOn = gain != 0.0f; |
||||
std::fill(m_ghostBuffer.begin(), m_ghostBuffer.end(), 0.0f); |
||||
m_ghostIndex = 0; |
||||
} |
||||
} |
||||
|
||||
void ATVSynchronousDetector::update() |
||||
{ |
||||
m_count = 0; |
||||
float magnitude = std::abs(m_phaseCarrier); |
||||
|
||||
if (magnitude > 0.0f) { |
||||
m_carrierUnit = std::conj(m_phaseCarrier) / magnitude; |
||||
} |
||||
|
||||
// Sync tip level: follows the strongest blocks, and decays over ~100 ms so keying
|
||||
// recovers if the signal level drops
|
||||
float blockAmplitude = std::abs(m_block) / m_blockLength; |
||||
|
||||
if (blockAmplitude > m_tipLevel) { |
||||
m_tipLevel += 0.02f * (blockAmplitude - m_tipLevel); |
||||
} else { |
||||
m_tipLevel *= 0.99999f; |
||||
} |
||||
|
||||
m_keyLevel = 0.85f * 0.85f * m_tipLevel * m_tipLevel; |
||||
|
||||
// Collect runs of blocks within 90% of the sync tip carrier
|
||||
if ((blockAmplitude > 0.9f * m_tipLevel) && (m_blockIndex > m_settleBlocks)) |
||||
{ |
||||
if (m_run.empty()) { |
||||
m_runStart = m_blockIndex; |
||||
} |
||||
|
||||
if ((int) m_run.size() < m_maxRunBlocks) { |
||||
m_run.push_back(m_block); |
||||
} else { |
||||
m_runOverflow = true; |
||||
} |
||||
} |
||||
else if (!m_run.empty()) |
||||
{ |
||||
endRun(); |
||||
} |
||||
|
||||
m_block = 0.0f; |
||||
m_blockIndex++; |
||||
m_rotation /= std::abs(m_rotation); // Keep the recursive rotation on the unit circle
|
||||
} |
||||
|
||||
void ATVSynchronousDetector::endRun() |
||||
{ |
||||
int length = (int) m_run.size(); |
||||
|
||||
if (!m_runOverflow) |
||||
{ |
||||
std::complex<float> sum = 0.0f; |
||||
|
||||
for (const auto& block : m_run) { |
||||
sum += block; |
||||
} |
||||
|
||||
// Coarse: phase change between blocks along the middle of a broad pulse
|
||||
for (int i = m_runEdgeBlocks + 1; i < length - m_runEdgeBlocks; i++) |
||||
{ |
||||
m_coarseSum += m_run[i] * std::conj(m_run[i - 1]); |
||||
m_coarseCount++; |
||||
} |
||||
|
||||
// Fine: phase change since the same pulse a line earlier
|
||||
float spacing = (float) ((m_runStart - m_prevRunStart) * m_blockLength); |
||||
|
||||
if ((length >= 2) && (std::abs(length - m_prevRunLength) <= 1) && (std::fabs(spacing - m_linePeriod) < 2.0f * m_blockLength)) |
||||
{ |
||||
float dphi = std::arg(sum * std::conj(m_prevRunSum)); |
||||
m_frequency -= 0.1 * dphi / m_linePeriod; |
||||
} |
||||
|
||||
m_prevRunSum = sum; |
||||
m_prevRunLength = length; |
||||
m_prevRunStart = m_runStart; |
||||
} |
||||
|
||||
m_run.clear(); |
||||
m_runOverflow = false; |
||||
|
||||
// Once a vertical sync's worth of broad pulses is measured, correct the frequency if it is
|
||||
// well out, which is when the fine loop could be on the wrong multiple of the line rate.
|
||||
// The pulses' edges still bias it by ~2 kHz, so small errors are left to the fine loop
|
||||
if (m_coarseCount >= 40) |
||||
{ |
||||
double error = std::arg(m_coarseSum) / m_blockLength; // radians / sample
|
||||
|
||||
if (std::fabs(error) > 2.0 * M_PI * 4000.0 / m_sampleRate) { |
||||
m_frequency -= error; |
||||
} |
||||
|
||||
m_coarseSum = 0.0f; |
||||
m_coarseCount = 0; |
||||
} |
||||
|
||||
m_step = std::polar(1.0f, (float) (m_nominalStep + m_frequency)); |
||||
} |
||||
|
||||
float ATVSynchronousDetector::getFrequencyError() const |
||||
{ |
||||
return (float) (-m_frequency * m_sampleRate / (2.0 * M_PI)); |
||||
} |
||||
|
||||
ATVColourDecoder::ATVColourDecoder() : |
||||
m_carrierReferenced(false), |
||||
m_saturation(1.0f), |
||||
m_hue(1.0f, 0.0f), |
||||
m_delayLine(true) |
||||
{ |
||||
configure(10000000.0f, ATVDemodSettings::ColourNTSC); |
||||
} |
||||
|
||||
void ATVColourDecoder::configure(float sampleRate, ATVDemodSettings::ColourSystem colourSystem) |
||||
{ |
||||
m_sampleRate = sampleRate; |
||||
m_subcarrierFrequency = ATVDemodSettings::getSubcarrierFrequency(colourSystem); |
||||
m_pal = (colourSystem == ATVDemodSettings::ColourPAL) |
||||
|| (colourSystem == ATVDemodSettings::ColourPALM) |
||||
|| (colourSystem == ATVDemodSettings::ColourPALN); |
||||
|
||||
// Levels in IRE (100 IRE = 700 mV for 625 line systems)
|
||||
bool system525 = (colourSystem == ATVDemodSettings::ColourNTSC) || (colourSystem == ATVDemodSettings::ColourPALM); |
||||
m_syncDepth = system525 ? 40.0f : 300.0f / 7.0f; |
||||
m_nominalBurst = system525 ? 20.0f : 150.0f / 7.0f; |
||||
m_setup = system525 ? 7.5f : 0.0f; |
||||
m_blankCarrier = 0.75f; // Negative modulation, as a fraction of the sync tip carrier
|
||||
m_whiteCarrier = ATVDemodSettings::getWhiteCarrier(colourSystem); |
||||
|
||||
// Measurement windows from the leading edge of sync: sync tip, and the burst
|
||||
// (NTSC burst is 5.3 to 7.8 us, PAL 5.6 to 7.85 us)
|
||||
m_tipStart = (int) (1.0e-6f * sampleRate); |
||||
m_tipEnd = (int) (3.5e-6f * sampleRate); |
||||
m_burstStart = (int) (5.8e-6f * sampleRate); |
||||
m_burstEnd = (int) (7.4e-6f * sampleRate); |
||||
|
||||
// Chroma low pass: 6 dB at 1.5 MHz, stop band from about 2.1 MHz, which rejects
|
||||
// both the luma (shifted down to -fsc) and the image at -2 fsc
|
||||
float cutoff = 1.5e6f / sampleRate; |
||||
int taps = ((int) std::ceil(5.5f * sampleRate / 1.2e6f)) | 1; |
||||
int half = taps / 2; |
||||
m_lpfTaps.resize(taps); |
||||
float sum = 0.0f; |
||||
|
||||
for (int i = 0; i < taps; i++) |
||||
{ |
||||
int k = i - half; |
||||
float sinc = (k == 0) ? 2.0f * cutoff : std::sin(2.0f * (float) M_PI * cutoff * k) / ((float) M_PI * k); |
||||
float window = 0.42f + 0.5f * std::cos((float) M_PI * k / (half + 1)) + 0.08f * std::cos(2.0f * (float) M_PI * k / (half + 1)); |
||||
m_lpfTaps[i] = sinc * window; |
||||
sum += m_lpfTaps[i]; |
||||
} |
||||
|
||||
for (auto& tap : m_lpfTaps) { |
||||
tap /= sum; |
||||
} |
||||
|
||||
m_chromaDecimation = std::max(1, (int) (sampleRate / 4.5e6f)); |
||||
|
||||
// The displayed chroma is narrower again, as a TV's was, which halves its noise:
|
||||
// two 0.6 us boxcars make a triangle about 0.75 MHz wide at 6 dB. The wider chroma is
|
||||
// still used to separate it from the luma, so the luma keeps no subcarrier
|
||||
m_chromaSmoothing = std::max(1, (int) std::round(0.6e-6f * sampleRate)); |
||||
|
||||
m_phasor.clear(); // Recalculated for the new rate by resize()
|
||||
m_prevUV.clear(); |
||||
m_tipLevel = 0.0f; |
||||
m_blankLevel = 0.0f; |
||||
m_levelsValid = false; |
||||
m_burstRef = 0.0f; |
||||
m_prevBurst = 0.0f; |
||||
m_burstAmplitude = 0.0f; |
||||
m_colourOn = false; |
||||
m_missingBursts = 1000; |
||||
m_vSign = 1.0f; |
||||
} |
||||
|
||||
void ATVColourDecoder::resize(int length) |
||||
{ |
||||
if ((int) m_phasor.size() < length) |
||||
{ |
||||
int oldSize = (int) m_phasor.size(); |
||||
m_phasor.resize(length); |
||||
float w = 2.0f * (float) M_PI * m_subcarrierFrequency / m_sampleRate; |
||||
|
||||
for (int n = oldSize; n < length; n++) { |
||||
m_phasor[n] = std::polar(2.0f, -w * n); |
||||
} |
||||
|
||||
m_ire.resize(length); |
||||
m_mixedRe.resize(length); |
||||
m_mixedIm.resize(length); |
||||
m_chroma.resize(length); |
||||
m_chromaSum.resize(length + 1); |
||||
m_chromaDisplay.resize(length); |
||||
m_prevUV.resize(length); |
||||
} |
||||
} |
||||
|
||||
// Centred moving average of m_chromaSmoothing samples (in and out can be the same)
|
||||
void ATVColourDecoder::smoothChroma(std::vector<std::complex<float>>& in, std::vector<std::complex<float>>& out, int length) |
||||
{ |
||||
const int w = m_chromaSmoothing; |
||||
const int before = w / 2; |
||||
m_chromaSum[0] = 0.0f; |
||||
|
||||
for (int n = 0; n < length; n++) { |
||||
m_chromaSum[n + 1] = m_chromaSum[n] + in[n]; |
||||
} |
||||
|
||||
for (int n = 0; n < length; n++) |
||||
{ |
||||
int a = std::max(n - before, 0); |
||||
int b = std::min(n - before + w, length); |
||||
out[n] = (m_chromaSum[b] - m_chromaSum[a]) / (float) (b - a); |
||||
} |
||||
} |
||||
|
||||
std::complex<float> ATVColourDecoder::filterChroma(int n, int length) const |
||||
{ |
||||
const int taps = (int) m_lpfTaps.size(); |
||||
const int half = taps / 2; |
||||
const float *h = m_lpfTaps.data(); |
||||
float re = 0.0f; |
||||
float im = 0.0f; |
||||
|
||||
if ((n - half >= 0) && (n + half < length)) |
||||
{ |
||||
// Separate real and imaginary arrays, so this vectorises
|
||||
const float *xr = &m_mixedRe[n - half]; |
||||
const float *xi = &m_mixedIm[n - half]; |
||||
|
||||
for (int i = 0; i < taps; i++) |
||||
{ |
||||
re += h[i] * xr[i]; |
||||
im += h[i] * xi[i]; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
for (int i = 0; i < taps; i++) |
||||
{ |
||||
int j = std::min(std::max(n + i - half, 0), length - 1); |
||||
re += h[i] * m_mixedRe[j]; |
||||
im += h[i] * m_mixedIm[j]; |
||||
} |
||||
} |
||||
|
||||
return {re, im}; |
||||
} |
||||
|
||||
static inline unsigned int packRGB(float r, float g, float b) |
||||
{ |
||||
int ri = std::min(std::max((int) (r * 255.0f), 0), 255); |
||||
int gi = std::min(std::max((int) (g * 255.0f), 0), 255); |
||||
int bi = std::min(std::max((int) (b * 255.0f), 0), 255); |
||||
return ri | (gi << 8) | (bi << 16); |
||||
} |
||||
|
||||
void ATVColourDecoder::decodeLine(const float *line, int length, int firstValid, int64_t lineStart, unsigned int *rgb) |
||||
{ |
||||
resize(length); |
||||
|
||||
// DC restore at the blanking level. The burst averages to zero, so the burst window
|
||||
// gives the blanking level
|
||||
if ((firstValid <= m_tipStart) && (length > m_burstEnd)) |
||||
{ |
||||
float tip = 0.0f; |
||||
float blank = 0.0f; |
||||
|
||||
for (int n = m_tipStart; n < m_tipEnd; n++) { |
||||
tip += line[n]; |
||||
} |
||||
|
||||
for (int n = m_burstStart; n < m_burstEnd; n++) { |
||||
blank += line[n]; |
||||
} |
||||
|
||||
tip /= m_tipEnd - m_tipStart; |
||||
blank /= m_burstEnd - m_burstStart; |
||||
|
||||
bool valid = m_carrierReferenced ? (tip - blank > 0.02f * tip) : (blank - tip > 0.02f); |
||||
|
||||
if (valid) |
||||
{ |
||||
if (m_levelsValid) |
||||
{ |
||||
m_tipLevel += 0.2f * (tip - m_tipLevel); |
||||
m_blankLevel += 0.2f * (blank - m_blankLevel); |
||||
} |
||||
else |
||||
{ |
||||
m_tipLevel = tip; |
||||
m_blankLevel = blank; |
||||
m_levelsValid = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (!m_levelsValid) |
||||
{ |
||||
for (int n = 0; n < length; n++) { |
||||
rgb[n] = packRGB(line[n], line[n], line[n]); |
||||
} |
||||
|
||||
return; |
||||
} |
||||
|
||||
// Scale to IRE. From the depth of sync, unless the carrier level is known, when the sync
|
||||
// tip carrier is used as a TV's keyed AGC does: sync is often compressed in transmission
|
||||
// or by fading, which would exaggerate the gain
|
||||
float scale = m_carrierReferenced |
||||
? -100.0f / ((m_blankCarrier - m_whiteCarrier) * m_tipLevel) |
||||
: m_syncDepth / (m_blankLevel - m_tipLevel); |
||||
|
||||
for (int n = 0; n < length; n++) |
||||
{ |
||||
m_ire[n] = (line[n] - m_blankLevel) * scale; |
||||
m_mixedRe[n] = m_ire[n] * m_phasor[n].real(); |
||||
m_mixedIm[n] = m_ire[n] * m_phasor[n].imag(); |
||||
} |
||||
|
||||
// Baseband chroma, filtered every m_chromaDecimation samples and linearly interpolated between
|
||||
int d = m_chromaDecimation; |
||||
int last = 0; |
||||
m_chroma[0] = filterChroma(0, length); |
||||
|
||||
for (int n = d; n < length; n += d) |
||||
{ |
||||
m_chroma[n] = filterChroma(n, length); |
||||
|
||||
for (int i = 1; i < d; i++) { |
||||
m_chroma[last + i] = m_chroma[last] + (m_chroma[n] - m_chroma[last]) * ((float) i / d); |
||||
} |
||||
|
||||
last = n; |
||||
} |
||||
|
||||
for (int n = last + 1; n < length; n++) { |
||||
m_chroma[n] = m_chroma[last]; |
||||
} |
||||
|
||||
// m_phasor restarts at each line, but the subcarrier does not (in NTSC its phase is
|
||||
// inverted on successive lines), so bursts are compared at a phase continuous across lines
|
||||
double w = 2.0 * M_PI * m_subcarrierFrequency / m_sampleRate; |
||||
std::complex<float> lineRotation = std::polar(1.0f, (float) -std::fmod(w * (double) lineStart, 2.0 * M_PI)); |
||||
|
||||
// Burst
|
||||
bool burstValid = (firstValid <= m_burstStart) && (length > m_burstEnd); |
||||
bool burstPresent = false; |
||||
std::complex<float> burst = 0.0f; |
||||
|
||||
if (burstValid) |
||||
{ |
||||
for (int n = m_burstStart; n < m_burstEnd; n++) { |
||||
burst += m_chroma[n]; |
||||
} |
||||
|
||||
burst *= lineRotation / (float) (m_burstEnd - m_burstStart); |
||||
float amplitude = std::abs(burst); |
||||
burstPresent = amplitude > 0.25f * m_nominalBurst; |
||||
|
||||
if (burstPresent) { |
||||
m_burstAmplitude += 0.1f * (amplitude - m_burstAmplitude); |
||||
} |
||||
|
||||
if (m_pal) |
||||
{ |
||||
// Successive bursts swing +/-45 degrees either side of -U, so their sum points along -U
|
||||
if (burstPresent && (std::abs(m_prevBurst) > 0.0f)) { |
||||
m_burstRef += 0.3f * (burst + m_prevBurst - m_burstRef); |
||||
} |
||||
|
||||
m_prevBurst = burstPresent ? burst : 0.0f; |
||||
} |
||||
else if (burstPresent) |
||||
{ |
||||
m_burstRef += 0.3f * (burst - m_burstRef); |
||||
} |
||||
} |
||||
|
||||
// Colour killer: off when no burst for longer than the vertical blanking interval
|
||||
m_missingBursts = burstPresent ? 0 : m_missingBursts + 1; |
||||
m_colourOn = (m_missingBursts < 50) && (std::abs(m_burstRef) > 0.25f * m_nominalBurst); |
||||
|
||||
float range = 100.0f - m_setup; |
||||
|
||||
if (!m_colourOn) |
||||
{ |
||||
for (int n = 0; n < length; n++) |
||||
{ |
||||
float y = (m_ire[n] - m_setup) / range; |
||||
rgb[n] = packRGB(y, y, y); |
||||
} |
||||
|
||||
return; |
||||
} |
||||
|
||||
// Rotate so the burst reference is at 180 degrees (-U); U is then real and V imaginary
|
||||
std::complex<float> rot = -std::conj(m_burstRef) / std::abs(m_burstRef); |
||||
|
||||
if (m_pal) |
||||
{ |
||||
// V switch: the burst is at 135 degrees on lines where V is not inverted
|
||||
if (burstPresent) { |
||||
m_vSign = (burst * rot).imag() > 0.0f ? 1.0f : -1.0f; |
||||
} else { |
||||
m_vSign = -m_vSign; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
rot *= m_hue; |
||||
} |
||||
|
||||
rot *= lineRotation * (m_saturation * m_nominalBurst / std::max(m_burstAmplitude, 1.0f) / range); |
||||
|
||||
smoothChroma(m_chroma, m_chromaDisplay, length); |
||||
smoothChroma(m_chromaDisplay, m_chromaDisplay, length); |
||||
|
||||
for (int n = 0; n < length; n++) |
||||
{ |
||||
const std::complex<float>& c = m_chroma[n]; |
||||
float chroma = 0.5f * (c.real() * m_phasor[n].real() + c.imag() * m_phasor[n].imag()); // Re(c * conj(phasor)) / 2
|
||||
float y = (m_ire[n] - chroma - m_setup) / range; |
||||
std::complex<float> uv = m_chromaDisplay[n] * rot; |
||||
|
||||
if (m_pal) { |
||||
uv.imag(uv.imag() * m_vSign); |
||||
} |
||||
|
||||
// PAL's delay line cancels phase errors. For NTSC too, averaging with the previous line
|
||||
// of the field halves the chroma noise, for half the vertical chroma resolution
|
||||
if (m_delayLine) |
||||
{ |
||||
std::complex<float> current = uv; |
||||
uv = 0.5f * (uv + m_prevUV[n]); |
||||
m_prevUV[n] = current; |
||||
} |
||||
|
||||
float ry = uv.imag() / 0.877f; |
||||
float by = uv.real() / 0.492f; |
||||
rgb[n] = packRGB(y + ry, y - 0.509f * ry - 0.194f * by, y + by); |
||||
} |
||||
} |
||||
@ -0,0 +1,295 @@
@@ -0,0 +1,295 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// Some code by AI //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_ATVCOLOURDECODER_H |
||||
#define INCLUDE_ATVCOLOURDECODER_H |
||||
|
||||
#include <complex> |
||||
#include <cstdint> |
||||
#include <vector> |
||||
|
||||
#include "dsp/dsptypes.h" |
||||
|
||||
#include "atvdemodsettings.h" |
||||
|
||||
class FFTEngine; |
||||
|
||||
/**
|
||||
* Front end for AM / VSB signals. |
||||
* |
||||
* Applies a Nyquist slope through the vision carrier, as a TV receiver's IF filter does, |
||||
* which flattens the response across the vestigial sideband and removes anything below |
||||
* the carrier (such as an aliased sound carrier). It also band limits above the video |
||||
* (the chroma for colour) and upsamples by an integer factor in the frequency domain, so |
||||
* the envelope of the signal can be taken without aliasing. |
||||
* |
||||
* For colour, input should have the centre of the video band at DC (see |
||||
* ATVDemodSettings::getColourBandCentreOffset). For mono without upsampling, it should |
||||
* have the vision carrier at DC, so the video is band limited to half the sample rate. |
||||
*/ |
||||
class ATVVSBFrontEnd |
||||
{ |
||||
public: |
||||
ATVVSBFrontEnd(); |
||||
~ATVVSBFrontEnd(); |
||||
ATVVSBFrontEnd(const ATVVSBFrontEnd&) = delete; |
||||
ATVVSBFrontEnd& operator=(const ATVVSBFrontEnd&) = delete; |
||||
|
||||
/**
|
||||
* @param sampleRate input sample rate |
||||
* @param carrierOffset frequency of the vision carrier in the input (Hz) |
||||
* @param videoBandwidth top of the video above the vision carrier (Hz) |
||||
* @param usb true when the video is above the vision carrier |
||||
* @param upsampling integer upsampling factor (1, 2 or 4) |
||||
*/ |
||||
void configure(int sampleRate, float carrierOffset, float videoBandwidth, bool usb, int upsampling); |
||||
|
||||
/** Returns the number of output samples in *out, which is 0 until a block completes */ |
||||
int process(const Complex& in, Complex **out) |
||||
{ |
||||
m_fftIn[m_inCount++] = in; |
||||
|
||||
if (m_inCount < m_blockLen) { |
||||
return 0; |
||||
} |
||||
|
||||
m_inCount = 0; |
||||
int n = processBlock(out); |
||||
|
||||
// Drop the start-up transient while the overlap fills, as it would upset the AGC
|
||||
if (m_skipBlocks > 0) |
||||
{ |
||||
m_skipBlocks--; |
||||
return 0; |
||||
} |
||||
|
||||
return n; |
||||
} |
||||
|
||||
private: |
||||
static const int m_fftLen = 1024; //!< Input FFT length
|
||||
static const int m_blockLen = m_fftLen / 2; //!< Input samples per block (and filter length)
|
||||
|
||||
int m_upsampling; |
||||
FFTEngine *m_fft; |
||||
unsigned int m_fftSequence; |
||||
FFTEngine *m_ifft; |
||||
unsigned int m_ifftSequence; |
||||
Complex *m_fftIn; //!< m_fft's input, filled a block at a time
|
||||
std::vector<Complex> m_response; //!< Filter frequency response, m_fftLen bins, scaled by 1 / m_fftLen
|
||||
std::vector<Complex> m_overlap; |
||||
std::vector<Complex> m_out; |
||||
int m_inCount; |
||||
int m_skipBlocks; |
||||
|
||||
int processBlock(Complex **out); |
||||
}; |
||||
|
||||
/**
|
||||
* Synchronous AM detector for the front end's output. |
||||
* |
||||
* Envelope detection of a vestigial sideband signal adds a quadrature distortion that |
||||
* grows with the square of the chroma, darkening saturated colours, so the vision carrier |
||||
* is recovered and the in-phase component taken instead, as a TV does. |
||||
* |
||||
* Carrier recovery is keyed to the sync tips, where the carrier is not modulated by the |
||||
* picture. Transmitters that overmodulate cut the carrier off in white areas and shift its |
||||
* phase, and through the Nyquist slope the picture's own detail is lopsided about the |
||||
* carrier, which an unkeyed loop reads as a frequency error (+3.5 kHz on a white text page, |
||||
* enough to tear the picture). Even within a sync tip the phase ramps, as the filter adds a |
||||
* quadrature component at the pulse's edges, so frequency is measured between matching |
||||
* points rather than along a pulse: |
||||
* - fine: the phase of each line's sync tip against the previous line's. This is unbiased, |
||||
* but unambiguous only to half the line rate (+/- 7.8 kHz for 525 lines) |
||||
* - coarse: the phase change along the flat middle of the vertical sync's broad pulses, |
||||
* away from their edges, which corrects the fine loop when it is a line rate out |
||||
* The phase comes from a narrow low pass of the samples within 85% of the sync tip carrier. |
||||
*/ |
||||
class ATVSynchronousDetector |
||||
{ |
||||
public: |
||||
ATVSynchronousDetector(); |
||||
|
||||
/**
|
||||
* @param carrierFrequency nominal frequency of the vision carrier in the input (Hz) |
||||
* @param lineFrequency lines per second |
||||
*/ |
||||
void configure(float sampleRate, float carrierFrequency, float lineFrequency); |
||||
|
||||
/** Returns the in-phase amplitude, which is the envelope when the carrier is tracked */ |
||||
float process(const std::complex<float>& in) |
||||
{ |
||||
std::complex<float> mixed = in * m_rotation; |
||||
m_rotation *= m_step; |
||||
m_ghostInput = mixed; |
||||
|
||||
if (m_ghostOn) |
||||
{ |
||||
// y[n] = x[n] - g y[n - D], which cancels an echo g x[n - D] exactly
|
||||
int i0 = (m_ghostIndex - m_ghostDelay) & m_ghostMask; |
||||
int i1 = (i0 - 1) & m_ghostMask; |
||||
mixed -= m_ghostGain * (m_ghostBuffer[i0] + m_ghostFrac * (m_ghostBuffer[i1] - m_ghostBuffer[i0])); |
||||
m_ghostBuffer[m_ghostIndex] = mixed; |
||||
m_ghostIndex = (m_ghostIndex + 1) & m_ghostMask; |
||||
} |
||||
|
||||
if (std::norm(mixed) > m_keyLevel) { |
||||
m_phaseCarrier += m_phaseLowPassAlpha * (mixed - m_phaseCarrier); |
||||
} |
||||
|
||||
m_block += mixed; |
||||
float out = mixed.real() * m_carrierUnit.real() - mixed.imag() * m_carrierUnit.imag(); // Re(mixed * unit)
|
||||
|
||||
if (++m_count == m_blockLength) { |
||||
update(); |
||||
} |
||||
|
||||
return out; |
||||
} |
||||
|
||||
float getFrequencyError() const; //!< Hz, carrier relative to its nominal frequency
|
||||
|
||||
/**
|
||||
* Cancels an echo (ghost) of the signal, delayed by delay samples (1 or more) with the |
||||
* given gain relative to the carrier. 0 gain turns cancellation off |
||||
*/ |
||||
void setGhost(float delay, std::complex<float> gain); |
||||
/** The last sample before ghost cancellation, with the carrier's phase removed (real is the in-phase amplitude) */ |
||||
std::complex<float> getGhostInput() const { return m_ghostInput * m_carrierUnit; } |
||||
|
||||
private: |
||||
static const int m_ghostBufferSize = 256; //!< samples, a power of 2
|
||||
static const int m_ghostMask = m_ghostBufferSize - 1; |
||||
static const int m_maxRunBlocks = 64; //!< longer runs (when the blanking is keyed through the vertical interval) are not used
|
||||
static const int m_runEdgeBlocks = 3; //!< blocks at each end of a broad pulse left out of the coarse estimate
|
||||
static const int m_settleBlocks = 2000; //!< blocks for the sync tip level to settle before keying
|
||||
|
||||
float m_sampleRate; |
||||
int m_blockLength; //!< samples per block, ~1 us, so several fit in a sync tip
|
||||
float m_linePeriod; //!< samples
|
||||
double m_nominalStep; //!< radians / sample
|
||||
double m_frequency; //!< FLL correction, radians / sample
|
||||
std::complex<float> m_rotation; |
||||
std::complex<float> m_step; |
||||
std::complex<float> m_phaseCarrier; //!< narrow low pass of the keyed samples, for the phase
|
||||
std::complex<float> m_carrierUnit; |
||||
float m_phaseLowPassAlpha; |
||||
int m_count; |
||||
std::complex<float> m_block; //!< sum of the samples in the current block
|
||||
int64_t m_blockIndex; |
||||
float m_tipLevel; //!< sync tip block amplitude
|
||||
float m_keyLevel; //!< power above which samples are used for the phase
|
||||
std::vector<std::complex<float>> m_run; //!< blocks of the current sync tip
|
||||
int64_t m_runStart; //!< block index
|
||||
bool m_runOverflow; |
||||
std::complex<float> m_prevRunSum; |
||||
int m_prevRunLength; |
||||
int64_t m_prevRunStart; |
||||
std::complex<float> m_coarseSum; //!< phase change per block along broad pulses
|
||||
int m_coarseCount; |
||||
bool m_ghostOn; |
||||
int m_ghostDelay; //!< samples, integer part
|
||||
float m_ghostFrac; //!< samples, fractional part
|
||||
std::complex<float> m_ghostGain; |
||||
std::vector<std::complex<float>> m_ghostBuffer; //!< output, for the cancellation's feedback
|
||||
int m_ghostIndex; |
||||
std::complex<float> m_ghostInput; |
||||
|
||||
void update(); |
||||
void endRun(); |
||||
}; |
||||
|
||||
/**
|
||||
* Decodes NTSC and PAL colour, one line at a time. |
||||
* |
||||
* Works on a whole line of composite video once it is complete, so its filters can be |
||||
* zero phase and the burst, which comes before the active video, is known before any |
||||
* pixel is decoded. |
||||
*/ |
||||
class ATVColourDecoder |
||||
{ |
||||
public: |
||||
ATVColourDecoder(); |
||||
|
||||
void configure(float sampleRate, ATVDemodSettings::ColourSystem colourSystem); |
||||
void setSaturation(int saturation) { m_saturation = saturation / 100.0f; } |
||||
void setHue(int hue) { m_hue = std::polar(1.0f, hue * (float) M_PI / 180.0f); } |
||||
void setDelayLine(bool delayLine) { m_delayLine = delayLine; } |
||||
/** Line is the envelope of a negatively modulated AM signal, rather than video scaled with sync tip low */ |
||||
void setCarrierReferenced(bool carrierReferenced) { m_carrierReferenced = carrierReferenced; } |
||||
|
||||
/**
|
||||
* Decode one line. |
||||
* |
||||
* @param line composite samples, index 0 at the leading edge of the sync pulse, scaled so sync tip is low, |
||||
* or the AM envelope when carrier referenced |
||||
* @param length number of samples in the line |
||||
* @param firstValid first index written for this line (earlier ones are stale after a sync jump) |
||||
* @param lineStart sample count at index 0 of the line, so the subcarrier phase is continuous across lines |
||||
* @param rgb output, packed as 0x00BBGGRR (the byte order the TV screen texture uses) |
||||
*/ |
||||
void decodeLine(const float *line, int length, int firstValid, int64_t lineStart, unsigned int *rgb); |
||||
|
||||
bool getColourLocked() const { return m_colourOn; } |
||||
float getBurstAmplitude() const { return m_burstAmplitude; } //!< Smoothed burst amplitude, IRE
|
||||
|
||||
private: |
||||
float m_sampleRate; |
||||
float m_subcarrierFrequency; |
||||
bool m_pal; |
||||
float m_syncDepth; //!< Sync depth below blanking, IRE
|
||||
float m_nominalBurst; //!< Nominal burst peak amplitude, IRE
|
||||
float m_setup; //!< Black level above blanking, IRE
|
||||
float m_blankCarrier; //!< Blanking and white carrier levels, fraction of the sync tip, when carrier referenced
|
||||
float m_whiteCarrier; |
||||
int m_tipStart, m_tipEnd; |
||||
int m_burstStart, m_burstEnd; |
||||
int m_chromaDecimation; //!< Chroma is band limited, so is only filtered every this many samples
|
||||
|
||||
bool m_carrierReferenced; |
||||
float m_saturation; |
||||
std::complex<float> m_hue; |
||||
bool m_delayLine; |
||||
|
||||
std::vector<float> m_lpfTaps; //!< Chroma low pass (zero phase, odd length)
|
||||
std::vector<std::complex<float>> m_phasor; //!< 2 * exp(-j w n) for the subcarrier, from the start of the line
|
||||
std::vector<float> m_ire; |
||||
std::vector<float> m_mixedRe; //!< Composite mixed down by the subcarrier
|
||||
std::vector<float> m_mixedIm; |
||||
std::vector<std::complex<float>> m_chroma; //!< Baseband chroma, every sample
|
||||
std::vector<std::complex<float>> m_chromaSum; //!< Running sums for smoothing the displayed chroma
|
||||
std::vector<std::complex<float>> m_chromaDisplay; |
||||
int m_chromaSmoothing; //!< Boxcar length, applied twice
|
||||
std::vector<std::complex<float>> m_prevUV; //!< Previous line's U + jV for the delay line
|
||||
|
||||
float m_tipLevel; |
||||
float m_blankLevel; |
||||
bool m_levelsValid; |
||||
std::complex<float> m_burstRef; //!< Smoothed burst vector (NTSC) or sum of two lines' bursts (PAL)
|
||||
std::complex<float> m_prevBurst; |
||||
float m_burstAmplitude; |
||||
bool m_colourOn; |
||||
int m_missingBursts; //!< Consecutive lines without a burst
|
||||
float m_vSign; //!< PAL V switch for the current line
|
||||
|
||||
void resize(int length); |
||||
void smoothChroma(std::vector<std::complex<float>>& in, std::vector<std::complex<float>>& out, int length); |
||||
std::complex<float> filterChroma(int n, int length) const; |
||||
}; |
||||
|
||||
#endif // INCLUDE_ATVCOLOURDECODER_H
|
||||
@ -0,0 +1,322 @@
@@ -0,0 +1,322 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// Some code by AI //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <algorithm> |
||||
#include <cmath> |
||||
|
||||
#include "atvghostestimator.h" |
||||
|
||||
namespace { |
||||
|
||||
typedef std::complex<double> Cd; |
||||
|
||||
// Signal delayed by a fractional number of samples: v[k - delay], or v[0] before the start
|
||||
Cd delayed(const std::vector<Cd>& v, int k, double delay) |
||||
{ |
||||
double x = k - delay; |
||||
|
||||
if (x <= 0.0) { |
||||
return v[0]; |
||||
} |
||||
|
||||
int i = (int) x; |
||||
double f = x - i; |
||||
return i + 1 < (int) v.size() ? v[i] + f * (v[i + 1] - v[i]) : v[i]; |
||||
} |
||||
|
||||
// y[k] = a[k] - g y[k - delay], as the detector cancels
|
||||
std::vector<Cd> cancel(const std::vector<Cd>& a, double delay, Cd gain) |
||||
{ |
||||
std::vector<Cd> y(a); |
||||
|
||||
for (int k = (int) std::ceil(delay) + 1; k < (int) a.size(); k++) { |
||||
y[k] = a[k] - gain * delayed(y, k, delay); |
||||
} |
||||
|
||||
return y; |
||||
} |
||||
|
||||
} |
||||
|
||||
// Keeps the trial cancellations stable
|
||||
std::complex<double> ATVGhostEstimator::limitGain(std::complex<double> gain) |
||||
{ |
||||
return std::abs(gain) > m_maxGain ? gain * (m_maxGain / std::abs(gain)) : gain; |
||||
} |
||||
|
||||
ATVGhostEstimator::ATVGhostEstimator() |
||||
{ |
||||
configure(10000000.0f, 640, 4.2e6f); |
||||
} |
||||
|
||||
void ATVGhostEstimator::configure(float sampleRate, int samplesPerLine, float videoBandwidth) |
||||
{ |
||||
auto us = [sampleRate](double t) { return (int) std::round(t * 1e-6 * sampleRate); }; |
||||
double ringing = 1.25e6 / videoBandwidth; // us, for the edges' own response to settle
|
||||
|
||||
m_sampleRate = sampleRate; |
||||
m_samplesPerLine = samplesPerLine; |
||||
m_pre = us(8.0); // the echo of what is up to 4 us before the tip, and history for its cancellation
|
||||
m_post = us(9.0); |
||||
m_tipStart = us(std::max(0.5, ringing)); |
||||
m_tipMid = us(2.3); |
||||
m_tipEnd = us(4.2); |
||||
m_backPorchStart = us(5.3); |
||||
m_backPorchEnd = us(8.5); |
||||
m_frontPorchStart = -us(1.2); |
||||
m_frontPorchEnd = -us(0.3); |
||||
m_maxDelay = 4.0e-6 * sampleRate; |
||||
// Below 2 MHz, the edges ring for so long that tuning errors look like echoes
|
||||
m_minDelay = videoBandwidth < 2.0e6f ? m_maxDelay : std::max(1.0, 1e-6 * sampleRate * std::max(1.0, 2.0 * ringing)); |
||||
m_delayStep = 0.1e-6 * sampleRate; |
||||
m_sharpness = 0.5e-6 * sampleRate; |
||||
m_line.assign(m_pre + m_post, 0.0f); |
||||
m_next.assign(m_pre, 0.0f); |
||||
reset(); |
||||
} |
||||
|
||||
void ATVGhostEstimator::reset() |
||||
{ |
||||
m_sum.assign(m_pre + m_post, 0.0); |
||||
m_lines = 0; |
||||
m_lastOffset = 0; |
||||
m_misses = 0; |
||||
m_delay = (float) m_minDelay; |
||||
m_gain = 0.0f; |
||||
} |
||||
|
||||
bool ATVGhostEstimator::feed(int sampleOffset, std::complex<float> z) |
||||
{ |
||||
if (sampleOffset < m_lastOffset) { |
||||
std::copy(m_next.begin(), m_next.end(), m_line.begin()); // a new line has started
|
||||
} |
||||
|
||||
m_lastOffset = sampleOffset; |
||||
int k = sampleOffset - (m_samplesPerLine - m_pre); |
||||
|
||||
if ((k >= 0) && (k < m_pre)) |
||||
{ |
||||
m_next[k] = z; |
||||
} |
||||
else if ((sampleOffset >= 0) && (sampleOffset < m_post)) |
||||
{ |
||||
m_line[m_pre + sampleOffset] = z; |
||||
|
||||
if (sampleOffset == m_post - 1) { |
||||
return endLine(); |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
bool ATVGhostEstimator::endLine() |
||||
{ |
||||
auto mean = [this](int start, int end) { |
||||
double sum = 0.0; |
||||
for (int i = m_pre + start; i < m_pre + end; i++) { |
||||
sum += m_line[i].real(); |
||||
} |
||||
return sum / (end - start); |
||||
}; |
||||
|
||||
// Only ordinary line sync pulses (not the vertical interval's): sync over the whole tip,
|
||||
// blanking either side. The echo can raise the second half of the tip
|
||||
double tipA = mean(m_tipStart, m_tipMid); |
||||
double tipB = mean(m_tipMid, m_tipEnd); |
||||
double backPorch = mean(m_backPorchStart, m_backPorchEnd); |
||||
double frontPorch = mean(m_frontPorchStart, m_frontPorchEnd); |
||||
double step = tipA - backPorch; |
||||
|
||||
if ((step > 0.1 * tipA) && (tipB - backPorch > 0.5 * step) && (tipA - frontPorch > 0.5 * step)) |
||||
{ |
||||
for (int i = 0; i < (int) m_line.size(); i++) { |
||||
m_sum[i] += Cd(m_line[i].real(), m_line[i].imag()); |
||||
} |
||||
|
||||
m_lines++; |
||||
} |
||||
|
||||
if (m_lines < m_linesPerEstimate) { |
||||
return false; |
||||
} |
||||
|
||||
estimate(); |
||||
std::fill(m_sum.begin(), m_sum.end(), 0.0); |
||||
m_lines = 0; |
||||
return true; |
||||
} |
||||
|
||||
void ATVGhostEstimator::estimate() |
||||
{ |
||||
if (m_minDelay + m_sharpness > m_maxDelay) { |
||||
return; // the video bandwidth is too narrow to tell an echo from the edges' ringing
|
||||
} |
||||
|
||||
std::vector<Cd> a(m_sum.size()); |
||||
|
||||
for (int i = 0; i < (int) a.size(); i++) { |
||||
a[i] = m_sum[i] / (double) m_lines; |
||||
} |
||||
|
||||
const int windows[2][2] = { |
||||
{m_pre + m_tipStart, m_pre + m_tipEnd}, |
||||
{m_pre + m_backPorchStart, m_pre + m_backPorchEnd} |
||||
}; |
||||
|
||||
// Power of the in-phase signal's variation about its mean, within each window
|
||||
auto flatness = [&windows](const std::vector<Cd>& y) { |
||||
double power = 0.0; |
||||
for (const auto& w : windows) |
||||
{ |
||||
double mean = 0.0; |
||||
for (int k = w[0]; k < w[1]; k++) { |
||||
mean += y[k].real(); |
||||
} |
||||
mean /= w[1] - w[0]; |
||||
for (int k = w[0]; k < w[1]; k++) { |
||||
power += (y[k].real() - mean) * (y[k].real() - mean); |
||||
} |
||||
} |
||||
return power; |
||||
}; |
||||
|
||||
// Least squares gain of an echo at the given delay in y (the in-phase part of y - g y[k - delay] flattest)
|
||||
auto fitGain = [&windows](const std::vector<Cd>& y, double delay) { |
||||
double uu = 0.0, uv = 0.0, vv = 0.0, ut = 0.0, vt = 0.0; |
||||
for (const auto& w : windows) |
||||
{ |
||||
int n = w[1] - w[0]; |
||||
double mt = 0.0, mu = 0.0, mv = 0.0; |
||||
for (int k = w[0]; k < w[1]; k++) |
||||
{ |
||||
Cd d = delayed(y, k, delay); |
||||
mt += y[k].real(); |
||||
mu += d.real(); |
||||
mv -= d.imag(); |
||||
} |
||||
mt /= n; mu /= n; mv /= n; |
||||
for (int k = w[0]; k < w[1]; k++) |
||||
{ |
||||
Cd d = delayed(y, k, delay); |
||||
double t = y[k].real() - mt; |
||||
double u = d.real() - mu; |
||||
double v = -d.imag() - mv; |
||||
uu += u * u; uv += u * v; vv += v * v; ut += u * t; vt += v * t; |
||||
} |
||||
} |
||||
double det = uu * vv - uv * uv; |
||||
return det > 0.0 ? Cd((vv * ut - uv * vt) / det, (uu * vt - uv * ut) / det) : Cd(0.0); |
||||
}; |
||||
|
||||
// Gain of an echo at this delay, refined on the cancelled signal, and how flat that leaves it
|
||||
auto fitEcho = [&](double delay, Cd& gain) { |
||||
gain = limitGain(fitGain(a, delay)); |
||||
for (int i = 0; i < 3; i++) { |
||||
gain = limitGain(gain + fitGain(cancel(a, delay, gain), delay)); |
||||
} |
||||
return flatness(cancel(a, delay, gain)); |
||||
}; |
||||
|
||||
double original = flatness(a); |
||||
|
||||
if (original <= 0.0) { |
||||
return; |
||||
} |
||||
|
||||
// Search in steps of 0.1 us, then refine about the best
|
||||
std::vector<double> delays, flat; |
||||
|
||||
for (double delay = m_minDelay; delay <= m_maxDelay; delay += m_delayStep) |
||||
{ |
||||
delays.push_back(delay); |
||||
flat.push_back(flatness(cancel(a, delay, limitGain(fitGain(a, delay)))) / original); |
||||
} |
||||
|
||||
// While an echo is being cancelled, look for it near where it was, and keep it unless it has
|
||||
// clearly gone, so the cancellation does not come and go as the picture changes
|
||||
bool tracking = m_gain != 0.0f; |
||||
int side = (int) std::round(m_sharpness / m_delayStep); |
||||
int first = 0, last = (int) flat.size() - 1; |
||||
|
||||
if (tracking) |
||||
{ |
||||
int centre = (int) std::round((m_delay - m_minDelay) / m_delayStep); |
||||
first = std::max(first, centre - side); |
||||
last = std::min(last, centre + side); |
||||
} |
||||
|
||||
int best = (int) (std::min_element(flat.begin() + first, flat.begin() + last + 1) - flat.begin()); |
||||
|
||||
// An echo flattens the sync region at its delay, and clearly less so either side
|
||||
double worse = 1.0; |
||||
|
||||
if (best - side >= 0) { |
||||
worse = std::min(worse, flat[best - side]); |
||||
} |
||||
if (best + side < (int) flat.size()) { |
||||
worse = std::min(worse, flat[best + side]); |
||||
} |
||||
|
||||
Cd gain = 0.0; |
||||
double delay = delays[best]; |
||||
double sharpness = tracking ? m_keepSharpness : m_minSharpness; |
||||
|
||||
if ((flat[best] < m_minImprovement) && (worse - flat[best] > sharpness * (1.0 - flat[best]))) |
||||
{ |
||||
double f[3]; |
||||
for (int i = 0; i < 3; i++) { |
||||
f[i] = fitEcho(delay + 0.5 * m_delayStep * (i - 1), gain); |
||||
} |
||||
|
||||
double curvature = f[0] - 2.0 * f[1] + f[2]; |
||||
double offset = curvature > 0.0 ? 0.25 * (f[0] - f[2]) / curvature : 0.0; |
||||
delay = std::max(m_minDelay, std::min(m_maxDelay, delay + m_delayStep * std::max(-0.5, std::min(0.5, offset)))); |
||||
|
||||
if (fitEcho(delay, gain) >= m_minImprovement * original) { |
||||
gain = 0.0; |
||||
} |
||||
} |
||||
|
||||
std::complex<float> g((float) gain.real(), (float) gain.imag()); |
||||
|
||||
if (g == 0.0f) |
||||
{ |
||||
// No echo: after several estimates without it, let it fade
|
||||
if (++m_misses >= m_maxMisses) |
||||
{ |
||||
m_gain *= 1.0f - m_smoothing; |
||||
|
||||
if (std::abs(m_gain) < 0.02f) { |
||||
m_gain = 0.0f; |
||||
} |
||||
} |
||||
} |
||||
else if (!tracking) |
||||
{ |
||||
m_misses = 0; |
||||
m_delay = (float) delay; |
||||
m_gain = m_smoothing * g; |
||||
} |
||||
else |
||||
{ |
||||
m_misses = 0; |
||||
m_delay += m_smoothing * ((float) delay - m_delay); |
||||
m_gain += m_smoothing * (g - m_gain); |
||||
} |
||||
} |
||||
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// Some code by AI //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_ATVGHOSTESTIMATOR_H |
||||
#define INCLUDE_ATVGHOSTESTIMATOR_H |
||||
|
||||
#include <complex> |
||||
#include <vector> |
||||
|
||||
/**
|
||||
* Estimates an echo (ghost) from multipath, for ATVSynchronousDetector to cancel. |
||||
* |
||||
* An echo is a delayed copy of the whole signal, so it puts a copy of each horizontal sync |
||||
* pulse's edges on the sync tip and back porch, which are otherwise flat. The detector's |
||||
* complex output, before cancellation and with the carrier's phase removed, is averaged |
||||
* around the sync pulses of many lines (which averages out the noise and the picture, and |
||||
* for NTSC and PAL, the colour burst). The echo is the delay and complex gain that, cancelled |
||||
* from that average, leave the sync tip and back porch flattest. The gain is complex as the |
||||
* echo's carrier arrives with a different phase, so part of it is in quadrature: after the |
||||
* vestigial sideband filter that is a distorted copy of the picture's detail. |
||||
* |
||||
* No reference waveform is needed, so the transmitter's filtering, which shapes the pulse |
||||
* edges, is not mistaken for an echo. Echoes shorter than 1 us (longer when the video |
||||
* bandwidth is narrow, as the edges ring for longer) cannot be told apart from that |
||||
* filtering, and only one echo, up to 4 us, is found. Other linear distortion, such as from |
||||
* the vestigial sideband filter when mistuned, flattens the tip almost as well over a wide |
||||
* range of delays, so only a delay clearly better than those either side is taken as an echo. |
||||
*/ |
||||
class ATVGhostEstimator |
||||
{ |
||||
public: |
||||
ATVGhostEstimator(); |
||||
|
||||
/** videoBandwidth limits how short an echo can be told apart from the edges' own ringing */ |
||||
void configure(float sampleRate, int samplesPerLine, float videoBandwidth); |
||||
void reset(); //!< Forget the estimate
|
||||
|
||||
/**
|
||||
* Feed the detector's output before ghost cancellation, with the sample's position in the |
||||
* line (0 at the sync pulse's leading edge). Returns true when the estimate is updated |
||||
*/ |
||||
bool feed(int sampleOffset, std::complex<float> z); |
||||
|
||||
float getDelay() const { return m_delay; } //!< samples
|
||||
std::complex<float> getGain() const { return m_gain; } //!< 0 when there is no echo
|
||||
float getDelaySeconds() const { return m_delay / m_sampleRate; } |
||||
|
||||
private: |
||||
static constexpr int m_linesPerEstimate = 500; //!< ~1 frame
|
||||
static constexpr double m_minImprovement = 0.9; //!< the echo must make the sync region at least 10% flatter (in power)
|
||||
static constexpr double m_minSharpness = 0.4; //!< and delays 0.5 us either side must leave at least 40% of that improvement
|
||||
static constexpr double m_keepSharpness = 0.2; //!< or 20%, for an echo already being cancelled
|
||||
static constexpr int m_maxMisses = 4; //!< estimates without the echo before it fades
|
||||
static constexpr float m_smoothing = 0.3f; //!< of successive estimates
|
||||
static constexpr float m_maxGain = 0.7f; |
||||
|
||||
float m_sampleRate; |
||||
int m_samplesPerLine; |
||||
int m_pre; //!< samples kept before the sync's leading edge
|
||||
int m_post; //!< samples kept after it
|
||||
int m_tipStart, m_tipMid, m_tipEnd; //!< sync tip, after the edge (two halves, to recognise sync pulses)
|
||||
int m_backPorchStart, m_backPorchEnd; |
||||
int m_frontPorchStart, m_frontPorchEnd; //!< before the edge (negative)
|
||||
double m_minDelay, m_maxDelay; //!< samples
|
||||
double m_delayStep; //!< samples, of the search
|
||||
double m_sharpness; //!< samples either side of an echo's delay that must flatten the tip less
|
||||
std::vector<std::complex<float>> m_line; //!< the current line's samples, from -m_pre
|
||||
std::vector<std::complex<float>> m_next; //!< the end of the current line, which starts the next
|
||||
std::vector<std::complex<double>> m_sum; |
||||
int m_lines; |
||||
int m_lastOffset; |
||||
int m_misses; //!< successive estimates without the echo
|
||||
float m_delay; |
||||
std::complex<float> m_gain; |
||||
|
||||
bool endLine(); |
||||
void estimate(); |
||||
static std::complex<double> limitGain(std::complex<double> gain); |
||||
}; |
||||
|
||||
#endif // INCLUDE_ATVGHOSTESTIMATOR_H
|
||||
@ -0,0 +1,142 @@
@@ -0,0 +1,142 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// Some code by AI //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <algorithm> |
||||
#include <cmath> |
||||
|
||||
#include "atvnoisereduction.h" |
||||
|
||||
static const int histogramBinsPerLevel = 4; |
||||
|
||||
ATVNoiseReduction::ATVNoiseReduction() : |
||||
m_width(0), |
||||
m_height(0), |
||||
m_strength(0.0f), |
||||
m_histogramCount(0), |
||||
m_threshold(0.0f), |
||||
m_window(7) |
||||
{ |
||||
m_histogram.resize(256 * histogramBinsPerLevel); |
||||
} |
||||
|
||||
void ATVNoiseReduction::configure(int width, int height) |
||||
{ |
||||
m_width = std::max(width, 0); |
||||
m_height = std::max(height, 0); |
||||
m_frame.assign((size_t) m_width * m_height * 3, 0.0f); |
||||
m_rowValid.assign(m_height, false); |
||||
m_differenceSum.resize(m_width + 1); |
||||
std::fill(m_histogram.begin(), m_histogram.end(), 0); |
||||
m_histogramCount = 0; |
||||
m_threshold = 0.0f; |
||||
} |
||||
|
||||
void ATVNoiseReduction::setStrength(int strength) |
||||
{ |
||||
// At 100%, still frames are blended 90% with the previous output, which reduces the
|
||||
// noise to about a quarter
|
||||
m_strength = 0.9f * std::min(std::max(strength, 0), 100) / 100.0f; |
||||
} |
||||
|
||||
void ATVNoiseReduction::processRow(int row, unsigned int *rgb) |
||||
{ |
||||
if ((row < 0) || (row >= m_height) || (m_width == 0)) { |
||||
return; |
||||
} |
||||
|
||||
float *prev = &m_frame[(size_t) row * m_width * 3]; |
||||
|
||||
if (!m_rowValid[row]) |
||||
{ |
||||
for (int n = 0; n < m_width; n++) |
||||
{ |
||||
prev[3*n] = rgb[n] & 0xff; |
||||
prev[3*n+1] = (rgb[n] >> 8) & 0xff; |
||||
prev[3*n+2] = (rgb[n] >> 16) & 0xff; |
||||
} |
||||
|
||||
m_rowValid[row] = true; |
||||
return; |
||||
} |
||||
|
||||
// Luminance difference from the previous frame, signed, with running sums
|
||||
m_differenceSum[0] = 0.0f; |
||||
|
||||
for (int n = 0; n < m_width; n++) |
||||
{ |
||||
float r = rgb[n] & 0xff; |
||||
float g = (rgb[n] >> 8) & 0xff; |
||||
float b = (rgb[n] >> 16) & 0xff; |
||||
float difference = 0.299f * (r - prev[3*n]) + 0.587f * (g - prev[3*n+1]) + 0.114f * (b - prev[3*n+2]); |
||||
m_differenceSum[n + 1] = m_differenceSum[n] + difference; |
||||
} |
||||
|
||||
for (int n = 0; n < m_width; n++) |
||||
{ |
||||
// The signed difference averaged over a few pixels: noise averages towards zero,
|
||||
// while motion, a consistent change in brightness, does not
|
||||
int a = std::max(n - m_window / 2, 0); |
||||
int b = std::min(n - m_window / 2 + m_window, m_width); |
||||
float d = std::fabs(m_differenceSum[b] - m_differenceSum[a]) / (b - a); |
||||
int bin = std::min((int) (d * histogramBinsPerLevel), (int) m_histogram.size() - 1); |
||||
m_histogram[bin]++; |
||||
m_histogramCount++; |
||||
|
||||
// Full blend below the threshold, none above twice it
|
||||
float k = m_threshold > 0.0f ? m_strength * std::min(std::max(2.0f - d / m_threshold, 0.0f), 1.0f) : 0.0f; |
||||
unsigned int packed = 0; |
||||
|
||||
for (int c = 0; c < 3; c++) |
||||
{ |
||||
float cur = (rgb[n] >> (8 * c)) & 0xff; |
||||
float out = cur + k * (prev[3*n+c] - cur); |
||||
prev[3*n+c] = out; |
||||
packed |= ((unsigned int) std::min(std::max((int) (out + 0.5f), 0), 255)) << (8 * c); |
||||
} |
||||
|
||||
rgb[n] = packed; |
||||
} |
||||
} |
||||
|
||||
void ATVNoiseReduction::endFrame() |
||||
{ |
||||
if (m_histogramCount == 0) { |
||||
return; |
||||
} |
||||
|
||||
// The lower quartile of the difference: as long as a quarter of the picture is still,
|
||||
// this measures the noise, even when most of it is moving
|
||||
int quartile = m_histogramCount / 4; |
||||
int sum = 0; |
||||
int bin = 0; |
||||
|
||||
for (; bin < (int) m_histogram.size(); bin++) |
||||
{ |
||||
sum += m_histogram[bin]; |
||||
|
||||
if (sum >= quartile) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// For noise alone, the quartile of |difference| is 0.32 sigma: threshold at about 1.6 sigma
|
||||
float threshold = std::max(5.0f * (bin + 0.5f) / histogramBinsPerLevel, 1.0f); |
||||
m_threshold = m_threshold > 0.0f ? m_threshold + 0.2f * (threshold - m_threshold) : threshold; |
||||
std::fill(m_histogram.begin(), m_histogram.end(), 0); |
||||
m_histogramCount = 0; |
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// Some code by AI //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_ATVNOISEREDUCTION_H |
||||
#define INCLUDE_ATVNOISEREDUCTION_H |
||||
|
||||
#include <vector> |
||||
|
||||
/**
|
||||
* Motion adaptive temporal noise reduction. |
||||
* |
||||
* Each pixel is blended with the same pixel of the previous frame (recursively), except |
||||
* where its luminance has changed by more than the noise, which is taken to be motion. The |
||||
* noise level is estimated each frame from the lower quartile of the frame to frame |
||||
* difference, so the threshold follows the signal as long as some of the picture is still. |
||||
*/ |
||||
class ATVNoiseReduction |
||||
{ |
||||
public: |
||||
ATVNoiseReduction(); |
||||
|
||||
void configure(int width, int height); //!< Pixels per row and rows; clears the frame store
|
||||
void setStrength(int strength); //!< 0 (off) to 100%
|
||||
bool isEnabled() const { return m_strength > 0.0f; } |
||||
|
||||
/** Filter one row in place. Pixels are packed 0x00BBGGRR */ |
||||
void processRow(int row, unsigned int *rgb); |
||||
void endFrame(); //!< Update the noise estimate from the frame just finished
|
||||
|
||||
float getThreshold() const { return m_threshold; } //!< Motion threshold, 8-bit levels
|
||||
|
||||
private: |
||||
int m_width; |
||||
int m_height; |
||||
float m_strength; //!< Maximum blend with the previous frame
|
||||
std::vector<float> m_frame; //!< Previous output, 3 floats per pixel
|
||||
std::vector<bool> m_rowValid; |
||||
std::vector<float> m_differenceSum; //!< Running sum of the luminance difference along the current row
|
||||
std::vector<int> m_histogram; //!< Of luminance differences over the frame, for the noise estimate
|
||||
int m_histogramCount; |
||||
float m_threshold; |
||||
int m_window; //!< Pixels the difference is averaged over
|
||||
}; |
||||
|
||||
#endif // INCLUDE_ATVNOISEREDUCTION_H
|
||||
Loading…
Reference in new issue