Skip to content

Commit 38668e4

Browse files
committed
48<->8 short resampler working again, including test
1 parent 448d9dd commit 38668e4

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ if(UNITTEST)
379379
set_tests_properties(test_fdmdv_16to8_short PROPERTIES PASS_REGULAR_EXPRESSION "PASS")
380380

381381
# 48<->8 kHz float resamplers
382+
add_test(NAME test_fdmdv_48to8_short
383+
COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/octave;
384+
${CMAKE_CURRENT_BINARY_DIR}/unittest/t48_8_short;
385+
DISPLAY=\"\" echo \"diff_fft_mag('in8.raw','out8.raw'); quit;\" | octave-cli -qf
386+
")
387+
set_tests_properties(test_fdmdv_48to8_short PROPERTIES PASS_REGULAR_EXPRESSION "PASS")
388+
389+
# 48<->8 kHz short resamplers
382390
add_test(NAME test_fdmdv_48to8
383391
COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/octave;
384392
${CMAKE_CURRENT_BINARY_DIR}/unittest/t48_8;

src/fdmdv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,9 +1922,8 @@ void fdmdv_8_to_48_short(short out48k[], short in8k[], int n)
19221922
for(j=0; j<FDMDV_OS_48; j++) {
19231923
acc = 0.0;
19241924
for(k=0,l=0; k<FDMDV_OS_TAPS_48K; k+=FDMDV_OS_48,l++)
1925-
out48k[i*FDMDV_OS_48+j] += fdmdv_os_filter48[k+j]*in8k[i-l];
1926-
out48k[i*FDMDV_OS_48+j] = acc*FDMDV_OS_48;
1927-
1925+
acc += fdmdv_os_filter48[k+j]*in8k[i-l];
1926+
out48k[i*FDMDV_OS_48+j] = acc*FDMDV_OS_48;
19281927
}
19291928
}
19301929

unittest/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ target_link_libraries(t16_8_short codec2)
9292

9393
add_executable(t48_8 t48_8.c ../src/fdmdv.c ../src/kiss_fft.c)
9494
target_link_libraries(t48_8 codec2)
95+
96+
add_executable(t48_8_short t48_8_short.c ../src/fdmdv.c ../src/kiss_fft.c)
97+
target_link_libraries(t48_8_short codec2)

unittest/t48_8_short.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
t48_8_short.c
3+
David Rowe
4+
Dec 2021
5+
*/
6+
7+
#include <assert.h>
8+
#include <math.h>
9+
#include <stdlib.h>
10+
#include <stdio.h>
11+
#include "codec2_fdmdv.h"
12+
13+
#define N8 180 /* processing buffer size at 8 kHz */
14+
#define N48 (N8*FDMDV_OS_48)
15+
#define MEM8 FDMDV_OS_TAPS_48_8K
16+
#define FRAMES 50
17+
#define TWO_PI 6.283185307
18+
#define FS 48000
19+
20+
#define SINE
21+
22+
int main() {
23+
short in8k[MEM8+N8];
24+
short out48k[N48];
25+
FILE *f48;
26+
27+
short in48k[FDMDV_OS_TAPS_48K + N48];
28+
short out8k[N48];
29+
FILE *f8, *f8in;
30+
31+
int i,f,t,t1;
32+
float freq = 800.0;
33+
34+
f48 = fopen("out48.raw", "wb");
35+
assert(f48 != NULL);
36+
f8 = fopen("out8.raw", "wb");
37+
assert(f8 != NULL);
38+
f8in = fopen("in8.raw", "wb");
39+
assert(f8in != NULL);
40+
41+
/* clear filter memories */
42+
43+
for(i=0; i<MEM8; i++)
44+
in8k[i] = 0.0;
45+
for(i=0; i<FDMDV_OS_TAPS_48K; i++)
46+
in48k[i] = 0.0;
47+
48+
t = t1 = 0;
49+
for(f=0; f<FRAMES; f++) {
50+
51+
#ifdef DC
52+
for(i=0; i<N8; i++)
53+
in8k[MEM8+i] = 16000.0;
54+
#endif
55+
#ifdef SINE
56+
for(i=0; i<N8; i++,t++)
57+
in8k[MEM8+i] = 16000.0*cos(TWO_PI*t*freq/(FS/FDMDV_OS_48));
58+
#endif
59+
fwrite(&in8k[MEM8], sizeof(short), N8, f8in);
60+
61+
/* upsample */
62+
fdmdv_8_to_48_short(out48k, &in8k[MEM8], N8);
63+
64+
/* save 48k to disk for plotting and check out */
65+
fwrite(out48k, sizeof(short), N48, f48);
66+
67+
/* add a 10 kHz spurious signal for fun, we want down sampler to
68+
knock this out */
69+
for(i=0; i<N48; i++,t1++)
70+
in48k[i+FDMDV_OS_TAPS_48K] = out48k[i] + 16000.0*cos(TWO_PI*t1*1E4/FS);
71+
72+
/* downsample */
73+
fdmdv_48_to_8_short(out8k, &in48k[FDMDV_OS_TAPS_48K], N8);
74+
75+
/* save 8k to disk for plotting and check out */
76+
fwrite(out8k, sizeof(short), N8, f8);
77+
}
78+
79+
fclose(f48);
80+
fclose(f8);
81+
fclose(f8in);
82+
return 0;
83+
84+
}

0 commit comments

Comments
 (0)