diff --git a/dsdplus/CMakeLists.txt b/dsdplus/CMakeLists.txt index baa3b579b..19440589b 100644 --- a/dsdplus/CMakeLists.txt +++ b/dsdplus/CMakeLists.txt @@ -2,6 +2,7 @@ project(dsdplus) set(dsdplus_SOURCES descramble.cpp + dmr_data.cpp dmr_voice.cpp dsd_decoder.cpp dsd_filters.cpp @@ -13,6 +14,7 @@ set(dsdplus_SOURCES set(dsdplus_HEADERS descramble.h + dmr_data.h dmr_voice.h dsd_decoder.h dsd_filters.h diff --git a/dsdplus/dmr_data.cpp b/dsdplus/dmr_data.cpp index 3045b71c5..9c6e2ef42 100644 --- a/dsdplus/dmr_data.cpp +++ b/dsdplus/dmr_data.cpp @@ -212,7 +212,7 @@ void DSDDMRData::preProcess() if (m_dsdDecoder->m_opts.errorbars == 1) { - fprintf(m_dsdDecoder->m_state.logfile, "%s %s ", m_dsdDecoder->m_state.slot0light, m_dsdDecoder->m_state.slot1light); + fprintf(stderr, "%s %s ", m_dsdDecoder->m_state.slot0light, m_dsdDecoder->m_state.slot1light); } } diff --git a/dsdplus/dmr_voice.cpp b/dsdplus/dmr_voice.cpp index be70cf1c5..c3fc4da98 100644 --- a/dsdplus/dmr_voice.cpp +++ b/dsdplus/dmr_voice.cpp @@ -351,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(m_dsdDecoder->m_state.logfile, "%s %s VOICE e:", m_dsdDecoder->m_state.slot0light, m_dsdDecoder->m_state.slot1light); + fprintf(stderr, "%s %s VOICE e:", m_dsdDecoder->m_state.slot0light, m_dsdDecoder->m_state.slot1light); } } } diff --git a/dsdplus/dsd_decoder.cpp b/dsdplus/dsd_decoder.cpp index 666403bdf..d4b7305df 100644 --- a/dsdplus/dsd_decoder.cpp +++ b/dsdplus/dsd_decoder.cpp @@ -32,12 +32,11 @@ DSDDecoder::DSDDecoder() : resetSymbol(); resetFrameSync(); noCarrier(); - m_state.logfile = fdopen(fileno(stderr), (const char *) 'w'); } DSDDecoder::~DSDDecoder() { - fclose(m_state.logfile); + fclose(stderr); } void DSDDecoder::run(short sample) @@ -196,7 +195,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(m_state.logfile, "O"); + fprintf(stderr, "O"); } } else @@ -204,7 +203,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(m_state.logfile, "+"); + fprintf(stderr, "+"); } if ((m_state.jitter < 0) && (m_state.lastsample < m_state.center) @@ -233,7 +232,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(m_state.logfile, "X"); + fprintf(stderr, "X"); } } else @@ -241,7 +240,7 @@ bool DSDDecoder::pushSample(short sample, int have_sync) if ((m_opts.symboltiming == 1) && (have_sync == 0) && (m_state.lastsynctype != -1)) { - fprintf(m_state.logfile, "-"); + fprintf(stderr, "-"); } if ((m_state.jitter < 0) && (m_state.lastsample > m_state.center) @@ -291,11 +290,11 @@ bool DSDDecoder::pushSample(short sample, int have_sync) { if (m_state.jitter >= 0) { - fprintf(m_state.logfile, " %i\n", m_state.jitter); + fprintf(stderr, " %i\n", m_state.jitter); } else { - fprintf(m_state.logfile, "\n"); + fprintf(stderr, "\n"); } } @@ -407,25 +406,25 @@ int DSDDecoder::getDibit() if (m_state.symbolcnt > (4800 / m_opts.scoperate)) { m_state.symbolcnt = 0; - fprintf(m_state.logfile, "\n"); - fprintf(m_state.logfile, + fprintf(stderr, "\n"); + fprintf(stderr, "Demod mode: %s Nac: %4X\n", modulation, m_state.nac); - fprintf(m_state.logfile, + fprintf(stderr, "Frame Type: %s Talkgroup: %7i\n", m_state.ftype, m_state.lasttg); - fprintf(m_state.logfile, + fprintf(stderr, "Frame Subtype: %s Source: %12i\n", m_state.fsubtype, m_state.lastsrc); - fprintf(m_state.logfile, + fprintf(stderr, "TDMA activity: %s %s Voice errors: %s\n", m_state.slot0light, m_state.slot1light, m_state.err_str); - fprintf(m_state.logfile, + fprintf(stderr, "+----------------------------------------------------------------+\n"); for (i = 0; i < 10; i++) { - fprintf(m_state.logfile, "|"); + fprintf(stderr, "|"); for (j = 0; j < 64; j++) { @@ -434,26 +433,26 @@ int DSDDecoder::getDibit() if ((j == ((m_state.min) + 32768) / 1024) || (j == ((m_state.max) + 32768) / 1024)) { - fprintf(m_state.logfile, "#"); + fprintf(stderr, "#"); } else if ((j == ((m_state.lmid) + 32768) / 1024) || (j == ((m_state.umid) + 32768) / 1024)) { - fprintf(m_state.logfile, "^"); + fprintf(stderr, "^"); } else if (j == (m_state.center + 32768) / 1024) { - fprintf(m_state.logfile, "!"); + fprintf(stderr, "!"); } else { if (j == 32) { - fprintf(m_state.logfile, "|"); + fprintf(stderr, "|"); } else { - fprintf(m_state.logfile, " "); + fprintf(stderr, " "); } } } @@ -461,24 +460,24 @@ int DSDDecoder::getDibit() { if (spectrum[j] > 9 - i) { - fprintf(m_state.logfile, "*"); + fprintf(stderr, "*"); } else { if (j == 32) { - fprintf(m_state.logfile, "|"); + fprintf(stderr, "|"); } else { - fprintf(m_state.logfile, " "); + fprintf(stderr, " "); } } } } - fprintf(m_state.logfile, "|\n"); + fprintf(stderr, "|\n"); } - fprintf(m_state.logfile, + fprintf(stderr, "+----------------------------------------------------------------+\n"); } } @@ -620,7 +619,7 @@ void DSDDecoder::resetFrameSync() if ((m_opts.symboltiming == 1) && (m_state.carrier == 1)) { - fprintf(m_state.logfile, "\nSymbol Timing:\n"); + fprintf(stderr, "\nSymbol Timing:\n"); } m_fsmState = DSDLookForSync; @@ -630,19 +629,19 @@ void DSDDecoder::printFrameSync(const char *frametype, int offset, char *modulat { if (m_opts.verbose > 0) { - fprintf(m_state.logfile, "Sync: %s ", frametype); + fprintf(stderr, "\nSync: %s ", frametype); } if (m_opts.verbose > 2) { - fprintf(m_state.logfile, "o: %4i ", offset); + fprintf(stderr, "o: %4i ", offset); } if (m_opts.verbose > 1) { - fprintf(m_state.logfile, "mod: %s ", modulation); + fprintf(stderr, "mod: %s ", modulation); } if (m_opts.verbose > 2) { - fprintf(m_state.logfile, "g: %f ", m_state.aout_gain); + fprintf(stderr, "g: %f ", m_state.aout_gain); } } @@ -834,26 +833,26 @@ int DSDDecoder::getFrameSync() { m_state.symbolcnt = 0; - fprintf(m_state.logfile, "\n"); - fprintf(m_state.logfile, + fprintf(stderr, "\n"); + fprintf(stderr, "Demod mode: %s Nac: %4X\n", m_modulation, m_state.nac); - fprintf(m_state.logfile, + fprintf(stderr, "Frame Type: %s Talkgroup: %7i\n", m_state.ftype, m_state.lasttg); - fprintf(m_state.logfile, + fprintf(stderr, "Frame Subtype: %s Source: %12i\n", m_state.fsubtype, m_state.lastsrc); - fprintf(m_state.logfile, + fprintf(stderr, "TDMA activity: %s %s Voice errors: %s\n", m_state.slot0light, m_state.slot1light, m_state.err_str); - fprintf(m_state.logfile, + fprintf(stderr, "+----------------------------------------------------------------+\n"); for (int i = 0; i < 10; i++) { - fprintf(m_state.logfile, "|"); + fprintf(stderr, "|"); for (int j = 0; j < 64; j++) { @@ -861,21 +860,21 @@ int DSDDecoder::getFrameSync() { if ((j == ((m_state.min) + 32768) / 1024) || (j == ((m_state.max) + 32768) / 1024)) { - fprintf(m_state.logfile, "#"); + fprintf(stderr, "#"); } else if (j == (m_state.center + 32768) / 1024) { - fprintf(m_state.logfile, "!"); + fprintf(stderr, "!"); } else { if (j == 32) { - fprintf(m_state.logfile, "|"); + fprintf(stderr, "|"); } else { - fprintf(m_state.logfile, " "); + fprintf(stderr, " "); } } } @@ -883,26 +882,26 @@ int DSDDecoder::getFrameSync() { if (m_spectrum[j] > 9 - i) { - fprintf(m_state.logfile, "*"); + fprintf(stderr, "*"); } else { if (j == 32) { - fprintf(m_state.logfile, "|"); + fprintf(stderr, "|"); } else { - fprintf(m_state.logfile, " "); + fprintf(stderr, " "); } } } } - fprintf(m_state.logfile, "|\n"); + fprintf(stderr, "|\n"); } - fprintf(m_state.logfile, + fprintf(stderr, "+----------------------------------------------------------------+\n"); } } @@ -1513,7 +1512,7 @@ int DSDDecoder::getFrameSync() if ((m_opts.errorbars == 1) && (m_opts.verbose > 1) && (m_state.carrier == 1)) { - printf("Sync: no sync\n"); + printf("\nSync: no sync\n"); } noCarrier(); @@ -1573,19 +1572,19 @@ void DSDDecoder::printFrameInfo() if (m_opts.verbose > 0) { - fprintf(m_state.logfile, "inlvl: %2i%% ", level); + fprintf(stderr, "inlvl: %2i%% ", level); } if (m_state.nac != 0) { - fprintf(m_state.logfile, "nac: %4X ", m_state.nac); + fprintf(stderr, "nac: %4X ", m_state.nac); } if (m_opts.verbose > 1) { - fprintf(m_state.logfile, "src: %8i ", m_state.lastsrc); + fprintf(stderr, "src: %8i ", m_state.lastsrc); } - fprintf(m_state.logfile, "tg: %5i ", m_state.lasttg); + fprintf(stderr, "tg: %5i ", m_state.lasttg); } int DSDDecoder::comp(const void *a, const void *b) @@ -1622,7 +1621,7 @@ void DSDDecoder::processFrame() if (m_opts.verbose > 0) { int level = (int) m_state.max / 164; - fprintf(m_state.logfile, "inlvl: %2i%% ", level); + fprintf(stderr, "inlvl: %2i%% ", level); } } @@ -1670,7 +1669,7 @@ void DSDDecoder::processFrame() if (m_opts.verbose > 0) { int level = (int) m_state.max / 164; - fprintf(m_state.logfile, "inlvl: %2i%% ", level); + fprintf(stderr, "inlvl: %2i%% ", level); } } diff --git a/dsdplus/dsd_decoder.h b/dsdplus/dsd_decoder.h index 844d8879b..68552cc80 100644 --- a/dsdplus/dsd_decoder.h +++ b/dsdplus/dsd_decoder.h @@ -91,6 +91,19 @@ public: ~DSDDecoder(); void run(short sample); + + short *getAudio(int& nbSamples) + { + nbSamples = m_state.audio_out_nb_samples; + return m_state.audio_out_buf; + } + + void resetAudio() + { + m_state.audio_out_nb_samples = 0; + m_state.audio_out_buf_p = m_state.audio_out_buf; + } + DSDOpts *getOpts() { return &m_opts; } DSDState *getState() { return &m_state; } diff --git a/dsdplus/dsd_mbe.cpp b/dsdplus/dsd_mbe.cpp index 08d8639b2..ba3f729b4 100644 --- a/dsdplus/dsd_mbe.cpp +++ b/dsdplus/dsd_mbe.cpp @@ -16,10 +16,13 @@ #include #include -#include #include "dsd_mbe.h" #include "dsd_decoder.h" +extern "C" { +#include +} + namespace DSDplus { @@ -68,7 +71,7 @@ void DSDMBEDecoder::processFrame(char imbe_fr[8][23], char ambe_fr[4][24], char if (m_dsdDecoder->m_opts.errorbars == 1) { - fprintf(m_dsdDecoder->m_state.logfile, "%s", m_dsdDecoder->m_state.err_str); + fprintf(stderr, "%s", m_dsdDecoder->m_state.err_str); } processAudio(); @@ -179,11 +182,18 @@ void DSDMBEDecoder::processAudio() m_dsdDecoder->m_state.aout_gain += ((float) 160 * gaindelta); } - // copy audio datat to output buffer and upsample if necessary + // copy audio data to output buffer and upsample if necessary m_dsdDecoder->m_state.audio_out_temp_buf_p = m_dsdDecoder->m_state.audio_out_temp_buf; - if (m_dsdDecoder->m_opts.split == 0) + if ((m_dsdDecoder->m_opts.split == 0) || (m_dsdDecoder->m_opts.upsample != 0)) // upsampling to 48k { + if (m_dsdDecoder->m_state.audio_out_nb_samples + 960 >= m_dsdDecoder->m_state.audio_out_buf_size) + { + m_dsdDecoder->resetAudio(); + } + + m_dsdDecoder->m_state.audio_out_float_buf_p = m_dsdDecoder->m_state.audio_out_float_buf; + for (n = 0; n < 160; n++) { upsample(*m_dsdDecoder->m_state.audio_out_temp_buf_p); @@ -193,7 +203,7 @@ void DSDMBEDecoder::processAudio() m_dsdDecoder->m_state.audio_out_idx2 += 6; } - m_dsdDecoder->m_state.audio_out_float_buf_p -= (960 + m_dsdDecoder->m_opts.playoffset); + m_dsdDecoder->m_state.audio_out_float_buf_p = m_dsdDecoder->m_state.audio_out_float_buf; // copy to output (short) buffer for (n = 0; n < 960; n++) @@ -209,13 +219,26 @@ void DSDMBEDecoder::processAudio() *m_dsdDecoder->m_state.audio_out_buf_p = (short) *m_dsdDecoder->m_state.audio_out_float_buf_p; m_dsdDecoder->m_state.audio_out_buf_p++; + + if (m_dsdDecoder->m_opts.stereo) // produce second channel + { + *m_dsdDecoder->m_state.audio_out_buf_p = (short) *m_dsdDecoder->m_state.audio_out_float_buf_p; + m_dsdDecoder->m_state.audio_out_buf_p++; + } + + m_dsdDecoder->m_state.audio_out_nb_samples++; m_dsdDecoder->m_state.audio_out_float_buf_p++; } m_dsdDecoder->m_state.audio_out_float_buf_p += m_dsdDecoder->m_opts.playoffset; } - else + else // leave at 8k { + if (m_dsdDecoder->m_state.audio_out_nb_samples + 160 >= m_dsdDecoder->m_state.audio_out_buf_size) + { + m_dsdDecoder->resetAudio(); + } + for (n = 0; n < 160; n++) { if (*m_dsdDecoder->m_state.audio_out_temp_buf_p > (float) 32760) @@ -229,13 +252,19 @@ void DSDMBEDecoder::processAudio() *m_dsdDecoder->m_state.audio_out_buf_p = (short) *m_dsdDecoder->m_state.audio_out_temp_buf_p; m_dsdDecoder->m_state.audio_out_buf_p++; + + if (m_dsdDecoder->m_opts.stereo) // produce second channel + { + *m_dsdDecoder->m_state.audio_out_buf_p = (short) *m_dsdDecoder->m_state.audio_out_float_buf_p; + m_dsdDecoder->m_state.audio_out_buf_p++; + } + + m_dsdDecoder->m_state.audio_out_nb_samples++; m_dsdDecoder->m_state.audio_out_temp_buf_p++; m_dsdDecoder->m_state.audio_out_idx++; m_dsdDecoder->m_state.audio_out_idx2++; } } - - // TODO: flag audio is uvailable } void DSDMBEDecoder::upsample(float invalue) diff --git a/dsdplus/dsd_opts.cpp b/dsdplus/dsd_opts.cpp index d56c87c22..610f49ef8 100644 --- a/dsdplus/dsd_opts.cpp +++ b/dsdplus/dsd_opts.cpp @@ -56,6 +56,7 @@ DSDOpts::DSDOpts() use_cosine_filter = 1; unmute_encrypted_p25 = 0; upsample = 0; + stereo = 0; } DSDOpts::~DSDOpts() diff --git a/dsdplus/dsd_opts.h b/dsdplus/dsd_opts.h index d91d37194..7c2e44cf8 100644 --- a/dsdplus/dsd_opts.h +++ b/dsdplus/dsd_opts.h @@ -60,7 +60,8 @@ public: int delay; int use_cosine_filter; int unmute_encrypted_p25; - int upsample; + int upsample; //!< force audio upsampling to 48k + int stereo; //!< double each audio sample to produce L+R channels }; } // namespace dsdplus diff --git a/dsdplus/dsd_state.cpp b/dsdplus/dsd_state.cpp index 4348710e2..2be8bedba 100644 --- a/dsdplus/dsd_state.cpp +++ b/dsdplus/dsd_state.cpp @@ -23,19 +23,27 @@ DSDState::DSDState() { int i, j; - dibit_buf = (int *) malloc(sizeof(int) * 1000000); - dibit_buf_p = dibit_buf + 200; - memset (dibit_buf, 0, sizeof (int) * 200); repeat = 0; - audio_out_buf = (short *) malloc(sizeof(short) * 1000000); - memset (audio_out_buf, 0, 100 * sizeof (short)); - audio_out_buf_p = audio_out_buf + 100; - audio_out_float_buf = (float *) malloc(sizeof(float) * 1000000); - memset (audio_out_float_buf, 0, 100 * sizeof (float)); - audio_out_float_buf_p = audio_out_float_buf + 100; + + dibit_buf = (int *) malloc(sizeof(int) * 1000000); + memset(dibit_buf, 0, sizeof(int) * 200); + dibit_buf_p = dibit_buf + 200; + + audio_out_buf = (short *) malloc(sizeof(short) * 2 * 48000); // 1s of L+R S16LE samples + memset(audio_out_buf, 0, sizeof(short) * 2 * 48000); + audio_out_buf_p = audio_out_buf; + audio_out_nb_samples = 0; + audio_out_buf_size = 48000; // given in number of unique samples + + audio_out_float_buf = (float *) malloc(sizeof(float) * 960); // 1 frame of 160 samples upampled 6 times + memset(audio_out_float_buf, 0, sizeof(float) * 960); + audio_out_float_buf_p = audio_out_float_buf; + + audio_out_temp_buf_p = audio_out_temp_buf; + audio_out_idx = 0; audio_out_idx2 = 0; - audio_out_temp_buf_p = audio_out_temp_buf; + center = 0; jitter = -1; synctype = -1; @@ -46,23 +54,28 @@ DSDState::DSDState() minref = -12000; maxref = 12000; lastsample = 0; + for (i = 0; i < 128; i++) - { + { sbuf[i] = 0; - } + } + sidx = 0; + for (i = 0; i < 1024; i++) - { + { maxbuf[i] = 15000; - } + } + for (i = 0; i < 1024; i++) - { + { minbuf[i] = -15000; - } + } + midx = 0; err_str[0] = 0; - sprintf (fsubtype, " "); - sprintf (ftype, " "); + sprintf(fsubtype, " "); + sprintf(ftype, " "); symbolcnt = 0; rf_mod = 0; numflips = 0; @@ -70,13 +83,15 @@ DSDState::DSDState() lastp25type = 0; offset = 0; carrier = 0; + for (i = 0; i < 25; i++) - { + { for (j = 0; j < 16; j++) - { + { tg[i][j] = 48; - } - } + } + } + tgcount = 0; lasttg = 0; lastsrc = 0; @@ -87,30 +102,27 @@ DSDState::DSDState() optind = 0; numtdulc = 0; firstframe = 0; - sprintf (slot0light, " slot0 "); - sprintf (slot1light, " slot1 "); + sprintf(slot0light, " slot0 "); + sprintf(slot1light, " slot1 "); aout_gain = 25; - memset (aout_max_buf, 0, sizeof (float) * 200); + memset(aout_max_buf, 0, sizeof(float) * 200); aout_max_buf_p = aout_max_buf; aout_max_buf_idx = 0; samplesPerSymbol = 10; symbolCenter = 4; - sprintf (algid, "________"); - sprintf (keyid, "________________"); + sprintf(algid, "________"); + sprintf(keyid, "________________"); currentslot = 0; - cur_mp = (mbe_parms *) malloc (sizeof (mbe_parms)); - prev_mp = (mbe_parms *) malloc (sizeof (mbe_parms)); - prev_mp_enhanced = (mbe_parms *) malloc (sizeof (mbe_parms)); - mbe_initMbeParms (cur_mp, prev_mp, prev_mp_enhanced); + cur_mp = (mbe_parms *) malloc(sizeof(mbe_parms)); + prev_mp = (mbe_parms *) malloc(sizeof(mbe_parms)); + prev_mp_enhanced = (mbe_parms *) malloc(sizeof(mbe_parms)); + mbe_initMbeParms(cur_mp, prev_mp, prev_mp_enhanced); p25kid = 0; output_finished = 0; - input_offset = 0; output_offset = 0; - input_samples = 0; output_num_samples = 0; output_samples = 0; - input_length = 0; output_length = 0; output_buffer = 0; } diff --git a/dsdplus/dsd_state.h b/dsdplus/dsd_state.h index 57ec46f6d..394a71ac5 100644 --- a/dsdplus/dsd_state.h +++ b/dsdplus/dsd_state.h @@ -20,7 +20,10 @@ #include #include #include + +extern "C" { #include +} namespace DSDplus { @@ -34,11 +37,13 @@ public: int *dibit_buf; int *dibit_buf_p; int repeat; - short *audio_out_buf; + short *audio_out_buf; //!< final result short *audio_out_buf_p; - float *audio_out_float_buf; + int audio_out_nb_samples; + int audio_out_buf_size; + float *audio_out_float_buf; //!< output of upsampler float *audio_out_float_buf_p; - float audio_out_temp_buf[160]; + float audio_out_temp_buf[160]; //!< output of decoder float *audio_out_temp_buf_p; int audio_out_idx; int audio_out_idx2; @@ -94,17 +99,12 @@ public: mbe_parms *prev_mp_enhanced; int p25kid; - const float *input_samples; - int input_length; - int input_offset; - short *output_buffer; int output_offset; float *output_samples; int output_num_samples; int output_length; int output_finished; - FILE *logfile; }; } // namespace dsdplus diff --git a/dsdplus/dstar.cpp b/dsdplus/dstar.cpp index 8304517db..ef6c5e4ec 100644 --- a/dsdplus/dstar.cpp +++ b/dsdplus/dstar.cpp @@ -136,7 +136,7 @@ DSDDstar::~DSDDstar() void DSDDstar::init() { if (m_dsdDecoder->m_opts.errorbars == 1) { - fprintf(m_dsdDecoder->m_state.logfile, "e:"); + fprintf(stderr, "e:"); } if (m_dsdDecoder->m_state.synctype == 18) { @@ -226,7 +226,7 @@ void DSDDstar::processVoice() if ((bitbuffer & 0x00FFFFFF) == 0x00AAB468) { // we're slipping bits - fprintf(m_dsdDecoder->m_state.logfile, "sync in voice after i=%d, restarting\n", i); + fprintf(stderr, "sync in voice after i=%d, restarting\n", i); //ugh just start over i = 0; w = dW; @@ -267,7 +267,7 @@ void DSDDstar::processData() // looking if we're slipping bits if (i != 96) { - fprintf(m_dsdDecoder->m_state.logfile, "sync after i=%d\n", i); + fprintf(stderr, "sync after i=%d\n", i); break; } } diff --git a/plugins/channel/demoddsd/dsddecoder.cpp b/plugins/channel/demoddsd/dsddecoder.cpp index 5fb2a7837..95936f0ae 100644 --- a/plugins/channel/demoddsd/dsddecoder.cpp +++ b/plugins/channel/demoddsd/dsddecoder.cpp @@ -50,19 +50,10 @@ DSDDecoder::DSDDecoder() dsdstate->rf_mod = 0; dsdstate->output_offset = 0; - - m_zeroBuffer = new short[1<<18]; // 128 kS - memset(m_zeroBuffer, 0, sizeof(short) * (1<<18)); + dsdopts->upsample = 1; + dsdopts->stereo = 1; } DSDDecoder::~DSDDecoder() { } - -void DSDDecoder::pushSamples(const short *samples,int nbSamples) -{ -} - -void DSDDecoder::popAudioSamples(AudioFifo *audioFifo, bool audioMute) -{ -} diff --git a/plugins/channel/demoddsd/dsddecoder.h b/plugins/channel/demoddsd/dsddecoder.h index 1c366abb5..20177358c 100644 --- a/plugins/channel/demoddsd/dsddecoder.h +++ b/plugins/channel/demoddsd/dsddecoder.h @@ -28,12 +28,12 @@ public: DSDDecoder(); ~DSDDecoder(); - void pushSamples(const short *samples, int nbSamples); // Push this amount of samples to the DSD decoder thread - void popAudioSamples(AudioFifo *audioFifo, bool audioMute); + void pushSample(short sample) { m_decoder.run(sample); } + short *getAudio(int& nbSamples) { return m_decoder.getAudio(nbSamples); } + void resetAudio() { m_decoder.resetAudio(); } private: DSDplus::DSDDecoder m_decoder; - short *m_zeroBuffer; }; #endif /* PLUGINS_CHANNEL_DEMODDSD_DSDDECODER_H_ */ diff --git a/plugins/channel/demoddsd/dsddemod.cpp b/plugins/channel/demoddsd/dsddemod.cpp index 22f9df461..f16806912 100644 --- a/plugins/channel/demoddsd/dsddemod.cpp +++ b/plugins/channel/demoddsd/dsddemod.cpp @@ -43,8 +43,6 @@ DSDDemod::DSDDemod(SampleSink* sampleSink) : { setObjectName("DSDDemod"); - m_samplesBuffer = new qint16[1<<18]; // 128 k Samples is the maximum size of all input devices sample buffers (Airspy or HackRF) = 2^(17+1) for 2 byte samples - m_config.m_inputSampleRate = 96000; m_config.m_inputFrequencyOffset = 0; m_config.m_rfBandwidth = 100; @@ -69,7 +67,6 @@ DSDDemod::DSDDemod(SampleSink* sampleSink) : DSDDemod::~DSDDemod() { DSPEngine::instance()->removeAudioSink(&m_audioFifo); - delete[] m_samplesBuffer; } void DSDDemod::configure(MessageQueue* messageQueue, @@ -96,7 +93,6 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto Complex ci; m_settingsMutex.lock(); - m_samplesBufferIndex = 0; m_scopeSampleBuffer.clear(); for (SampleVector::const_iterator it = begin; it != end; ++it) @@ -141,7 +137,7 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto Sample s(sample, 0.0); m_scopeSampleBuffer.push_back(s); - m_samplesBuffer[m_samplesBufferIndex++] = sample; + m_dsdDecoder.pushSample(sample); // if (m_running.m_audioMute) // { @@ -185,8 +181,18 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto // m_audioBufferFill = 0; // } - m_dsdDecoder.popAudioSamples(&m_audioFifo, m_running.m_audioMute); - m_dsdDecoder.pushSamples(m_samplesBuffer, m_samplesBufferIndex); + int nbAudioSamples; + short *audio = m_dsdDecoder.getAudio(nbAudioSamples); + + if (nbAudioSamples > 0) + { + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], nbAudioSamples, 10); + + if (res != nbAudioSamples) + { + qDebug("NFMDemod::feed: %u/%u tail samples written", res, nbAudioSamples); + } + } if ((m_scope != 0) && (m_scopeEnabled)) { diff --git a/plugins/channel/demoddsd/dsddemod.h b/plugins/channel/demoddsd/dsddemod.h index 83c8d132f..20c70a9c3 100644 --- a/plugins/channel/demoddsd/dsddemod.h +++ b/plugins/channel/demoddsd/dsddemod.h @@ -169,8 +169,6 @@ private: Real m_fmExcursion; - qint16 *m_samplesBuffer; //!< Input buffer for DSD decoder process - int m_samplesBufferIndex; SampleVector m_scopeSampleBuffer; AudioVector m_audioBuffer; uint m_audioBufferFill;