Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTSC chroma-encoder filter changes #760

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tools/ld-chroma-decoder/encoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int main(int argc, char *argv[])

// Option to select chroma mode (--chroma-mode)
QCommandLineOption chromaOption(QStringList() << "chroma-mode",
QCoreApplication::translate("main", "NTSC only. Chroma encoder mode to use (wideband-yuv, wideband-yiq; default: wideband-yuv)"),
QCoreApplication::translate("main", "NTSC only. Chroma encoder mode to use (wideband-yuv, wideband-yiq, narrowband-q; default: wideband-yuv)"),
QCoreApplication::translate("main", "chroma-mode"));
parser.addOption(chromaOption);

Expand Down Expand Up @@ -142,6 +142,8 @@ int main(int argc, char *argv[])
chromaName = parser.value(chromaOption);
if (chromaName == "wideband-yiq") {
chromaMode = WIDEBAND_YIQ;
} else if (chromaName == "narrowband-q") {
chromaMode = NARROWBAND_Q;
} else if (chromaName == "wideband-yuv") {
chromaMode = WIDEBAND_YUV;
} else {
Expand Down
30 changes: 21 additions & 9 deletions tools/ld-chroma-decoder/encoder/ntscencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,26 @@ static double syncPulseGate(double t, double startTime, SyncPulseType type)
return raisedCosineGate(t, startTime, startTime + length, 200.0e-9 / 2.0);
}

// 1.3 MHz low-pass Gaussian filter, as used in pyctools-pal's coder.
// Generated by: c = scipy.signal.gaussian(13, 1.49); c / sum(c)
// 1.3 MHz low-pass filter
//
// The UV filter should be 0 dB at 0 Hz, >= -3 dB at 1.3 MHz, <= -20 dB at
// 4.0 MHz. [Clarke p8]
static constexpr std::array<double, 13> uvFilterCoeffs {
8.06454142158873e-05, 0.0009604748783110286, 0.007290763490157312, 0.035272860169480155, 0.10876496139131472,
0.21375585039760908, 0.2677488885178237, 0.21375585039760908, 0.10876496139131472, 0.035272860169480155,
0.007290763490157312, 0.0009604748783110286, 8.06454142158873e-05
// The filter should be 0 dB at 0 Hz, >= -2 dB at 1.3 MHz, < -20 dB at
// 3.6 MHz. [Clarke p15]
static constexpr std::array<double, 9> uvFilterCoeffs {
0.0021, 0.0191, 0.0903, 0.2308, 0.3153,
0.2308, 0.0903, 0.0191, 0.0021
};
static constexpr auto uvFilter = makeFIRFilter(uvFilterCoeffs);

// 0.6 MHz low-pass filter
//
// The filter should be 0 dB at 0 Hz, >= -2 dB at 0.4 MHz, >= -6 dB at
// 0.5 MHz, <= -6 dB at 0.6 MHz. [Clarke p15]
static constexpr std::array<double, 23> qFilterCoeffs {
0.0002, 0.0027, 0.0085, 0.0171, 0.0278, 0.0398, 0.0522, 0.0639, 0.0742, 0.0821, 0.0872, 0.0889,
0.0872, 0.0821, 0.0742, 0.0639, 0.0522, 0.0398, 0.0278, 0.0171, 0.0085, 0.0027, 0.0002
};
static constexpr auto qFilter = makeFIRFilter(qFilterCoeffs);

void NTSCEncoder::encodeLine(qint32 fieldNo, qint32 frameLine, const quint16 *rgbData, QVector<quint16> &outputLine)
{
// Resize the output line and fill with blanking
Expand Down Expand Up @@ -394,7 +402,11 @@ void NTSCEncoder::encodeLine(qint32 fieldNo, qint32 frameLine, const quint16 *rg

// Low-pass filter chroma components to 1.3 MHz [Poynton p342]
uvFilter.apply(C1);
uvFilter.apply(C2);
if (chromaMode == NARROWBAND_Q) {
qFilter.apply(C2);
} else {
uvFilter.apply(C2);
}
}

for (qint32 x = 0; x < outputLine.size(); x++) {
Expand Down
1 change: 1 addition & 0 deletions tools/ld-chroma-decoder/encoder/ntscencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
enum ChromaMode {
WIDEBAND_YUV = 0, // Y'UV
WIDEBAND_YIQ, // Y'IQ
NARROWBAND_Q // Y'IQ with Q low-passed
};

class NTSCEncoder
Expand Down