1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#!/bin/sh
BUILDDIR=build_stripped
DESTDIR=codec2lite
LIBSRC="codebook.c codebookd.c codebookge.c codebookjvm.c codebooknewamp1.c codebooknewamp1_energy.c codec2.c codec2_fft.c interp.c kiss_fft.c kiss_fftr.c lpc.c lsp.c mbest.c newamp1.c newamp2.c nlp.c pack.c phase.c postfilter.c quantise.c sine.c"
LIBGENSRC="codebooklspmelvq.c codebookmel.c codebooknewamp2.c codebooknewamp2_energy.c"
LIBINC="_kiss_fft_guts.h comp_prim.h lpc.h os.h bpf.h lsp.h phase.h bpfb.h defines.h machdep.h postfilter.h mbest.h quantise.h codec2_fft.h interp.h newamp1.h sine.h codec2_internal.h kiss_fft.h newamp2.h comp.h kiss_fftr.h nlp.h"
LIBGENINC="version.h"
EMPTYINC="c2wideband.h dump.h"
rm -rf "${BUILDDIR}" "${DESTDIR}"
mkdir "${BUILDDIR}" "${DESTDIR}"
# copy LICENSE
cp COPYING "${DESTDIR}"/
# copy static sources
for file in ${LIBSRC} ${LIBINC}; do
cp src/"${file}" "${DESTDIR}"/
done
# fixup one include
sed s:\<codec2/version.h\>:\"version.h\": src/codec2.h > "${DESTDIR}"/codec2.h
cat > "${DESTDIR}"/debug_alloc.h <<'EOF'
#define FREE free
#define MALLOC malloc
EOF
for file in ${EMPTYINC}; do
touch "${DESTDIR}"/"${file}"
done
cd ${BUILDDIR}
cmake ..
make tnewamp1
# copy generated files
for file in ${LIBGENSRC}; do
cp src/"${file}" ../"${DESTDIR}"/
done
for file in ${LIBGENINC}; do
cp codec2/"${file}" ../"${DESTDIR}"/
done
cd ..
rm -r "${BUILDDIR}"
cat > "${DESTDIR}"/Makefile <<'EOF'
CFLAGS = -Wall -Wno-strict-overflow -std=gnu11 -fPIC -g -O2 -I. -lm
CFLAGS += -DHORUS_L2_RX -DINTERLEAVER -DRUN_TIME_TABLES -DSCRAMBLER -Dcodec2_EXPORTS
CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
LIBSRC=codebook.c codebookd.c codebookge.c codebookmel.c codebooklspmelvq.c codebookjvm.c \
codebooknewamp1.c codebooknewamp1_energy.c codebooknewamp2.c codebooknewamp2_energy.c \
codec2.c codec2_fft.c interp.c kiss_fft.c kiss_fftr.c lpc.c lsp.c mbest.c \
newamp1.c newamp2.c nlp.c pack.c phase.c postfilter.c quantise.c sine.c
all: main
main: main.c $(LIBSRC)
clang $(CFLAGS) -o $@ $^
.PHONY: clean
clean:
rm -f main
EOF
cat > "${DESTDIR}"/main.c <<'EOF'
#include <time.h>
#include <stdio.h>
#include "codec2.h"
int main() {
struct timespec tstart={0,0}, tend={0,0};
short input[976692];
FILE * recoded = fopen("count-recoded.raw", "w+");
FILE * f = fopen("count.raw", "r");
void * codec2 = codec2_create(CODEC2_MODE_700C);
int nsam = codec2_samples_per_frame(codec2);
int nbit = codec2_bits_per_frame(codec2);
int off = 0;
unsigned char bits[128];
fread(input, 976692, 1, f);
fclose(f);
clock_gettime(CLOCK_MONOTONIC, &tstart);
while (off < 976692 / 2) {
codec2_encode(codec2, bits, input + off);
codec2_decode(codec2, input + off, bits);
off += 320;
}
clock_gettime(CLOCK_MONOTONIC, &tend);
printf("%lf\n", ((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec));
fwrite(input, 976692, 1, recoded);
codec2_destroy(codec2);
}
EOF
cat > ${DESTDIR}/README <<'EOF'
This project is meant to generate a subset of the amazing codec2 library containing only the actual speech codec and having no further dependencies than a C99 compiler.
The generate a stripped down version of codec2 that does not need CMake etc, just copy the stripdown.sh file to your codec2 directory and run it. This will generate the directory you see here.
Codec 2 is an open source (LGPL 2.1) low bit rate speech codec:
http://rowetel.com/codec2.html
EOF
|