Skip to content

Commit 535e437

Browse files
committed
Reverts all changes past 2ab504b.
Individual optimizations will be cherry-picked and included in subsequent PRs.
1 parent 30bc980 commit 535e437

File tree

14 files changed

+46
-280
lines changed

14 files changed

+46
-280
lines changed

src/codec2.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,11 +2088,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[])
20882088
for(i=0; i<n_samp; i++)
20892089
c2->Sn[i+m_pitch-n_samp] = speech[i];
20902090

2091-
#if defined(STM32F40_41xxx)
20922091
dft_speech(&c2->c2const, c2->fft_fwd_cfg, Sw, c2->Sn, c2->w);
2093-
#else
2094-
dft_speech(&c2->c2const, c2->fftr_fwd_cfg, Sw, c2->Sn, c2->w);
2095-
#endif // STM32F40_41xxx
20962092

20972093
/* Estimate pitch */
20982094
nlp(c2->nlp, c2->Sn, n_samp, &pitch, Sw, c2->W, &c2->prev_f0_enc);

src/filter.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#include <math.h>
2121
#include <complex.h>
2222

23-
#ifdef FDV_ARM_MATH
24-
#include "arm_math.h"
25-
#endif // FDV_ARM_MATH
26-
2723
#include "filter.h"
2824
#include "filter_coef.h"
2925
#include "debug_alloc.h"
@@ -258,28 +254,6 @@ void quisk_cfTune(struct quisk_cfFilter * filter, float freq) {
258254
\*---------------------------------------------------------------------------*/
259255

260256
void quisk_ccfFilter(complex float * inSamples, complex float * outSamples, int count, struct quisk_cfFilter * filter) {
261-
#if defined(FDV_ARM_MATH)
262-
complex float ptSample[filter->nTaps + count - 1];
263-
complex float *ptSamplePtr = &ptSample[0];
264-
complex float ptCoeff[filter->nTaps];
265-
memcpy(&ptSample, &filter->cSamples[1], (filter->nTaps - 1) * sizeof(complex float));
266-
memcpy(&ptSample[filter->nTaps - 1], inSamples, count * sizeof(complex float));
267-
268-
// Reverse coefficients since we're going to go forwards over samples.
269-
for (int i = 0, k = filter->nTaps - 1; i < filter->nTaps; i++, k--)
270-
{
271-
ptCoeff[i] = filter->cpxCoefs[k];
272-
}
273-
274-
for (int i = 0; i < count; i++, ptSamplePtr++)
275-
{
276-
complex float accum = 0;
277-
arm_cmplx_dot_prod_f32((float32_t*)ptSamplePtr, (float32_t*)&ptCoeff, filter->nTaps, (float32_t*)&accum, (float32_t*)&accum + 1);
278-
outSamples[i] = accum;
279-
}
280-
281-
memcpy((float32_t*)filter->cSamples, (float32_t*)&ptSample[count - 1 - filter->nTaps], filter->nTaps * sizeof(complex float));
282-
#else
283257
int i, k;
284258
complex float * ptSample;
285259
complex float * ptCoef;
@@ -303,6 +277,5 @@ void quisk_ccfFilter(complex float * inSamples, complex float * outSamples, int
303277
if (++filter->ptcSamp >= filter->cSamples + filter->nTaps)
304278
filter->ptcSamp = filter->cSamples;
305279
}
306-
#endif
307280
}
308281

src/fmfsk.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void fmfsk_mod(struct FMFSK *fmfsk, float fmfsk_out[],uint8_t bits_in[]){
168168
* float fsk_in[] - nin samples of modualted FMFSK from an FM radio
169169
*/
170170
void fmfsk_demod(struct FMFSK *fmfsk, uint8_t rx_bits[],float fmfsk_in[]){
171-
int i,j;
171+
int i,j,k;
172172
int Ts = fmfsk->Ts;
173173
int Fs = fmfsk->Fs;
174174
int Rs = fmfsk->Rs;
@@ -187,6 +187,9 @@ void fmfsk_demod(struct FMFSK *fmfsk, uint8_t rx_bits[],float fmfsk_in[]){
187187
int next_nin;
188188
float apeven,apodd; /* Approx. prob of even or odd stream being correct */
189189
float currv,mdiff,lastv;
190+
int neyesamp;
191+
int neyeoffset;
192+
float eye_max;
190193
uint8_t mbit;
191194
float var_signal = 0, var_noise = 0, lastFabsV;
192195

@@ -340,11 +343,6 @@ void fmfsk_demod(struct FMFSK *fmfsk, uint8_t rx_bits[],float fmfsk_in[]){
340343
fmfsk->stats->snr_est = fmfsk->snr_mean;
341344

342345
#ifndef __EMBEDDED__
343-
int neyesamp;
344-
int neyeoffset;
345-
float eye_max;
346-
int k;
347-
348346
/* Collect an eye diagram */
349347
/* Take a sample for the eye diagrams */
350348
neyesamp = fmfsk->stats->neyesamp = Ts*4;

src/fsk.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
640640
float rx_timing,norm_rx_timing,old_norm_rx_timing,d_norm_rx_timing,appm;
641641

642642
float fc_avg,fc_tx;
643-
float meanebno,stdebno;
643+
float meanebno,stdebno,eye_max;
644+
int neyesamp,neyeoffset;
644645

645646
#ifdef MODEMPROBE_ENABLE
646647
#define NMP_NAME 26
@@ -878,8 +879,6 @@ void fsk_demod_core(struct FSK *fsk, uint8_t rx_bits[], float rx_filt[], COMP fs
878879
trace. So lets output a decimated version. We use 2P
879880
as we want two symbols worth of samples in trace */
880881
#ifndef __EMBEDDED__
881-
float eye_max;
882-
int neyesamp,neyeoffset;
883882
int neyesamp_dec = ceil(((float)P*2)/MODEM_STATS_EYE_IND_MAX);
884883
neyesamp = (P*2)/neyesamp_dec;
885884
assert(neyesamp <= MODEM_STATS_EYE_IND_MAX);
@@ -958,18 +957,18 @@ void fsk_demod_sd(struct FSK *fsk, float rx_filt[], COMP fsk_in[]){
958957

959958
/* make sure stats have known values in case monitoring process reads stats before they are set */
960959
static void stats_init(struct FSK *fsk) {
960+
/* Take a sample for the eye diagrams */
961+
int i,j,m;
962+
int P = fsk->P;
963+
int M = fsk->mode;
964+
961965
/* due to oversample rate P, we have too many samples for eye
962966
trace. So lets output a decimated version */
963967

964968
/* asserts below as we found some problems over-running eye matrix */
965969

966970
/* TODO: refactor eye tracing code here and in fsk_demod */
967971
#ifndef __EMBEDDED__
968-
/* Take a sample for the eye diagrams */
969-
int i,j,m;
970-
int P = fsk->P;
971-
int M = fsk->mode;
972-
973972
int neyesamp_dec = ceil(((float)P*2)/MODEM_STATS_EYE_IND_MAX);
974973
int neyesamp = (P*2)/neyesamp_dec;
975974
assert(neyesamp <= MODEM_STATS_EYE_IND_MAX);

src/mbest.c

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ void mbest_destroy(struct MBEST *mbest) {
7575
\*---------------------------------------------------------------------------*/
7676

7777
void mbest_insert(struct MBEST *mbest, int index[], float error) {
78-
int i, found;
78+
int i, j, found;
7979
struct MBEST_LIST *list = mbest->list;
8080
int entries = mbest->entries;
8181

8282
found = 0;
8383
for(i=0; i<entries && !found; i++)
8484
if (error < list[i].error) {
8585
found = 1;
86-
memmove(&list[i+1], &list[i], sizeof(struct MBEST_LIST) * (entries - i - 1));
87-
memcpy(&list[i].index[0], &index[0], sizeof(int) * MBEST_STAGES);
86+
for(j=entries-1; j>i; j--)
87+
list[j] = list[j-1];
88+
for(j=0; j<MBEST_STAGES; j++)
89+
list[i].index[j] = index[j];
8890
list[i].error = error;
8991
}
9092
}
@@ -122,57 +124,17 @@ void mbest_search(
122124
)
123125
{
124126
float e;
125-
126-
for(int j = 0; j < m; j++) {
127-
int i;
128-
129-
e = 0.0;
130-
for(int i = 0; i < k; i++) {
131-
float diff = (*cb++) - vec[i];
132-
float diff2 = diff * diff;
133-
float w2 = w[i] * w[i];
134-
e += diff2 * w2;
135-
}
136-
137-
index[0] = j;
138-
if (e < mbest->list[mbest->entries - 1].error)
139-
mbest_insert(mbest, index, e);
140-
}
141-
}
127+
int i,j;
128+
float diff;
142129

143-
/*---------------------------------------------------------------------------*\
144-
145-
mbest_search_equalweight
146-
147-
Searches vec[] to a codebbook of vectors, and maintains a list of the mbest
148-
closest matches. Similar to mbest_search() but with w[] = 1.
149-
150-
\*---------------------------------------------------------------------------*/
151-
152-
void mbest_search_equalweight(
153-
const float *cb, /* VQ codebook to search */
154-
float vec[], /* target vector */
155-
int k, /* dimension of vector */
156-
int m, /* number on entries in codebook */
157-
struct MBEST *mbest, /* list of closest matches */
158-
int index[] /* indexes that lead us here */
159-
)
160-
{
161-
float e;
162-
163-
for(int j = 0; j < m; j++) {
164-
int i;
165-
166-
e = 0.0;
167-
for(int i = 0; i < k; i++) {
168-
float diff = (*cb++) - vec[i];
169-
float diff2 = diff * diff;
170-
e += diff2;
171-
}
172-
173-
index[0] = j;
174-
if (e < mbest->list[mbest->entries - 1].error)
175-
mbest_insert(mbest, index, e);
130+
for(j=0; j<m; j++) {
131+
e = 0.0;
132+
for(i=0; i<k; i++) {
133+
diff = cb[j*k+i]-vec[i];
134+
e += diff*w[i]*diff*w[i];
135+
}
136+
index[0] = j;
137+
mbest_insert(mbest, index, e);
176138
}
177139
}
178140

src/mbest.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct MBEST *mbest_create(int entries);
4646
void mbest_destroy(struct MBEST *mbest);
4747
void mbest_insert(struct MBEST *mbest, int index[], float error);
4848
void mbest_search(const float *cb, float vec[], float w[], int k, int m, struct MBEST *mbest, int index[]);
49-
void mbest_search_equalweight(const float *cb, float vec[], int k, int m, struct MBEST *mbest, int index[]);
5049
void mbest_search450(const float *cb, float vec[], float w[], int k,int shorterK, int m, struct MBEST *mbest, int index[]);
5150

5251
void mbest_print(char title[], struct MBEST *mbest);

src/modem_stats.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@
3333

3434
void modem_stats_open(struct MODEM_STATS *f)
3535
{
36+
int i;
37+
3638
/* zero out all the stats */
3739

3840
memset(f, 0, sizeof(struct MODEM_STATS));
3941

4042
/* init the FFT */
4143

4244
#ifndef __EMBEDDED__
43-
for(int i=0; i<2*MODEM_STATS_NSPEC; i++)
45+
for(i=0; i<2*MODEM_STATS_NSPEC; i++)
4446
f->fft_buf[i] = 0.0;
4547
f->fft_cfg = (void*)kiss_fft_alloc (2*MODEM_STATS_NSPEC, 0, NULL, NULL);
4648
assert(f->fft_cfg != NULL);

src/newamp1.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,18 @@ float rate_K_mbest_encode(int *indexes, float *x, float *xq, int ndim, int mbest
166166
const float *codebook2 = newamp1vq_cb[1].cb;
167167
struct MBEST *mbest_stage1, *mbest_stage2;
168168
float target[ndim];
169+
float w[ndim];
169170
int index[MBEST_STAGES];
170171
float mse, tmp;
171172

172173
/* codebook is compiled for a fixed K */
173174

174175
assert(ndim == newamp1vq_cb[0].k);
175176

176-
/* note: using equal weights, could be argued mel freq axis gives freq dep weighting */
177+
/* equal weights, could be argued mel freq axis gives freq dep weighting */
178+
179+
for(i=0; i<ndim; i++)
180+
w[i] = 1.0;
177181

178182
mbest_stage1 = mbest_create(mbest_entries);
179183
mbest_stage2 = mbest_create(mbest_entries);
@@ -182,15 +186,15 @@ float rate_K_mbest_encode(int *indexes, float *x, float *xq, int ndim, int mbest
182186

183187
/* Stage 1 */
184188

185-
mbest_search_equalweight(codebook1, x, ndim, newamp1vq_cb[0].m, mbest_stage1, index);
189+
mbest_search(codebook1, x, w, ndim, newamp1vq_cb[0].m, mbest_stage1, index);
186190

187191
/* Stage 2 */
188192

189193
for (j=0; j<mbest_entries; j++) {
190194
index[1] = n1 = mbest_stage1->list[j].index[0];
191195
for(i=0; i<ndim; i++)
192196
target[i] = x[i] - codebook1[ndim*n1+i];
193-
mbest_search_equalweight(codebook2, target, ndim, newamp1vq_cb[1].m, mbest_stage2, index);
197+
mbest_search(codebook2, target, w, ndim, newamp1vq_cb[1].m, mbest_stage2, index);
194198
}
195199

196200
n1 = mbest_stage2->list[0].index[1];

src/nlp.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ typedef struct {
126126
float sq[PMAX_M]; /* squared speech samples */
127127
float mem_x,mem_y; /* memory for notch filter */
128128
float mem_fir[NLP_NTAP]; /* decimation FIR filter memory */
129-
#if defined(STM32F40_41xxx)
130129
codec2_fft_cfg fft_cfg; /* kiss FFT config */
131-
#else
132-
codec2_fftr_cfg fft_cfg;
133-
#endif // defined(STM32F40_41xxx)
134130
float *Sn16k; /* Fs=16kHz input speech vector */
135131
FILE *f;
136132
} NLP;
@@ -194,11 +190,7 @@ void *nlp_create(C2CONST *c2const)
194190
for(i=0; i<NLP_NTAP; i++)
195191
nlp->mem_fir[i] = 0.0;
196192

197-
#if defined(STM32F40_41xxx)
198193
nlp->fft_cfg = codec2_fft_alloc (PE_FFT_SIZE, 0, NULL, NULL);
199-
#else
200-
nlp->fft_cfg = codec2_fftr_alloc (PE_FFT_SIZE, 0, NULL, NULL);
201-
#endif // defined(STM32F40_41xxx)
202194
assert(nlp->fft_cfg != NULL);
203195

204196
return (void*)nlp;
@@ -218,11 +210,7 @@ void nlp_destroy(void *nlp_state)
218210
assert(nlp_state != NULL);
219211
nlp = (NLP*)nlp_state;
220212

221-
#if defined(STM32F40_41xxx)
222213
codec2_fft_free(nlp->fft_cfg);
223-
#else
224-
codec2_fftr_free(nlp->fft_cfg);
225-
#endif // defined(STM32F40_41xxx)
226214
if (nlp->Fs == 16000) {
227215
free(nlp->Sn16k);
228216
}
@@ -363,35 +351,15 @@ float nlp(
363351
#ifdef DUMP
364352
dump_dec(Fw);
365353
#endif
366-
367-
#if defined(STM32F40_41xxx)
354+
368355
// FIXME: check if this can be converted to a real fft
369356
// since all imag inputs are 0
370357
codec2_fft_inplace(nlp->fft_cfg, Fw);
371358
PROFILE_SAMPLE_AND_LOG(fft, window, " fft");
372359

373360
for(i=0; i<PE_FFT_SIZE; i++)
374-
Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
375-
#else
376-
float Fw_input[PE_FFT_SIZE];
377-
for (i = 0; i < PE_FFT_SIZE; i++)
378-
{
379-
Fw_input[i] = Fw[i].real;
380-
}
381-
codec2_fftr(nlp->fft_cfg, &Fw_input[0], &Fw[0]);
382-
PROFILE_SAMPLE_AND_LOG(fft, window, " fft");
383-
384-
for(i=0; i<PE_FFT_SIZE/2; i++)
385-
{
386-
Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
387-
388-
// Set Fw[PE_FFT_SIZE - i - 1] to the same as Fw[i] due to the real FFT's symmetry
389-
// (and to avoid having to change anything else further down).
390-
Fw[PE_FFT_SIZE - i - 1].real = Fw[i].real;
391-
}
392-
393-
#endif // defined(STM32F40_41xxx)
394-
361+
Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
362+
395363
PROFILE_SAMPLE_AND_LOG(magsq, fft, " mag sq");
396364
#ifdef DUMP
397365
dump_sq(m, nlp->sq);

0 commit comments

Comments
 (0)