mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
DSD demod plugin: DSD proper integration interim state #1
This commit is contained in:
parent
9ef7497c40
commit
5872ee0ca7
@ -17,8 +17,7 @@
|
||||
|
||||
#include "dsd.h"
|
||||
|
||||
void
|
||||
processAudio (dsd_opts * opts, dsd_state * state)
|
||||
void processAudio(dsd_opts * opts, dsd_state * state)
|
||||
{
|
||||
|
||||
int i, n;
|
||||
@ -90,12 +89,14 @@ processAudio (dsd_opts * opts, dsd_state * state)
|
||||
gaindelta = (float) 0;
|
||||
}
|
||||
|
||||
if(opts->audio_gain >= 0){
|
||||
if (opts->audio_gain >= 0)
|
||||
{
|
||||
// adjust output gain
|
||||
state->audio_out_temp_buf_p = state->audio_out_temp_buf;
|
||||
for (n = 0; n < 160; n++)
|
||||
{
|
||||
*state->audio_out_temp_buf_p = (state->aout_gain + ((float) n * gaindelta)) * (*state->audio_out_temp_buf_p);
|
||||
*state->audio_out_temp_buf_p = (state->aout_gain
|
||||
+ ((float) n * gaindelta)) * (*state->audio_out_temp_buf_p);
|
||||
state->audio_out_temp_buf_p++;
|
||||
}
|
||||
state->aout_gain += ((float) 160 * gaindelta);
|
||||
@ -103,7 +104,7 @@ processAudio (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
// copy audio datat to output buffer and upsample if necessary
|
||||
state->audio_out_temp_buf_p = state->audio_out_temp_buf;
|
||||
if (opts->split == 0)
|
||||
if ((opts->split == 0) || (opts->upsample))
|
||||
{
|
||||
for (n = 0; n < 160; n++)
|
||||
{
|
||||
@ -152,8 +153,7 @@ processAudio (dsd_opts * opts, dsd_state * state)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
writeSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
||||
void writeSynthesizedVoice(dsd_opts * opts, dsd_state * state)
|
||||
{
|
||||
#ifdef USE_LIBSNDFILE
|
||||
int n;
|
||||
@ -214,8 +214,7 @@ writeSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
||||
void playSynthesizedVoice(dsd_opts * opts, dsd_state * state)
|
||||
{
|
||||
|
||||
ssize_t result;
|
||||
@ -225,12 +224,16 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
||||
// output synthesized speech to sound card
|
||||
if (opts->audio_out_fd == -1)
|
||||
{
|
||||
memcpy(state->output_buffer + state->output_offset, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2));
|
||||
memcpy(state->output_buffer + state->output_offset,
|
||||
(state->audio_out_buf_p - state->audio_out_idx),
|
||||
(state->audio_out_idx * 2));
|
||||
state->output_offset += state->audio_out_idx;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = write (opts->audio_out_fd, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2));
|
||||
result = write(opts->audio_out_fd,
|
||||
(state->audio_out_buf_p - state->audio_out_idx),
|
||||
(state->audio_out_idx * 2));
|
||||
}
|
||||
state->audio_out_idx = 0;
|
||||
}
|
||||
@ -245,18 +248,21 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
openAudioOutDevice (dsd_opts * opts, int speed)
|
||||
void openAudioOutDevice(dsd_opts * opts, int speed)
|
||||
{
|
||||
// get info of device/file
|
||||
struct stat stat_buf;
|
||||
if(stat(opts->audio_out_dev, &stat_buf) != 0) {
|
||||
if (stat(opts->audio_out_dev, &stat_buf) != 0)
|
||||
{
|
||||
fprintf(stderr, "Error, couldn't open %s\n", opts->audio_out_dev);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if( !(S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode))) { // this is not a device
|
||||
fprintf(stderr, "Error, %s is not a device. use -w filename for wav output.\n", opts->audio_out_dev);
|
||||
if (!(S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode)))
|
||||
{ // this is not a device
|
||||
fprintf(stderr,
|
||||
"Error, %s is not a device. use -w filename for wav output.\n",
|
||||
opts->audio_out_dev);
|
||||
exit(1);
|
||||
}
|
||||
#ifdef SOLARIS
|
||||
@ -325,27 +331,30 @@ openAudioOutDevice (dsd_opts * opts, int speed)
|
||||
fprintf(stderr, "Audio Out Device: %s\n", opts->audio_out_dev);
|
||||
}
|
||||
|
||||
void
|
||||
openAudioInDevice (dsd_opts * opts)
|
||||
void openAudioInDevice(dsd_opts * opts)
|
||||
{
|
||||
#ifdef USE_LIBSNDFILE
|
||||
// get info of device/file
|
||||
struct stat stat_buf;
|
||||
if (stat(opts->audio_in_dev, &stat_buf) != 0) {
|
||||
if (stat(opts->audio_in_dev, &stat_buf) != 0)
|
||||
{
|
||||
fprintf(stderr, "Error, couldn't open %s\n", opts->audio_in_dev);
|
||||
exit(1);
|
||||
}
|
||||
if(S_ISREG(stat_buf.st_mode)) { // is this a regular file? then process with libsndfile.
|
||||
if(S_ISREG(stat_buf.st_mode))
|
||||
{ // is this a regular file? then process with libsndfile.
|
||||
opts->audio_in_type = 1;
|
||||
opts->audio_in_file_info = calloc(1, sizeof(SF_INFO));
|
||||
opts->audio_in_file_info->channels = 1;
|
||||
opts->audio_in_file = sf_open(opts->audio_in_dev, SFM_READ, opts->audio_in_file_info);
|
||||
if(opts->audio_in_file == NULL) {
|
||||
if(opts->audio_in_file == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error, couldn't open file %s\n", opts->audio_in_dev);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else { // this is a device, use old handling
|
||||
else
|
||||
{ // this is a device, use old handling
|
||||
opts->audio_in_type = 0;
|
||||
#ifdef SOLARIS
|
||||
sample_info_t aset, aget;
|
||||
|
@ -78,5 +78,6 @@ void initOpts(dsd_opts * opts)
|
||||
opts->delay = 0;
|
||||
opts->use_cosine_filter = 1;
|
||||
opts->unmute_encrypted_p25 = 0;
|
||||
opts->upsample = 0; // by default stay with 8k audio
|
||||
}
|
||||
|
||||
|
@ -132,5 +132,6 @@ void initState(dsd_state * state)
|
||||
}
|
||||
|
||||
state->dsd_running = 0;
|
||||
state->output_phasor = 0;
|
||||
}
|
||||
|
||||
|
@ -111,9 +111,11 @@ typedef struct
|
||||
short *output_buffer; //!< Output of decoder single S16LE
|
||||
int output_offset; //!< producer pointer
|
||||
short *output_samples; //!< L+R channels S16LE ready for writing to audio FIFO
|
||||
int output_buffers_size; //!< Size of buffers in number of samples
|
||||
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; //!< Number of wished samples
|
||||
int output_finished; //!< 0: not ready, 1: ready
|
||||
float output_phasor;
|
||||
|
||||
pthread_mutex_t input_mutex;
|
||||
pthread_cond_t input_ready;
|
||||
|
@ -102,22 +102,36 @@ int getSymbol(dsd_opts * opts, dsd_state * state, int have_sync)
|
||||
{
|
||||
int i;
|
||||
state->input_length = 0; // states all samples have been consumed
|
||||
state->input_offset = 0;
|
||||
|
||||
// debug ...
|
||||
for (i = 0; i < state->output_length; i++)
|
||||
{
|
||||
float s = sin(state->output_phasor);
|
||||
state->output_phasor = fmod(state->output_phasor + (M_PI / 48.0), 2.0 * M_PI);
|
||||
state->output_samples[2*state->output_offset + 2*i] = s * 16368.0f;
|
||||
state->output_samples[2*state->output_offset + 2*i+1] = s * 16368.0f;
|
||||
}
|
||||
state->output_offset += state->output_length;
|
||||
state->output_num_samples = state->output_offset;
|
||||
// ... debug
|
||||
|
||||
//ffprintf(stderr, stderr, "dsd::getSymbol: input processing has finished\n");
|
||||
|
||||
if (state->output_num_samples > state->output_length)
|
||||
{
|
||||
fprintf(stderr, "WARNING: audio buffer over-run! Truncating output\n");
|
||||
state->output_num_samples = state->output_length;
|
||||
}
|
||||
|
||||
for (i = 0; i < state->output_num_samples; i++)
|
||||
{
|
||||
state->output_samples[2*i] = state->output_buffer[i]; // L channel
|
||||
state->output_samples[2*i+1] = state->output_buffer[i]; // R channel
|
||||
}
|
||||
|
||||
// state->output_num_samples = state->output_offset;
|
||||
//
|
||||
// //ffprintf(stderr, stderr, "dsd::getSymbol: input processing has finished\n");
|
||||
//
|
||||
// if (state->output_num_samples > state->output_length)
|
||||
// {
|
||||
// fprintf(stderr, "WARNING: audio buffer over-run! Truncating output\n");
|
||||
// state->output_num_samples = state->output_length;
|
||||
// }
|
||||
//
|
||||
// for (i = 0; i < state->output_num_samples; i++)
|
||||
// {
|
||||
// state->output_samples[2*i] = state->output_buffer[i]; // L channel
|
||||
// state->output_samples[2*i+1] = state->output_buffer[i]; // R channel
|
||||
// }
|
||||
//
|
||||
state->output_finished = 1;
|
||||
}
|
||||
else
|
||||
|
@ -17,8 +17,56 @@
|
||||
|
||||
#include "dsd.h"
|
||||
|
||||
void
|
||||
upsample (dsd_state * state, float invalue)
|
||||
void upsample(dsd_state * state, float invalue)
|
||||
{
|
||||
|
||||
int i, j, sum;
|
||||
float *outbuf1, c, d;
|
||||
|
||||
outbuf1 = state->audio_out_float_buf_p;
|
||||
outbuf1--;
|
||||
c = *outbuf1;
|
||||
d = invalue;
|
||||
// basic triangle interpolation
|
||||
outbuf1++;
|
||||
*outbuf1 = ((invalue * (float) 0.166) + (c * (float) 0.834));
|
||||
outbuf1++;
|
||||
*outbuf1 = ((invalue * (float) 0.332) + (c * (float) 0.668));
|
||||
outbuf1++;
|
||||
*outbuf1 = ((invalue * (float) 0.5) + (c * (float) 0.5));
|
||||
outbuf1++;
|
||||
*outbuf1 = ((invalue * (float) 0.668) + (c * (float) 0.332));
|
||||
outbuf1++;
|
||||
*outbuf1 = ((invalue * (float) 0.834) + (c * (float) 0.166));
|
||||
outbuf1++;
|
||||
*outbuf1 = d;
|
||||
outbuf1++;
|
||||
|
||||
if (state->audio_out_idx2 > 24)
|
||||
{
|
||||
// smoothing
|
||||
outbuf1 -= 16;
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
sum = 0;
|
||||
outbuf1 -= 2;
|
||||
sum += *outbuf1;
|
||||
outbuf1 += 2;
|
||||
sum += *outbuf1;
|
||||
outbuf1 += 2;
|
||||
sum += *outbuf1;
|
||||
outbuf1 -= 2;
|
||||
*outbuf1 = (sum / (float) 3);
|
||||
outbuf1++;
|
||||
}
|
||||
outbuf1 -= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void upsample16(dsd_state * state, short invalue)
|
||||
{
|
||||
|
||||
int i, j, sum;
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include <QtGlobal>
|
||||
#include "dsddecoder.h"
|
||||
#include "dsd_livescanner.h"
|
||||
#include "audio/audiofifo.h"
|
||||
|
||||
|
||||
DSDDecoder::DSDDecoder()
|
||||
{
|
||||
@ -25,6 +27,7 @@ DSDDecoder::DSDDecoder()
|
||||
initState(&m_dsdParams.state);
|
||||
|
||||
m_dsdParams.opts.split = 1;
|
||||
m_dsdParams.opts.upsample = 1; // force upsampling of audio to 48k
|
||||
m_dsdParams.opts.playoffset = 0;
|
||||
m_dsdParams.opts.delay = 0;
|
||||
m_dsdParams.opts.audio_in_type = 0;
|
||||
@ -54,6 +57,7 @@ DSDDecoder::DSDDecoder()
|
||||
|
||||
m_dsdParams.state.output_buffer = (short *) malloc(1<<18); // Raw output buffer with single S16LE samples @ 8k (max: 128 kS)
|
||||
m_dsdParams.state.output_offset = 0;
|
||||
m_dsdParams.state.output_finished = 0;
|
||||
|
||||
if (m_dsdParams.state.output_buffer == NULL)
|
||||
{
|
||||
@ -61,13 +65,17 @@ DSDDecoder::DSDDecoder()
|
||||
}
|
||||
|
||||
m_dsdParams.state.output_samples = (short *) malloc(1<<19); // Audio output buffer with L+R S16LE samples (max: 128 kS)
|
||||
m_dsdParams.state.output_length = 1<<19; // the buffer size fixed
|
||||
m_dsdParams.state.output_buffers_size = 1<<17; // the buffers size in number of samples: 128 kS
|
||||
|
||||
if (m_dsdParams.state.output_samples == NULL)
|
||||
{
|
||||
qCritical("DSDDecoder::DSDDecoder: Unable to allocate audio L+R buffer.");
|
||||
}
|
||||
|
||||
m_dsdParams.state.output_offset = 0;
|
||||
m_zeroBuffer = new short[1<<18]; // 128 kS
|
||||
memset(m_zeroBuffer, 0, sizeof(short) * (1<<18));
|
||||
m_lastNbSamples = 0;
|
||||
}
|
||||
|
||||
DSDDecoder::~DSDDecoder()
|
||||
@ -82,14 +90,47 @@ void DSDDecoder::setInBuffer(const short *inBuffer)
|
||||
}
|
||||
|
||||
void DSDDecoder::pushSamples(int nbSamples)
|
||||
{
|
||||
if (nbSamples == 0)
|
||||
{
|
||||
m_lastNbSamples = 0;
|
||||
m_dsdParams.state.output_offset = 0; // reset output
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dsdParams.state.input_offset = 0;
|
||||
m_dsdParams.state.input_length = nbSamples;
|
||||
m_dsdParams.state.output_finished = 0;
|
||||
m_dsdParams.state.output_length = m_lastNbSamples;
|
||||
m_lastNbSamples = nbSamples;
|
||||
|
||||
if (pthread_cond_signal(&m_dsdParams.state.input_ready)) {
|
||||
printf("DSDDecoder::pushSamples: Unable to signal input ready");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DSDDecoder::popAudioSamples(AudioFifo *audioFifo, bool audioMute)
|
||||
{
|
||||
if (audioMute)
|
||||
{
|
||||
uint res = audioFifo->write((const quint8*) m_zeroBuffer, m_dsdParams.state.output_num_samples, 10);
|
||||
|
||||
if (res != m_dsdParams.state.output_num_samples) {
|
||||
qDebug("DSDDemod::feed: %u/%u audio samples written", res, m_dsdParams.state.output_num_samples);
|
||||
}
|
||||
}
|
||||
else if (m_dsdParams.state.output_finished)
|
||||
{
|
||||
uint res = audioFifo->write((const quint8*) m_dsdParams.state.output_samples, m_dsdParams.state.output_num_samples, 10);
|
||||
|
||||
if (res != m_dsdParams.state.output_num_samples) {
|
||||
qDebug("DSDDemod::feed: %u/%u audio samples written", res, m_dsdParams.state.output_num_samples);
|
||||
}
|
||||
}
|
||||
|
||||
m_dsdParams.state.output_finished = 0; // will be done by the next push anyway
|
||||
}
|
||||
|
||||
void DSDDecoder::start()
|
||||
{
|
||||
@ -102,6 +143,8 @@ void DSDDecoder::start()
|
||||
m_dsdParams.state.dsd_running = 0;
|
||||
}
|
||||
|
||||
m_lastNbSamples = 0;
|
||||
|
||||
qDebug("DSDDecoder::start: started");
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "dsd.h"
|
||||
|
||||
class AudioFifo;
|
||||
|
||||
class DSDDecoder
|
||||
{
|
||||
public:
|
||||
@ -27,7 +29,9 @@ public:
|
||||
~DSDDecoder();
|
||||
|
||||
void setInBuffer(const short *inBuffer);
|
||||
void pushSample(short sample);
|
||||
void pushSamples(int nbSamples); // Push this amount of samples to the DSD decoder thread
|
||||
void popAudioSamples(AudioFifo *audioFifo, bool audioMute);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
@ -42,6 +46,8 @@ private:
|
||||
static void* run_dsd(void *arg);
|
||||
|
||||
dsd_params m_dsdParams;
|
||||
short *m_zeroBuffer;
|
||||
int m_lastNbSamples;
|
||||
};
|
||||
|
||||
#endif /* PLUGINS_CHANNEL_DEMODDSD_DSDDECODER_H_ */
|
||||
|
@ -145,52 +145,51 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
m_scopeSampleBuffer.push_back(s);
|
||||
m_dsdInBuffer[m_dsdInCount++] = sample;
|
||||
|
||||
if (m_running.m_audioMute)
|
||||
{
|
||||
m_audioBuffer[m_audioBufferFill].l = 0;
|
||||
m_audioBuffer[m_audioBufferFill].r = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_audioBuffer[m_audioBufferFill].l = sample;
|
||||
m_audioBuffer[m_audioBufferFill].r = sample;
|
||||
}
|
||||
|
||||
++m_audioBufferFill;
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
qDebug("DSDDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
|
||||
}
|
||||
|
||||
m_audioBufferFill = 0;
|
||||
}
|
||||
// if (m_running.m_audioMute)
|
||||
// {
|
||||
// m_audioBuffer[m_audioBufferFill].l = 0;
|
||||
// m_audioBuffer[m_audioBufferFill].r = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_audioBuffer[m_audioBufferFill].l = sample;
|
||||
// m_audioBuffer[m_audioBufferFill].r = sample;
|
||||
// }
|
||||
//
|
||||
// ++m_audioBufferFill;
|
||||
//
|
||||
// if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
// {
|
||||
// uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
//
|
||||
// if (res != m_audioBufferFill)
|
||||
// {
|
||||
// qDebug("DSDDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
|
||||
// }
|
||||
//
|
||||
// m_audioBufferFill = 0;
|
||||
// }
|
||||
|
||||
m_interpolatorDistanceRemain += m_interpolatorDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_audioBufferFill > 0)
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
qDebug("NFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill);
|
||||
}
|
||||
// if (m_audioBufferFill > 0)
|
||||
// {
|
||||
// uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
//
|
||||
// if (res != m_audioBufferFill)
|
||||
// {
|
||||
// qDebug("NFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill);
|
||||
// }
|
||||
//
|
||||
// m_audioBufferFill = 0;
|
||||
// }
|
||||
|
||||
m_audioBufferFill = 0;
|
||||
}
|
||||
|
||||
if (m_dsdInCount > 0)
|
||||
{
|
||||
m_dsdDecoder.popAudioSamples(&m_audioFifo, m_running.m_audioMute);
|
||||
m_dsdDecoder.pushSamples(m_dsdInCount);
|
||||
}
|
||||
|
||||
if((m_scope != 0) && (m_scopeEnabled))
|
||||
{
|
||||
|
@ -179,7 +179,7 @@ qint64 AudioOutput::readData(char* data, qint64 maxLen)
|
||||
|
||||
if (samples != framesPerBuffer)
|
||||
{
|
||||
qDebug("AudioOutput::readData: read %d samples vs %d requested", samples, framesPerBuffer);
|
||||
//qDebug("AudioOutput::readData: read %d samples vs %d requested", samples, framesPerBuffer);
|
||||
}
|
||||
|
||||
for (uint i = 0; i < samples; i++)
|
||||
|
Loading…
Reference in New Issue
Block a user