C-Netz: Make demodulation buffer size dynamic
This commit is contained in:
@@ -181,6 +181,8 @@ void dsp_cleanup_sender(cnetz_t *cnetz)
|
|||||||
free(cnetz->dsp_speech_buffer);
|
free(cnetz->dsp_speech_buffer);
|
||||||
cnetz->dsp_speech_buffer = NULL;
|
cnetz->dsp_speech_buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fsk_fm_exit(&cnetz->fsk_demod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* receive sample time and calculate speed against system clock
|
/* receive sample time and calculate speed against system clock
|
||||||
|
@@ -102,6 +102,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "../common/timer.h"
|
#include "../common/timer.h"
|
||||||
@@ -129,20 +130,42 @@ int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitr
|
|||||||
|
|
||||||
len = (int)((double)samplerate / bitrate + 0.5);
|
len = (int)((double)samplerate / bitrate + 0.5);
|
||||||
half = (int)((double)samplerate / bitrate / 2.0 + 0.5);
|
half = (int)((double)samplerate / bitrate / 2.0 + 0.5);
|
||||||
if (len > (int)(sizeof(fsk->bit_buffer_spl) / sizeof(fsk->bit_buffer_spl[0]))) {
|
fsk->bit_buffer_spl = calloc(sizeof(fsk->bit_buffer_spl[0]), len);
|
||||||
PDEBUG(DDSP, DEBUG_ERROR, "Sample rate too high for buffer, please use lower rate, like 192000 Hz!\n");
|
if (!fsk->bit_buffer_spl) {
|
||||||
return -1;
|
PDEBUG(DDSP, DEBUG_ERROR, "No mem!\n");
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsk->bit_buffer_len = len;
|
fsk->bit_buffer_len = len;
|
||||||
fsk->bit_buffer_half = half;
|
fsk->bit_buffer_half = half;
|
||||||
fsk->bits_per_sample = bitrate / (double)samplerate;
|
fsk->bits_per_sample = bitrate / (double)samplerate;
|
||||||
|
|
||||||
fsk->speech_size = sizeof(fsk->speech_buffer) / sizeof(fsk->speech_buffer[0]);
|
fsk->speech_size = samplerate * 60 / bitrate + 10; /* 60 bits duration, add 10 to be safe */
|
||||||
|
fsk->speech_buffer = calloc(sizeof(fsk->speech_buffer[0]), fsk->speech_size);
|
||||||
|
if (!fsk->speech_buffer) {
|
||||||
|
PDEBUG(DDSP, DEBUG_ERROR, "No mem!\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
fsk->level_threshold = 655;
|
fsk->level_threshold = 655;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
fsk_fm_exit(fsk);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsk_fm_exit(fsk_fm_demod_t *fsk)
|
||||||
|
{
|
||||||
|
if (fsk->bit_buffer_spl) {
|
||||||
|
free(fsk->bit_buffer_spl);
|
||||||
|
fsk->bit_buffer_spl = NULL;
|
||||||
|
}
|
||||||
|
if (fsk->speech_buffer) {
|
||||||
|
free(fsk->speech_buffer);
|
||||||
|
fsk->speech_buffer = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get levels, sync time and jitter from sync sequence or frame data */
|
/* get levels, sync time and jitter from sync sequence or frame data */
|
||||||
|
@@ -20,7 +20,7 @@ typedef struct fsk_fm_demod {
|
|||||||
double bit_time_uncorrected; /* same as above, but not corrected by sync */
|
double bit_time_uncorrected; /* same as above, but not corrected by sync */
|
||||||
|
|
||||||
/* bit detection */
|
/* bit detection */
|
||||||
int16_t bit_buffer_spl[40]; /* samples ring buffer */
|
int16_t *bit_buffer_spl; /* samples ring buffer */
|
||||||
int bit_buffer_len; /* number of samples in ring buffer */
|
int bit_buffer_len; /* number of samples in ring buffer */
|
||||||
int bit_buffer_half; /* half of ring buffer */
|
int bit_buffer_half; /* half of ring buffer */
|
||||||
int bit_buffer_pos; /* current position to write next sample */
|
int bit_buffer_pos; /* current position to write next sample */
|
||||||
@@ -35,7 +35,7 @@ typedef struct fsk_fm_demod {
|
|||||||
double sync_jitter; /* what was the jitter of the sync */
|
double sync_jitter; /* what was the jitter of the sync */
|
||||||
|
|
||||||
/* speech */
|
/* speech */
|
||||||
int16_t speech_buffer[3000]; /* holds one chunk of 12.5ms */
|
int16_t *speech_buffer; /* holds one chunk of 12.5ms */
|
||||||
int speech_size;
|
int speech_size;
|
||||||
int speech_count;
|
int speech_count;
|
||||||
|
|
||||||
@@ -51,6 +51,7 @@ typedef struct fsk_fm_demod {
|
|||||||
} fsk_fm_demod_t;
|
} fsk_fm_demod_t;
|
||||||
|
|
||||||
int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitrate);
|
int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitrate);
|
||||||
|
void fsk_fm_exit(fsk_fm_demod_t *fsk);
|
||||||
void fsk_fm_demod(fsk_fm_demod_t *fsk, int16_t *samples, int length);
|
void fsk_fm_demod(fsk_fm_demod_t *fsk, int16_t *samples, int length);
|
||||||
void fsk_correct_sync(fsk_fm_demod_t *fsk, double offset);
|
void fsk_correct_sync(fsk_fm_demod_t *fsk, double offset);
|
||||||
void fsk_copy_sync(fsk_fm_demod_t *fsk_to, fsk_fm_demod_t *fsk_from);
|
void fsk_copy_sync(fsk_fm_demod_t *fsk_to, fsk_fm_demod_t *fsk_from);
|
||||||
|
Reference in New Issue
Block a user