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

Add DTS support to ld-process-efm #772

Merged
merged 2 commits into from
Aug 20, 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
11 changes: 6 additions & 5 deletions tools/ld-process-efm/Datatypes/f3frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ F3Frame::F3Frame()
}
}

F3Frame::F3Frame(uchar *tValuesIn, qint32 tLength)
F3Frame::F3Frame(uchar *tValuesIn, qint32 tLength, bool audioIsDts)
{
validEfmSymbols = 0;
invalidEfmSymbols = 0;
Expand All @@ -57,11 +57,11 @@ F3Frame::F3Frame(uchar *tValuesIn, qint32 tLength)
isSync1 = false;
subcodeSymbol = 0;

setTValues(tValuesIn, tLength);
setTValues(tValuesIn, tLength, audioIsDts);
}

// This method sets the T-values for the F3 Frame
void F3Frame::setTValues(uchar* tValuesIn, qint32 tLength)
void F3Frame::setTValues(uchar* tValuesIn, qint32 tLength, bool audioIsDts)
{
// Does tValuesIn contain values?
if (tLength == 0) {
Expand Down Expand Up @@ -134,8 +134,9 @@ void F3Frame::setTValues(uchar* tValuesIn, qint32 tLength)

// Step 3:

// Decode the subcode symbol
if (efmValues[0] == 0x801) {
// Decode the subcode symbol.
// Some (but not all) DTS LaserDiscs use a non-standard Sync 0 value.
if (efmValues[0] == 0x801 || (audioIsDts && efmValues[0] == 0x812)) {
// Sync 0
subcodeSymbol = 0;
isSync0 = true;
Expand Down
4 changes: 2 additions & 2 deletions tools/ld-process-efm/Datatypes/f3frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class F3Frame
{
public:
F3Frame();
F3Frame(uchar *tValuesIn, qint32 tLength);
F3Frame(uchar *tValuesIn, qint32 tLength, bool audioIsDts);

void setTValues(uchar *tValuesIn, qint32 tLength);
void setTValues(uchar *tValuesIn, qint32 tLength, bool audioIsDts);
uchar* getDataSymbols();
uchar* getErrorSymbols();
uchar getSubcodeSymbol();
Expand Down
5 changes: 3 additions & 2 deletions tools/ld-process-efm/Decoders/efmtof3frames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ EfmToF3Frames::EfmToF3Frames()
// Public methods -----------------------------------------------------------------------------------------------------

// Main processing method
QVector<F3Frame> EfmToF3Frames::process(QByteArray efmDataIn, bool debugState)
QVector<F3Frame> EfmToF3Frames::process(QByteArray efmDataIn, bool debugState, bool _audioIsDts)
{
debugOn = debugState;
audioIsDts = _audioIsDts;

// Clear the output buffer
f3FramesOut.clear();
Expand Down Expand Up @@ -382,7 +383,7 @@ EfmToF3Frames::StateMachine EfmToF3Frames::sm_state_processFrame()

// Now we hand the data over to the F3 frame class which converts the data
// into a F3 frame and save the F3 frame to our output data buffer
f3FramesOut.append(F3Frame(frameT, tLength));
f3FramesOut.append(F3Frame(frameT, tLength, audioIsDts));

statistics.validEfmSymbols += f3FramesOut.last().getNumberOfValidEfmSymbols();
statistics.invalidEfmSymbols += f3FramesOut.last().getNumberOfInvalidEfmSymbols();
Expand Down
3 changes: 2 additions & 1 deletion tools/ld-process-efm/Decoders/efmtof3frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ class EfmToF3Frames
qint64 correctedEfmSymbols;
};

QVector<F3Frame> process(QByteArray efmDataIn, bool debugState);
QVector<F3Frame> process(QByteArray efmDataIn, bool debugState, bool _audioIsDts);
Statistics getStatistics();
void reportStatistics();
void reset();

private:
bool debugOn;
bool audioIsDts;
Statistics statistics;
QByteArray efmDataBuffer;
QVector<F3Frame> f3FramesOut;
Expand Down
17 changes: 7 additions & 10 deletions tools/ld-process-efm/efmprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,22 @@ void EfmProcess::setDebug(bool _debug_efmToF3Frames, bool _debug_syncF3Frames,
}

// Set the audio error treatment type
void EfmProcess::setAudioErrorTreatment(bool concealAudio, bool silenceAudio, bool passThroughAudio)
void EfmProcess::setAudioErrorTreatment(EfmProcess::ErrorTreatment _errorTreatment)
{
qDebug() << "EfmProcess::setAudioErrorTreatment(): Conceal audio =" << concealAudio;
qDebug() << "EfmProcess::setAudioErrorTreatment(): Silence audio =" << silenceAudio;
qDebug() << "EfmProcess::setAudioErrorTreatment(): Pass through audio =" << passThroughAudio;
qDebug() << "EfmProcess::setAudioErrorTreatment(): Error treatment =" << _errorTreatment;

// Set the audio error treatment option
errorTreatment = F1ToAudio::ErrorTreatment::conceal; // Default
if (concealAudio) errorTreatment = F1ToAudio::ErrorTreatment::conceal;
if (silenceAudio) errorTreatment = F1ToAudio::ErrorTreatment::silence;
if (passThroughAudio) errorTreatment = F1ToAudio::ErrorTreatment::passThrough;
errorTreatment = _errorTreatment;

// Set the conceal type option (THIS SHOULD BE REMOVED)
concealType = F1ToAudio::ConcealType::linear;
}

// Set the decoder options
void EfmProcess::setDecoderOptions(bool _padInitialDiscTime, bool _decodeAsData, bool _noTimeStamp)
void EfmProcess::setDecoderOptions(bool _padInitialDiscTime, bool _decodeAsData, bool _audioIsDts, bool _noTimeStamp)
{
qDebug() << "EfmProcess::setDecoderOptions(): Pad initial disc time is" << _padInitialDiscTime;
qDebug() << "EfmProcess::setDecoderOptions(): Audio-is-DTS is" << _audioIsDts;
qDebug() << "EfmProcess::setDecoderOptions(): No time-stamp is" << _noTimeStamp;
padInitialDiscTime = _padInitialDiscTime;

Expand All @@ -89,6 +85,7 @@ void EfmProcess::setDecoderOptions(bool _padInitialDiscTime, bool _decodeAsData,
qDebug() << "EfmProcess::setDecoderOptions(): Decoding F1 frames as audio";
}

audioIsDts = _audioIsDts;
noTimeStamp = _noTimeStamp;
}

Expand Down Expand Up @@ -158,7 +155,7 @@ bool EfmProcess::process(QString inputFilename, QString outputFilename)
if (bytesRead != bufferSize) inputEfmBuffer.resize(static_cast<qint32>(bytesRead));

// Perform EFM processing
QVector<F3Frame> initialF3Frames = efmToF3Frames.process(inputEfmBuffer, debug_efmToF3Frames);
QVector<F3Frame> initialF3Frames = efmToF3Frames.process(inputEfmBuffer, debug_efmToF3Frames, audioIsDts);
QVector<F3Frame> syncedF3Frames = syncF3Frames.process(initialF3Frames, debug_syncF3Frames);
QVector<F2Frame> f2Frames = f3ToF2Frames.process(syncedF3Frames, debug_f3ToF2Frames, noTimeStamp);
QVector<F1Frame> f1Frames = f2ToF1Frames.process(f2Frames, debug_f2ToF1Frame, noTimeStamp);
Expand Down
8 changes: 5 additions & 3 deletions tools/ld-process-efm/efmprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class EfmProcess
public:
EfmProcess();

using ErrorTreatment = F1ToAudio::ErrorTreatment;

struct Statistics {
EfmToF3Frames::Statistics efmToF3Frames;
SyncF3Frames::Statistics syncF3Frames;
Expand All @@ -53,9 +55,8 @@ class EfmProcess
void setDebug(bool _debug_efmToF3Frames, bool _debug_syncF3Frames,
bool _debug_f3ToF2Frames, bool _debug_f2ToF1Frames,
bool _debug_f1ToAudio, bool _debug_f1ToData);
void setAudioErrorTreatment(bool concealAudio,
bool silenceAudio, bool passThroughAudio);
void setDecoderOptions(bool _padInitialDiscTime, bool _decodeAsData, bool _noTimeStamp);
void setAudioErrorTreatment(ErrorTreatment _errorTreatment);
void setDecoderOptions(bool _padInitialDiscTime, bool _decodeAsData, bool _audioIsDts, bool _noTimeStamp);
void reportStatistics();
bool process(QString inputFilename, QString outputFilename);
Statistics getStatistics();
Expand Down Expand Up @@ -84,6 +85,7 @@ class EfmProcess
bool padInitialDiscTime;
bool decodeAsAudio;
bool decodeAsData;
bool audioIsDts;
bool noTimeStamp;

Statistics statistics;
Expand Down
34 changes: 28 additions & 6 deletions tools/ld-process-efm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "Decode F1 frames as data instead of audio"));
parser.addOption(decodeAsDataOption);

QCommandLineOption audioIsDtsOption(QStringList() << "D" << "dts",
QCoreApplication::translate("main", "Audio is DTS rather than PCM (allow non-standard F3 syncs)"));
parser.addOption(audioIsDtsOption);

QCommandLineOption noTimeStampOption(QStringList() << "t" << "time",
QCoreApplication::translate("main", "Non-standard audio decode (no time-stamp information)"));
parser.addOption(noTimeStampOption);
Expand Down Expand Up @@ -121,14 +125,32 @@ int main(int argc, char *argv[])
// Standard logging options
processStandardDebugOptions(parser);

// Get the audio options from the parser
bool concealAudio = parser.isSet(concealAudioOption);
bool silenceAudio = parser.isSet(silenceAudioOption);
bool passThroughAudio = parser.isSet(passThroughAudioOption);
// Get the audio options from the parser.
// Default to conceal for PCM audio, and passThrough for DTS audio.
EfmProcess::ErrorTreatment errorTreatment = parser.isSet(audioIsDtsOption) ? EfmProcess::ErrorTreatment::passThrough
: EfmProcess::ErrorTreatment::conceal;
int numTreatments = 0;
if (parser.isSet(concealAudioOption)) {
errorTreatment = EfmProcess::ErrorTreatment::conceal;
numTreatments++;
}
if (parser.isSet(silenceAudioOption)) {
errorTreatment = EfmProcess::ErrorTreatment::silence;
numTreatments++;
}
if (parser.isSet(passThroughAudioOption)) {
errorTreatment = EfmProcess::ErrorTreatment::passThrough;
numTreatments++;
}
if (numTreatments > 1) {
qCritical() << "You may only specify one error treatment option (-c, -s or -g)";
return 1;
}

// Get the decoding options from the parser
bool pad = parser.isSet(padOption);
bool decodeAsData = parser.isSet(decodeAsDataOption);
bool audioIsDts = parser.isSet(audioIsDtsOption);
bool noTimeStamp = parser.isSet(noTimeStampOption);

// Get the additional debug options from the parser
Expand Down Expand Up @@ -156,8 +178,8 @@ int main(int argc, char *argv[])
EfmProcess efmProcess;
efmProcess.setDebug(debug_efmToF3Frames, debug_syncF3Frames, debug_f3ToF2Frames,
debug_f2ToF1Frame, debug_f1ToAudio, debug_f1ToData);
efmProcess.setDecoderOptions(pad, decodeAsData, noTimeStamp);
efmProcess.setAudioErrorTreatment(concealAudio, silenceAudio, passThroughAudio);
efmProcess.setDecoderOptions(pad, decodeAsData, audioIsDts, noTimeStamp);
efmProcess.setAudioErrorTreatment(errorTreatment);

if (!efmProcess.process(inputFilename, outputFilename)) return 1;

Expand Down