mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-23 08:28:36 -05:00
DSD demod plugin: integration of DSD engine
This commit is contained in:
parent
3f92de1d53
commit
97b60ccb87
@ -15,12 +15,12 @@
|
|||||||
* PERFORMANCE OF THIS SOFTWARE.
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
#include "dsd_cleanupexit.h"
|
#include "dsd_cleanupexit.h"
|
||||||
#include "dsd_nocarrier.h"
|
#include "dsd_nocarrier.h"
|
||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
|
|
||||||
void
|
void cleanupAndExit(dsd_opts * opts, dsd_state * state)
|
||||||
cleanupAndExit (dsd_opts * opts, dsd_state * state)
|
|
||||||
{
|
{
|
||||||
noCarrier(opts, state);
|
noCarrier(opts, state);
|
||||||
#ifdef USE_LIBSNDFILE
|
#ifdef USE_LIBSNDFILE
|
||||||
@ -29,8 +29,7 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state)
|
|||||||
closeWavOutFile (opts, state);
|
closeWavOutFile (opts, state);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
printf ("Exiting.\n");
|
printf("dsd::cleanupAndExit: Exiting.\n");
|
||||||
//exit (0); // You just can't do that within SDRangel
|
int rc = 0;
|
||||||
|
pthread_exit(&rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void printFrameInfo(dsd_opts * opts, dsd_state * state)
|
||||||
printFrameInfo (dsd_opts * opts, dsd_state * state)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
int level;
|
int level;
|
||||||
@ -43,8 +42,7 @@ printFrameInfo (dsd_opts * opts, dsd_state * state)
|
|||||||
printf("tg: %5i ", state->lasttg);
|
printf("tg: %5i ", state->lasttg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void processFrame(dsd_opts * opts, dsd_state * state)
|
||||||
processFrame (dsd_opts * opts, dsd_state * state)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
int i, j, dibit;
|
int i, j, dibit;
|
||||||
@ -181,7 +179,9 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (opts->mbe_out_f != NULL) {
|
||||||
closeMbeOutFile(opts, state);
|
closeMbeOutFile(opts, state);
|
||||||
|
}
|
||||||
state->err_str[0] = 0;
|
state->err_str[0] = 0;
|
||||||
processDMRdata(opts, state);
|
processDMRdata(opts, state);
|
||||||
}
|
}
|
||||||
@ -205,7 +205,9 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (opts->mbe_out_f != NULL) {
|
||||||
closeMbeOutFile(opts, state);
|
closeMbeOutFile(opts, state);
|
||||||
|
}
|
||||||
state->err_str[0] = 0;
|
state->err_str[0] = 0;
|
||||||
processX2TDMAdata(opts, state);
|
processX2TDMAdata(opts, state);
|
||||||
}
|
}
|
||||||
@ -261,10 +263,13 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
if (opts->mbe_out_dir[0] != 0)
|
if (opts->mbe_out_dir[0] != 0)
|
||||||
{
|
{
|
||||||
|
if (opts->mbe_out_f != NULL) {
|
||||||
closeMbeOutFile(opts, state);
|
closeMbeOutFile(opts, state);
|
||||||
|
}
|
||||||
openMbeOutFile(opts, state);
|
openMbeOutFile(opts, state);
|
||||||
}
|
}
|
||||||
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
|
mbe_initMbeParms(state->cur_mp, state->prev_mp,
|
||||||
|
state->prev_mp_enhanced);
|
||||||
state->lastp25type = 2;
|
state->lastp25type = 2;
|
||||||
sprintf(state->fsubtype, " HDU ");
|
sprintf(state->fsubtype, " HDU ");
|
||||||
processHDU(opts, state);
|
processHDU(opts, state);
|
||||||
@ -329,9 +334,12 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
if (opts->mbe_out_dir[0] != 0)
|
if (opts->mbe_out_dir[0] != 0)
|
||||||
{
|
{
|
||||||
|
if (opts->mbe_out_f != NULL) {
|
||||||
closeMbeOutFile(opts, state);
|
closeMbeOutFile(opts, state);
|
||||||
}
|
}
|
||||||
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
|
}
|
||||||
|
mbe_initMbeParms(state->cur_mp, state->prev_mp,
|
||||||
|
state->prev_mp_enhanced);
|
||||||
state->lasttg = 0;
|
state->lasttg = 0;
|
||||||
state->lastsrc = 0;
|
state->lastsrc = 0;
|
||||||
state->lastp25type = 0;
|
state->lastp25type = 0;
|
||||||
@ -352,11 +360,12 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
printFrameInfo(opts, state);
|
printFrameInfo(opts, state);
|
||||||
printf(" TDU\n");
|
printf(" TDU\n");
|
||||||
}
|
}
|
||||||
if (opts->mbe_out_dir[0] != 0)
|
if (opts->mbe_out_f != NULL)
|
||||||
{
|
{
|
||||||
closeMbeOutFile(opts, state);
|
closeMbeOutFile(opts, state);
|
||||||
}
|
}
|
||||||
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
|
mbe_initMbeParms(state->cur_mp, state->prev_mp,
|
||||||
|
state->prev_mp_enhanced);
|
||||||
state->lasttg = 0;
|
state->lasttg = 0;
|
||||||
state->lastsrc = 0;
|
state->lastsrc = 0;
|
||||||
state->lastp25type = 0;
|
state->lastp25type = 0;
|
||||||
|
@ -46,6 +46,7 @@ int
|
|||||||
getFrameSync (dsd_opts * opts, dsd_state * state)
|
getFrameSync (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
/* detects frame sync and returns frame type
|
/* detects frame sync and returns frame type
|
||||||
|
* -1 -> thread has to terminate
|
||||||
* 0 = +P25p1
|
* 0 = +P25p1
|
||||||
* 1 = -P25p1
|
* 1 = -P25p1
|
||||||
* 2 = +X2-TDMA (non inverted signal data frame)
|
* 2 = +X2-TDMA (non inverted signal data frame)
|
||||||
@ -107,6 +108,11 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
|
|||||||
{
|
{
|
||||||
t++;
|
t++;
|
||||||
symbol = getSymbol (opts, state, 0);
|
symbol = getSymbol (opts, state, 0);
|
||||||
|
|
||||||
|
if (!state->dsd_running) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
lbuf[lidx] = symbol;
|
lbuf[lidx] = symbol;
|
||||||
state->sbuf[state->sidx] = symbol;
|
state->sbuf[state->sidx] = symbol;
|
||||||
if (lidx == 23)
|
if (lidx == 23)
|
||||||
|
@ -21,8 +21,13 @@
|
|||||||
|
|
||||||
void liveScanner(dsd_opts * opts, dsd_state * state)
|
void liveScanner(dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
while (1) // FIXME: loop while input available
|
while (state->dsd_running) // FIXME: loop while input available
|
||||||
{
|
{
|
||||||
|
// if (pthread_cond_wait(&state->input_ready, &state->input_mutex)) {
|
||||||
|
// fprintf(stderr, "dsd::liveScanner: Error waiting for input ready condition\n");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fprintf (stderr, "dsd::liveScanner: input is ready\n");
|
||||||
noCarrier(opts, state);
|
noCarrier(opts, state);
|
||||||
state->synctype = getFrameSync(opts, state);
|
state->synctype = getFrameSync(opts, state);
|
||||||
|
|
||||||
@ -31,7 +36,7 @@ void liveScanner(dsd_opts * opts, dsd_state * state)
|
|||||||
state->umid = (((state->max) - state->center) * 5 / 8) + state->center;
|
state->umid = (((state->max) - state->center) * 5 / 8) + state->center;
|
||||||
state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
|
state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
|
||||||
|
|
||||||
while (state->synctype != -1) // TODO: make sure it ends
|
while (state->synctype != -1) // -1 -> exit thread
|
||||||
{
|
{
|
||||||
processFrame(opts, state);
|
processFrame(opts, state);
|
||||||
state->synctype = getFrameSync(opts, state);
|
state->synctype = getFrameSync(opts, state);
|
||||||
@ -42,4 +47,6 @@ void liveScanner(dsd_opts * opts, dsd_state * state)
|
|||||||
state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
|
state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "dsd::liveScanner: end loop\n");
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,14 @@
|
|||||||
#include "dsd_opts.h"
|
#include "dsd_opts.h"
|
||||||
#include "dsd_state.h"
|
#include "dsd_state.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void liveScanner (dsd_opts * opts, dsd_state * state);
|
void liveScanner (dsd_opts * opts, dsd_state * state);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* INCLUDE_DSD_LIVESCANNER_H_ */
|
#endif /* INCLUDE_DSD_LIVESCANNER_H_ */
|
||||||
|
@ -121,5 +121,16 @@ void initState(dsd_state * state)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
initialize_p25_heuristics(&state->p25_heuristics);
|
initialize_p25_heuristics(&state->p25_heuristics);
|
||||||
|
|
||||||
|
// Initialize the mutexes
|
||||||
|
if (pthread_mutex_init(&state->input_mutex, NULL)) {
|
||||||
|
fprintf(stderr, "dsd::initState: Unable to initialize input mutex\n");
|
||||||
|
}
|
||||||
|
// Initialize the conditions
|
||||||
|
if (pthread_cond_init(&state->input_ready, NULL)) {
|
||||||
|
fprintf(stderr, "dsd::initState: Unable to initialize input condition\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
state->dsd_running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#ifndef INCLUDE_DSD_STATE_H_
|
#ifndef INCLUDE_DSD_STATE_H_
|
||||||
#define INCLUDE_DSD_STATE_H_
|
#define INCLUDE_DSD_STATE_H_
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
#include <mbelib.h>
|
#include <mbelib.h>
|
||||||
#include "p25p1_heuristics.h"
|
#include "p25p1_heuristics.h"
|
||||||
|
|
||||||
@ -113,6 +114,11 @@ typedef struct
|
|||||||
int output_num_samples; //!< Number of L+R samples available in the above buffer
|
int output_num_samples; //!< Number of L+R samples available in the above buffer
|
||||||
int output_length; //!< L+R buffer size (fixed)
|
int output_length; //!< L+R buffer size (fixed)
|
||||||
int output_finished; //!< 0: not ready, 1: ready
|
int output_finished; //!< 0: not ready, 1: ready
|
||||||
|
|
||||||
|
pthread_mutex_t input_mutex;
|
||||||
|
pthread_cond_t input_ready;
|
||||||
|
pthread_t dsd_thread;
|
||||||
|
int dsd_running;
|
||||||
} dsd_state;
|
} dsd_state;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -86,40 +86,25 @@ int getSymbol(dsd_opts * opts, dsd_state * state, int have_sync)
|
|||||||
{
|
{
|
||||||
if (opts->audio_in_fd == -1)
|
if (opts->audio_in_fd == -1)
|
||||||
{
|
{
|
||||||
// Get the next sample from the buffer
|
if (state->input_length == 0) // no input available
|
||||||
sample = state->input_samples[state->input_offset++]; // FIXME: get sample only if available
|
{
|
||||||
|
// wait for input
|
||||||
|
if (pthread_cond_wait(&state->input_ready, &state->input_mutex)) {
|
||||||
|
fprintf(stderr, "dsd::getSymbol: Error waiting for input ready condition\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state->input_offset == state->input_length) // all available samples have been read
|
if (!state->dsd_running) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->input_offset == state->input_length) // finished
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
state->input_length = 0; // states all samples have been consumed
|
||||||
// We've reached the end of the buffer. Wait for more next time.
|
|
||||||
state->input_length = 0;
|
|
||||||
|
|
||||||
state->output_num_samples = state->output_offset;
|
state->output_num_samples = state->output_offset;
|
||||||
|
|
||||||
// GNUradio drivel
|
//fprintf(stderr, "dsd::getSymbol: input processing has finished\n");
|
||||||
// if (state->output_num_samples > state->output_length)
|
|
||||||
// {
|
|
||||||
// state->output_num_samples = state->output_length;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (i = 0; i < state->output_length - state->output_num_samples; i++)
|
|
||||||
// {
|
|
||||||
// state->output_samples[i] = 0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (; i < state->output_length; i++)
|
|
||||||
// {
|
|
||||||
// state->output_samples[i] = state->output_buffer[i - (state->output_length - state->output_num_samples)] / 32768.0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// state->output_offset -= state->output_num_samples;
|
|
||||||
//
|
|
||||||
// for (i = 0; i < state->output_offset; i++)
|
|
||||||
// {
|
|
||||||
// state->output_buffer[i] = state->output_buffer[i + state->output_num_samples];
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (state->output_num_samples > state->output_length)
|
if (state->output_num_samples > state->output_length)
|
||||||
{
|
{
|
||||||
@ -135,6 +120,10 @@ int getSymbol(dsd_opts * opts, dsd_state * state, int have_sync)
|
|||||||
|
|
||||||
state->output_finished = 1;
|
state->output_finished = 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sample = state->input_samples[state->input_offset++]; // get sample and move pointer to next
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -83,6 +83,59 @@ void DSDDecoder::setInBuffer(const short *inBuffer)
|
|||||||
|
|
||||||
void DSDDecoder::pushSamples(int nbSamples)
|
void DSDDecoder::pushSamples(int nbSamples)
|
||||||
{
|
{
|
||||||
m_dsdParams.state.input_length = nbSamples;
|
|
||||||
m_dsdParams.state.input_offset = 0;
|
m_dsdParams.state.input_offset = 0;
|
||||||
|
m_dsdParams.state.input_length = nbSamples;
|
||||||
|
|
||||||
|
if (pthread_cond_signal(&m_dsdParams.state.input_ready)) {
|
||||||
|
printf("DSDDecoder::pushSamples: Unable to signal input ready");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DSDDecoder::start()
|
||||||
|
{
|
||||||
|
qDebug("DSDDecoder::start: starting");
|
||||||
|
m_dsdParams.state.dsd_running = 1;
|
||||||
|
|
||||||
|
if (pthread_create(&m_dsdParams.state.dsd_thread, NULL, &run_dsd, &m_dsdParams))
|
||||||
|
{
|
||||||
|
qCritical("DSDDecoder::start: Unable to spawn thread");
|
||||||
|
m_dsdParams.state.dsd_running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug("DSDDecoder::start: started");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DSDDecoder::stop()
|
||||||
|
{
|
||||||
|
if (m_dsdParams.state.dsd_running)
|
||||||
|
{
|
||||||
|
qDebug("DSDDecoder::stop: stopping");
|
||||||
|
m_dsdParams.state.dsd_running = 0;
|
||||||
|
char *b;
|
||||||
|
|
||||||
|
if (pthread_cond_signal(&m_dsdParams.state.input_ready)) {
|
||||||
|
printf("DSDDecoder::pushSamples: Unable to signal input ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (pthread_join(m_dsdParams.state.dsd_thread, (void**) &b)) {
|
||||||
|
// qCritical("DSDDecoder::stop: cannot join dsd thread");
|
||||||
|
// }
|
||||||
|
|
||||||
|
qDebug("DSDDecoder::stop: stopped");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug("DSDDecoder::stop: not running");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* DSDDecoder::run_dsd(void *arg)
|
||||||
|
{
|
||||||
|
dsd_params *params = (dsd_params *) arg;
|
||||||
|
liveScanner (¶ms->opts, ¶ms->state);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ public:
|
|||||||
void setInBuffer(const short *inBuffer);
|
void setInBuffer(const short *inBuffer);
|
||||||
void pushSamples(int nbSamples); // Push this amount of samples to the DSD decoder thread
|
void pushSamples(int nbSamples); // Push this amount of samples to the DSD decoder thread
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -36,6 +39,8 @@ private:
|
|||||||
dsd_state state;
|
dsd_state state;
|
||||||
} dsd_params;
|
} dsd_params;
|
||||||
|
|
||||||
|
static void* run_dsd(void *arg);
|
||||||
|
|
||||||
dsd_params m_dsdParams;
|
dsd_params m_dsdParams;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,10 +209,12 @@ void DSDDemod::start()
|
|||||||
{
|
{
|
||||||
m_audioFifo.clear();
|
m_audioFifo.clear();
|
||||||
m_phaseDiscri.reset();
|
m_phaseDiscri.reset();
|
||||||
|
m_dsdDecoder.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSDDemod::stop()
|
void DSDDemod::stop()
|
||||||
{
|
{
|
||||||
|
m_dsdDecoder.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DSDDemod::handleMessage(const Message& cmd)
|
bool DSDDemod::handleMessage(const Message& cmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user