From e7906225b24491a9a6479d09cc15fe7fa0adec22 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 10 Apr 2016 18:20:31 +0200 Subject: [PATCH] DSDplus library: interim state #2 --- dsdplus/CMakeLists.txt | 2 + dsdplus/dmr_voice.cpp | 93 ++++++++++++++++++++++++++++++++++-- dsdplus/dmr_voice.h | 9 +++- dsdplus/dsd_decoder.cpp | 102 ++++++++++++++++++++-------------------- dsdplus/dsd_decoder.h | 1 + dsdplus/dsd_state.h | 1 + 6 files changed, 153 insertions(+), 55 deletions(-) diff --git a/dsdplus/CMakeLists.txt b/dsdplus/CMakeLists.txt index 5f21a4d2b..9c2eb7f5d 100644 --- a/dsdplus/CMakeLists.txt +++ b/dsdplus/CMakeLists.txt @@ -4,6 +4,7 @@ set(dsdplus_SOURCES dmr_voice.cpp dsd_decoder.cpp dsd_filters.cpp + dsd_mbe.cpp dsd_opts.cpp dsd_state.cpp ) @@ -12,6 +13,7 @@ set(dsdplus_HEADERS dmr_voice.h dsd_decoder.h dsd_filters.h + dsd_mbe.h dsd_opts.h dsd_state.h ) diff --git a/dsdplus/dmr_voice.cpp b/dsdplus/dmr_voice.cpp index 2e659c220..be70cf1c5 100644 --- a/dsdplus/dmr_voice.cpp +++ b/dsdplus/dmr_voice.cpp @@ -123,6 +123,9 @@ void DSDDMRVoice::process() case 9: processSlot9(symbolIndex); break; + case 10: + postProcess(symbolIndex); + break; default: break; } @@ -167,6 +170,16 @@ void DSDDMRVoice::preProcess() m_symbolIndex = 144; // advance the main symbol index } +void DSDDMRVoice::postProcess(int symbolIndex) +{ + m_dsdDecoder->getDibit(); // get dibit from symbol but do nothing with it + + if (symbolIndex == 54+12+54-1) // very last symbol -> go back to search sync state + { + m_dsdDecoder->m_fsmState = DSDDecoder::DSDLookForSync; + } +} + void DSDDMRVoice::processSlot0(int symbolIndex) // Slot0 is a 54 symbol slot { m_dsdDecoder->getDibit(); // get dibit from symbol but do nothing with it @@ -216,7 +229,6 @@ void DSDDMRVoice::processSlot1(int symbolIndex) // Slot1 is a 12 symbol slot } cachdata[12] = 0; - m_dibitIndex = 0; // done with the cache -> reset index } } @@ -294,7 +306,7 @@ void DSDDMRVoice::processSlot4(int symbolIndex) // Slot4 is a 24 symbol slot { int *dibitCache = &m_dibitCache[m_dibitIndex - symbolIndex]; // move back to start of corresponding cache section - for (int i = 0; i < 18; i++) + for (int i = 0; i < 24; i++) { int dibit = dibitCache[i]; @@ -339,7 +351,7 @@ void DSDDMRVoice::processSlot4(int symbolIndex) // Slot4 is a 24 symbol slot if ((m_majorBlock == 0) && (m_dsdDecoder->m_opts.errorbars == 1)) { - fprintf(stderr, "%s %s VOICE e:", m_dsdDecoder->m_state.slot0light, m_dsdDecoder->m_state.slot1light); + fprintf(m_dsdDecoder->m_state.logfile, "%s %s VOICE e:", m_dsdDecoder->m_state.slot0light, m_dsdDecoder->m_state.slot1light); } } } @@ -380,5 +392,80 @@ void DSDDMRVoice::processSlot5(int symbolIndex) // Slot5 is a 18 symbol slot } } +void DSDDMRVoice::processSlot6(int symbolIndex) // Slot6 is a 36 symbol slot +{ + int dibit = m_dsdDecoder->getDibit(); // get dibit from symbol and store it in cache + m_dibitCache[m_dibitIndex] = dibit; + + if (symbolIndex == 36-1) // last symbol -> launch process + { + int *dibitCache = &m_dibitCache[m_dibitIndex - symbolIndex]; // move back to start of corresponding cache section + + // current slot frame 3 + w = rW; + x = rX; + y = rY; + z = rZ; + + for (int i = 0; i < 36; i++) + { + int dibit = dibitCache[i]; + + ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1 + ambe_fr3[*y][*z] = (1 & dibit); // bit 0 + w++; + x++; + y++; + z++; + } + + if (mutecurrentslot == 0) + { + m_dsdDecoder->m_mbeDecoder.processFrame(0, ambe_fr3, 0); + } + } +} + +void DSDDMRVoice::processSlot7(int symbolIndex) // Slot7 is a 12 symbol slot +{ + int dibit = m_dsdDecoder->getDibit(); // get dibit from symbol and store it in cache + m_dibitCache[m_dibitIndex] = dibit; + + if (symbolIndex == 12-1) // last symbol -> launch process + { + int *dibitCache = &m_dibitCache[m_dibitIndex - symbolIndex]; // move back to start of corresponding cache section + // CACH + for (int i = 0; i < 12; i++) + { + int dibit = dibitCache[i]; + cachdata[i] = dibit; + } + + cachdata[12] = 0; + } +} + +void DSDDMRVoice::processSlot9(int symbolIndex) // Slot9 is a 24 symbol slot +{ + int dibit = m_dsdDecoder->getDibit(); // get dibit from symbol and store it in cache + m_dibitCache[m_dibitIndex] = dibit; + + if (symbolIndex == 24-1) // last symbol -> launch process + { + int *dibitCache = &m_dibitCache[m_dibitIndex - symbolIndex]; // move back to start of corresponding cache section + + for (int i = 0; i < 24; i++) + { + int dibit = dibitCache[i]; + + syncdata[i] = dibit; + sync[i] = (dibit | 1) + 48; + } + + sync[24] = 0; + syncdata[24] = 0; + + } +} } // namespace dsdplus diff --git a/dsdplus/dmr_voice.h b/dsdplus/dmr_voice.h index b2ed201da..cde52fa06 100644 --- a/dsdplus/dmr_voice.h +++ b/dsdplus/dmr_voice.h @@ -109,6 +109,11 @@ private: m_slotIndex = 9; return symbolInMajorBlockIndex - 54+12+36+18+24+18+36+12+54; } + else if (symbolInMajorBlockIndex < 54+12+36+18+24+18+36+12+54+24+54+12+54) + { + m_slotIndex = 10; // dummy slot for last skipped symbols + return symbolInMajorBlockIndex - 54+12+36+18+24+18+36+12+54+24; + } else // cannot go there if using this function in its valid context (input is a remainder of division by 288) { m_slotIndex = -1; // invalid slot @@ -116,7 +121,8 @@ private: } } - void preProcess(); //!< process the 144 in memory dibits in initial phase + void preProcess(); //!< process the 144 in memory dibits in initial phase + void postProcess(int symbolIndex); //!< skip 54 + 12 + 54 symbols at the end of the last slot (block 5 slot 9) void processSlot0(int symbolIndex); void processSlot1(int symbolIndex); void processSlot2(int symbolIndex); @@ -150,7 +156,6 @@ private: static const int rX[36]; static const int rY[36]; static const int rZ[36]; - }; } diff --git a/dsdplus/dsd_decoder.cpp b/dsdplus/dsd_decoder.cpp index 931ff63cd..27807b034 100644 --- a/dsdplus/dsd_decoder.cpp +++ b/dsdplus/dsd_decoder.cpp @@ -30,10 +30,12 @@ DSDDecoder::DSDDecoder() : resetSymbol(); resetFrameSync(); noCarrier(); + m_state.logfile = fdopen(fileno(stderr), (const char *) 'w'); } DSDDecoder::~DSDDecoder() { + fclose(m_state.logfile); } void DSDDecoder::run(short sample) @@ -183,7 +185,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(stderr, "O"); + fprintf(m_state.logfile, "O"); } } else @@ -191,7 +193,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(stderr, "+"); + fprintf(m_state.logfile, "+"); } if ((m_state.jitter < 0) && (m_state.lastsample < m_state.center) @@ -220,7 +222,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(stderr, "X"); + fprintf(m_state.logfile, "X"); } } else @@ -228,7 +230,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(stderr, "-"); + fprintf(m_state.logfile, "-"); } if ((m_state.jitter < 0) && (m_state.lastsample > m_state.center) @@ -278,11 +280,11 @@ bool DSDDecoder::pushSample(short sample, int have_sync) { if (m_state.jitter >= 0) { - fprintf(stderr, " %i\n", m_state.jitter); + fprintf(m_state.logfile, " %i\n", m_state.jitter); } else { - fprintf(stderr, "\n"); + fprintf(m_state.logfile, "\n"); } } @@ -394,25 +396,25 @@ int DSDDecoder::getDibit() if (m_state.symbolcnt > (4800 / m_opts.scoperate)) { m_state.symbolcnt = 0; - fprintf(stderr, "\n"); - fprintf(stderr, + fprintf(m_state.logfile, "\n"); + fprintf(m_state.logfile, "Demod mode: %s Nac: %4X\n", modulation, m_state.nac); - fprintf(stderr, + fprintf(m_state.logfile, "Frame Type: %s Talkgroup: %7i\n", m_state.ftype, m_state.lasttg); - fprintf(stderr, + fprintf(m_state.logfile, "Frame Subtype: %s Source: %12i\n", m_state.fsubtype, m_state.lastsrc); - fprintf(stderr, + fprintf(m_state.logfile, "TDMA activity: %s %s Voice errors: %s\n", m_state.slot0light, m_state.slot1light, m_state.err_str); - fprintf(stderr, + fprintf(m_state.logfile, "+----------------------------------------------------------------+\n"); for (i = 0; i < 10; i++) { - fprintf(stderr, "|"); + fprintf(m_state.logfile, "|"); for (j = 0; j < 64; j++) { @@ -421,26 +423,26 @@ int DSDDecoder::getDibit() if ((j == ((m_state.min) + 32768) / 1024) || (j == ((m_state.max) + 32768) / 1024)) { - fprintf(stderr, "#"); + fprintf(m_state.logfile, "#"); } else if ((j == ((m_state.lmid) + 32768) / 1024) || (j == ((m_state.umid) + 32768) / 1024)) { - fprintf(stderr, "^"); + fprintf(m_state.logfile, "^"); } else if (j == (m_state.center + 32768) / 1024) { - fprintf(stderr, "!"); + fprintf(m_state.logfile, "!"); } else { if (j == 32) { - fprintf(stderr, "|"); + fprintf(m_state.logfile, "|"); } else { - fprintf(stderr, " "); + fprintf(m_state.logfile, " "); } } } @@ -448,24 +450,24 @@ int DSDDecoder::getDibit() { if (spectrum[j] > 9 - i) { - fprintf(stderr, "*"); + fprintf(m_state.logfile, "*"); } else { if (j == 32) { - fprintf(stderr, "|"); + fprintf(m_state.logfile, "|"); } else { - fprintf(stderr, " "); + fprintf(m_state.logfile, " "); } } } } - fprintf(stderr, "|\n"); + fprintf(m_state.logfile, "|\n"); } - fprintf(stderr, + fprintf(m_state.logfile, "+----------------------------------------------------------------+\n"); } } @@ -607,7 +609,7 @@ void DSDDecoder::resetFrameSync() if ((m_opts.symboltiming == 1) && (m_state.carrier == 1)) { - fprintf(stderr, "\nSymbol Timing:\n"); + fprintf(m_state.logfile, "\nSymbol Timing:\n"); } m_fsmState = DSDLookForSync; @@ -617,19 +619,19 @@ void DSDDecoder::printFrameSync(const char *frametype, int offset, char *modulat { if (m_opts.verbose > 0) { - fprintf(stderr, "Sync: %s ", frametype); + fprintf(m_state.logfile, "Sync: %s ", frametype); } if (m_opts.verbose > 2) { - fprintf(stderr, "o: %4i ", offset); + fprintf(m_state.logfile, "o: %4i ", offset); } if (m_opts.verbose > 1) { - fprintf(stderr, "mod: %s ", modulation); + fprintf(m_state.logfile, "mod: %s ", modulation); } if (m_opts.verbose > 2) { - fprintf(stderr, "g: %f ", m_state.aout_gain); + fprintf(m_state.logfile, "g: %f ", m_state.aout_gain); } } @@ -821,26 +823,26 @@ int DSDDecoder::getFrameSync() { m_state.symbolcnt = 0; - fprintf(stderr, "\n"); - fprintf(stderr, + fprintf(m_state.logfile, "\n"); + fprintf(m_state.logfile, "Demod mode: %s Nac: %4X\n", m_modulation, m_state.nac); - fprintf(stderr, + fprintf(m_state.logfile, "Frame Type: %s Talkgroup: %7i\n", m_state.ftype, m_state.lasttg); - fprintf(stderr, + fprintf(m_state.logfile, "Frame Subtype: %s Source: %12i\n", m_state.fsubtype, m_state.lastsrc); - fprintf(stderr, + fprintf(m_state.logfile, "TDMA activity: %s %s Voice errors: %s\n", m_state.slot0light, m_state.slot1light, m_state.err_str); - fprintf(stderr, + fprintf(m_state.logfile, "+----------------------------------------------------------------+\n"); for (int i = 0; i < 10; i++) { - fprintf(stderr, "|"); + fprintf(m_state.logfile, "|"); for (int j = 0; j < 64; j++) { @@ -848,21 +850,21 @@ int DSDDecoder::getFrameSync() { if ((j == ((m_state.min) + 32768) / 1024) || (j == ((m_state.max) + 32768) / 1024)) { - fprintf(stderr, "#"); + fprintf(m_state.logfile, "#"); } else if (j == (m_state.center + 32768) / 1024) { - fprintf(stderr, "!"); + fprintf(m_state.logfile, "!"); } else { if (j == 32) { - fprintf(stderr, "|"); + fprintf(m_state.logfile, "|"); } else { - fprintf(stderr, " "); + fprintf(m_state.logfile, " "); } } } @@ -870,26 +872,26 @@ int DSDDecoder::getFrameSync() { if (m_spectrum[j] > 9 - i) { - fprintf(stderr, "*"); + fprintf(m_state.logfile, "*"); } else { if (j == 32) { - fprintf(stderr, "|"); + fprintf(m_state.logfile, "|"); } else { - fprintf(stderr, " "); + fprintf(m_state.logfile, " "); } } } } - fprintf(stderr, "|\n"); + fprintf(m_state.logfile, "|\n"); } - fprintf(stderr, + fprintf(m_state.logfile, "+----------------------------------------------------------------+\n"); } } @@ -1560,19 +1562,19 @@ void DSDDecoder::printFrameInfo() if (m_opts.verbose > 0) { - fprintf(stderr, "inlvl: %2i%% ", level); + fprintf(m_state.logfile, "inlvl: %2i%% ", level); } if (m_state.nac != 0) { - fprintf(stderr, "nac: %4X ", m_state.nac); + fprintf(m_state.logfile, "nac: %4X ", m_state.nac); } if (m_opts.verbose > 1) { - fprintf(stderr, "src: %8i ", m_state.lastsrc); + fprintf(m_state.logfile, "src: %8i ", m_state.lastsrc); } - fprintf(stderr, "tg: %5i ", m_state.lasttg); + fprintf(m_state.logfile, "tg: %5i ", m_state.lasttg); } int DSDDecoder::comp(const void *a, const void *b) @@ -1609,7 +1611,7 @@ void DSDDecoder::processFrame() if (m_opts.verbose > 0) { int level = (int) m_state.max / 164; - fprintf(stderr, "inlvl: %2i%% ", level); + fprintf(m_state.logfile, "inlvl: %2i%% ", level); } } @@ -1655,7 +1657,7 @@ void DSDDecoder::processFrame() if (m_opts.verbose > 0) { int level = (int) m_state.max / 164; - fprintf(stderr, "inlvl: %2i%% ", level); + fprintf(m_state.logfile, "inlvl: %2i%% ", level); } } diff --git a/dsdplus/dsd_decoder.h b/dsdplus/dsd_decoder.h index aba6814ca..b26a762a2 100644 --- a/dsdplus/dsd_decoder.h +++ b/dsdplus/dsd_decoder.h @@ -63,6 +63,7 @@ namespace DSDplus class DSDDecoder { + friend class DSDMBEDecoder; friend class DSDDMRVoice; public: typedef enum diff --git a/dsdplus/dsd_state.h b/dsdplus/dsd_state.h index 1436d165a..57ec46f6d 100644 --- a/dsdplus/dsd_state.h +++ b/dsdplus/dsd_state.h @@ -104,6 +104,7 @@ public: int output_num_samples; int output_length; int output_finished; + FILE *logfile; }; } // namespace dsdplus