kopia lustrzana https://github.com/sh123/codec2_talkie
Updates
rodzic
8484dab0eb
commit
320f1dc152
|
@ -111,9 +111,8 @@ public class Hdlc implements Protocol {
|
||||||
int packetCrc = ((int)packetBytes[packetBytes.length - 2] & 0xff) | (((int)packetBytes[packetBytes.length - 1] & 0xff) << 8);
|
int packetCrc = ((int)packetBytes[packetBytes.length - 2] & 0xff) | (((int)packetBytes[packetBytes.length - 1] & 0xff) << 8);
|
||||||
//Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc);
|
//Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc);
|
||||||
if (calculatedCrc == packetCrc) {
|
if (calculatedCrc == packetCrc) {
|
||||||
Log.i(TAG, DebugTools.byteBitsToString(packetBits));
|
Log.v(TAG, DebugTools.byteBitsToString(packetBits));
|
||||||
Log.i(TAG, "RX: " + DebugTools.bytesToHex(packetBytes));
|
Log.i(TAG, "RX: " + DebugTools.bytesToHex(packetBytes));
|
||||||
Log.i(TAG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
||||||
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, contentBytes);
|
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, contentBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,6 @@ public class SoundModem implements Transport, Runnable {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// TODO, take readCnt into account, do not read if playback is active
|
|
||||||
if (_isLoopback) {
|
if (_isLoopback) {
|
||||||
synchronized (_sampleBuffer) {
|
synchronized (_sampleBuffer) {
|
||||||
if (_sampleBuffer.position() / 2 >= nin) {
|
if (_sampleBuffer.position() / 2 >= nin) {
|
||||||
|
|
|
@ -35,10 +35,6 @@
|
||||||
/* This needs square roots, may take more cpu time than it's worth */
|
/* This needs square roots, may take more cpu time than it's worth */
|
||||||
#define EST_EBNO
|
#define EST_EBNO
|
||||||
|
|
||||||
/* This is a flag to make the mod/demod allocate their memory on the stack instead of the heap */
|
|
||||||
/* At large sample rates, there's not enough stack space to run the demod */
|
|
||||||
#define DEMOD_ALLOC_STACK
|
|
||||||
|
|
||||||
/* This is a flag for the freq. estimator to use a precomputed/rt computed hann window table
|
/* This is a flag for the freq. estimator to use a precomputed/rt computed hann window table
|
||||||
On platforms with slow cosf, this will produce a substantial speedup at the cost of a small
|
On platforms with slow cosf, this will produce a substantial speedup at the cost of a small
|
||||||
amount of memory
|
amount of memory
|
||||||
|
@ -472,14 +468,8 @@ void fsk_demod_freq_est(struct FSK *fsk, COMP fsk_in[], float *freqs, int M) {
|
||||||
int freqi[M];
|
int freqi[M];
|
||||||
int st,en,f_zero;
|
int st,en,f_zero;
|
||||||
|
|
||||||
/* Array to do complex FFT from using kiss_fft */
|
|
||||||
#ifdef DEMOD_ALLOC_STACK
|
|
||||||
kiss_fft_cpx *fftin = (kiss_fft_cpx*)alloca(sizeof(kiss_fft_cpx)*Ndft);
|
|
||||||
kiss_fft_cpx *fftout = (kiss_fft_cpx*)alloca(sizeof(kiss_fft_cpx)*Ndft);
|
|
||||||
#else
|
|
||||||
kiss_fft_cpx *fftin = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*Ndft);
|
kiss_fft_cpx *fftin = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*Ndft);
|
||||||
kiss_fft_cpx *fftout = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*Ndft);
|
kiss_fft_cpx *fftout = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*Ndft);
|
||||||
#endif
|
|
||||||
|
|
||||||
st = (fsk->est_min*Ndft)/Fs + Ndft/2; if (st < 0) st = 0;
|
st = (fsk->est_min*Ndft)/Fs + Ndft/2; if (st < 0) st = 0;
|
||||||
en = (fsk->est_max*Ndft)/Fs + Ndft/2; if (en > Ndft) en = Ndft;
|
en = (fsk->est_max*Ndft)/Fs + Ndft/2; if (en > Ndft) en = Ndft;
|
||||||
|
@ -605,14 +595,13 @@ void fsk_demod_freq_est(struct FSK *fsk, COMP fsk_in[], float *freqs, int M) {
|
||||||
//fprintf(stderr, "fsk->tone_spacing: %d\n",fsk->tone_spacing);
|
//fprintf(stderr, "fsk->tone_spacing: %d\n",fsk->tone_spacing);
|
||||||
for (int m=0; m<M; m++)
|
for (int m=0; m<M; m++)
|
||||||
fsk->f2_est[m] = foff + m*fsk->tone_spacing;
|
fsk->f2_est[m] = foff + m*fsk->tone_spacing;
|
||||||
|
|
||||||
#ifdef MODEMPROBE_ENABLE
|
#ifdef MODEMPROBE_ENABLE
|
||||||
modem_probe_samp_f("t_f2_est",fsk->f2_est,M);
|
modem_probe_samp_f("t_f2_est",fsk->f2_est,M);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEMOD_ALLOC_STACK
|
|
||||||
free(fftin);
|
free(fftin);
|
||||||
free(fftout);
|
free(fftout);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* core demodulator function */
|
/* core demodulator function */
|
||||||
|
@ -777,7 +766,7 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
|
||||||
/* resample at ideal sampling instant */
|
/* resample at ideal sampling instant */
|
||||||
int st = (i+1)*P;
|
int st = (i+1)*P;
|
||||||
for( m=0; m<M; m++) {
|
for( m=0; m<M; m++) {
|
||||||
t[m] = fcmult(1-fract,f_int[m][st+ low_sample]);
|
t[m] = fcmult(1-fract,f_int[m][st+low_sample]);
|
||||||
t[m] = cadd(t[m],fcmult( fract,f_int[m][st+high_sample]));
|
t[m] = cadd(t[m],fcmult( fract,f_int[m][st+high_sample]));
|
||||||
/* Figure mag^2 of each resampled fx_int */
|
/* Figure mag^2 of each resampled fx_int */
|
||||||
tmax[m] = (t[m].real*t[m].real) + (t[m].imag*t[m].imag);
|
tmax[m] = (t[m].real*t[m].real) + (t[m].imag*t[m].imag);
|
||||||
|
@ -830,8 +819,8 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_sig_pow = rx_sig_pow/nsym;
|
fsk->rx_sig_pow = rx_sig_pow = rx_sig_pow/nsym;
|
||||||
rx_nse_pow = rx_nse_pow/nsym;
|
fsk->rx_nse_pow = rx_nse_pow = rx_nse_pow/nsym;
|
||||||
fsk->v_est = sqrt(rx_sig_pow-rx_nse_pow);
|
fsk->v_est = sqrt(rx_sig_pow-rx_nse_pow);
|
||||||
fsk->SNRest = rx_sig_pow/rx_nse_pow;
|
fsk->SNRest = rx_sig_pow/rx_nse_pow;
|
||||||
|
|
||||||
|
@ -878,7 +867,7 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
|
||||||
/* due to oversample rate P, we have too many samples for eye
|
/* due to oversample rate P, we have too many samples for eye
|
||||||
trace. So lets output a decimated version. We use 2P
|
trace. So lets output a decimated version. We use 2P
|
||||||
as we want two symbols worth of samples in trace */
|
as we want two symbols worth of samples in trace */
|
||||||
|
#ifndef __EMBEDDED__
|
||||||
int neyesamp_dec = ceil(((float)P*2)/MODEM_STATS_EYE_IND_MAX);
|
int neyesamp_dec = ceil(((float)P*2)/MODEM_STATS_EYE_IND_MAX);
|
||||||
neyesamp = (P*2)/neyesamp_dec;
|
neyesamp = (P*2)/neyesamp_dec;
|
||||||
assert(neyesamp <= MODEM_STATS_EYE_IND_MAX);
|
assert(neyesamp <= MODEM_STATS_EYE_IND_MAX);
|
||||||
|
@ -899,8 +888,9 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
|
||||||
j*neweyesamp_dec: For 2*P>MODEM_STATS_EYE_IND_MAX advance through integrated
|
j*neweyesamp_dec: For 2*P>MODEM_STATS_EYE_IND_MAX advance through integrated
|
||||||
samples newamp_dec at a time so we dont overflow rx_eye[][]
|
samples newamp_dec at a time so we dont overflow rx_eye[][]
|
||||||
*/
|
*/
|
||||||
ind = 2*P*i + neyeoffset + j*neyesamp_dec;
|
ind = 2*P*(i+1) + neyeoffset + j*neyesamp_dec;
|
||||||
assert((i*M+m) < MODEM_STATS_ET_MAX);
|
assert((i*M+m) < MODEM_STATS_ET_MAX);
|
||||||
|
assert(ind >= 0);
|
||||||
assert(ind < (nsym+1)*P);
|
assert(ind < (nsym+1)*P);
|
||||||
fsk->stats->rx_eye[i*M+m][j] = cabsolute(f_int[m][ind]);
|
fsk->stats->rx_eye[i*M+m][j] = cabsolute(f_int[m][ind]);
|
||||||
}
|
}
|
||||||
|
@ -925,7 +915,8 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
|
||||||
|
|
||||||
for(i=0; i<M; i++)
|
for(i=0; i<M; i++)
|
||||||
fsk->stats->f_est[i] = f_est[i];
|
fsk->stats->f_est[i] = f_est[i];
|
||||||
|
#endif // !__EMBEDDED__
|
||||||
|
|
||||||
/* Dump some internal samples */
|
/* Dump some internal samples */
|
||||||
modem_probe_samp_f("t_EbNodB",&(fsk->EbNodB),1);
|
modem_probe_samp_f("t_EbNodB",&(fsk->EbNodB),1);
|
||||||
modem_probe_samp_f("t_ppm",&(fsk->ppm),1);
|
modem_probe_samp_f("t_ppm",&(fsk->ppm),1);
|
||||||
|
@ -966,7 +957,7 @@ static void stats_init(struct FSK *fsk) {
|
||||||
/* asserts below as we found some problems over-running eye matrix */
|
/* asserts below as we found some problems over-running eye matrix */
|
||||||
|
|
||||||
/* TODO: refactor eye tracing code here and in fsk_demod */
|
/* TODO: refactor eye tracing code here and in fsk_demod */
|
||||||
|
#ifndef __EMBEDDED__
|
||||||
int neyesamp_dec = ceil(((float)P*2)/MODEM_STATS_EYE_IND_MAX);
|
int neyesamp_dec = ceil(((float)P*2)/MODEM_STATS_EYE_IND_MAX);
|
||||||
int neyesamp = (P*2)/neyesamp_dec;
|
int neyesamp = (P*2)/neyesamp_dec;
|
||||||
assert(neyesamp <= MODEM_STATS_EYE_IND_MAX);
|
assert(neyesamp <= MODEM_STATS_EYE_IND_MAX);
|
||||||
|
@ -983,6 +974,7 @@ static void stats_init(struct FSK *fsk) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // !__EMBEDDED__
|
||||||
|
|
||||||
fsk->stats->rx_timing = fsk->stats->snr_est = 0;
|
fsk->stats->rx_timing = fsk->stats->snr_est = 0;
|
||||||
|
|
||||||
|
@ -1016,12 +1008,13 @@ void fsk_get_demod_stats(struct FSK *fsk, struct MODEM_STATS *stats){
|
||||||
stats->snr_est = fsk->stats->snr_est; // TODO: make this SNR not Eb/No
|
stats->snr_est = fsk->stats->snr_est; // TODO: make this SNR not Eb/No
|
||||||
stats->rx_timing = fsk->stats->rx_timing;
|
stats->rx_timing = fsk->stats->rx_timing;
|
||||||
stats->foff = fsk->stats->foff;
|
stats->foff = fsk->stats->foff;
|
||||||
|
#ifndef __EMBEDDED__
|
||||||
stats->neyesamp = fsk->stats->neyesamp;
|
stats->neyesamp = fsk->stats->neyesamp;
|
||||||
stats->neyetr = fsk->stats->neyetr;
|
stats->neyetr = fsk->stats->neyetr;
|
||||||
memcpy(stats->rx_eye, fsk->stats->rx_eye, sizeof(stats->rx_eye));
|
memcpy(stats->rx_eye, fsk->stats->rx_eye, sizeof(stats->rx_eye));
|
||||||
memcpy(stats->f_est, fsk->stats->f_est, fsk->mode*sizeof(float));
|
memcpy(stats->f_est, fsk->stats->f_est, fsk->mode*sizeof(float));
|
||||||
|
#endif // !__EMBEDDED__
|
||||||
|
|
||||||
/* these fields not used for FSK so set to something sensible */
|
/* these fields not used for FSK so set to something sensible */
|
||||||
|
|
||||||
stats->sync = 0;
|
stats->sync = 0;
|
||||||
|
|
|
@ -85,6 +85,8 @@ struct FSK {
|
||||||
float ppm; /* Estimated PPM clock offset */
|
float ppm; /* Estimated PPM clock offset */
|
||||||
float SNRest; /* used for LLRs */
|
float SNRest; /* used for LLRs */
|
||||||
float v_est; /* used for LLRs */
|
float v_est; /* used for LLRs */
|
||||||
|
float rx_sig_pow;
|
||||||
|
float rx_nse_pow;
|
||||||
|
|
||||||
/* Parameters used by mod/demod and driving code */
|
/* Parameters used by mod/demod and driving code */
|
||||||
int nin; /* Number of samples to feed the next demod cycle */
|
int nin; /* Number of samples to feed the next demod cycle */
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
|
||||||
struct ContextFsk *conFsk;
|
struct ContextFsk *conFsk;
|
||||||
conFsk = (struct ContextFsk *) malloc(sizeof(struct ContextFsk));
|
conFsk = (struct ContextFsk *) malloc(sizeof(struct ContextFsk));
|
||||||
struct FSK *fsk;
|
struct FSK *fsk;
|
||||||
fsk = fsk_create_hbr(sampleFrequency, symbolRate, MODE_2FSK, sampleFrequency/symbolRate, FSK_DEFAULT_NSYM, toneFreq, toneSpacing);
|
fsk = fsk_create_hbr(sampleFrequency, symbolRate, MODE_2FSK, 10, FSK_DEFAULT_NSYM, toneFreq, toneSpacing);
|
||||||
conFsk->fsk = fsk;
|
conFsk->fsk = fsk;
|
||||||
|
|
||||||
conFsk->Nbits = fsk->Nbits;
|
conFsk->Nbits = fsk->Nbits;
|
||||||
|
|
Ładowanie…
Reference in New Issue