diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/libspeex/testdenoise.c | 44 | ||||
-rw-r--r-- | apps/codecs/libspeex/testecho.c | 53 | ||||
-rw-r--r-- | apps/codecs/libspeex/testenc.c | 142 | ||||
-rw-r--r-- | apps/codecs/libspeex/testenc_uwb.c | 137 | ||||
-rw-r--r-- | apps/codecs/libspeex/testenc_wb.c | 143 | ||||
-rw-r--r-- | apps/codecs/libspeex/testresample.c | 86 |
6 files changed, 0 insertions, 605 deletions
diff --git a/apps/codecs/libspeex/testdenoise.c b/apps/codecs/libspeex/testdenoise.c deleted file mode 100644 index 42644cb011..0000000000 --- a/apps/codecs/libspeex/testdenoise.c +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <speex/speex_preprocess.h> | ||
6 | #include <stdio.h> | ||
7 | |||
8 | #define NN 160 | ||
9 | |||
10 | int main() | ||
11 | { | ||
12 | short in[NN]; | ||
13 | int i; | ||
14 | SpeexPreprocessState *st; | ||
15 | int count=0; | ||
16 | float f; | ||
17 | |||
18 | st = speex_preprocess_state_init(NN, 8000); | ||
19 | i=1; | ||
20 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &i); | ||
21 | i=0; | ||
22 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &i); | ||
23 | f=8000; | ||
24 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &f); | ||
25 | i=0; | ||
26 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB, &i); | ||
27 | f=.0; | ||
28 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f); | ||
29 | f=.0; | ||
30 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f); | ||
31 | while (1) | ||
32 | { | ||
33 | int vad; | ||
34 | fread(in, sizeof(short), NN, stdin); | ||
35 | if (feof(stdin)) | ||
36 | break; | ||
37 | vad = speex_preprocess_run(st, in); | ||
38 | /*fprintf (stderr, "%d\n", vad);*/ | ||
39 | fwrite(in, sizeof(short), NN, stdout); | ||
40 | count++; | ||
41 | } | ||
42 | speex_preprocess_state_destroy(st); | ||
43 | return 0; | ||
44 | } | ||
diff --git a/apps/codecs/libspeex/testecho.c b/apps/codecs/libspeex/testecho.c deleted file mode 100644 index 7c32c8f60e..0000000000 --- a/apps/codecs/libspeex/testecho.c +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <sys/stat.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <unistd.h> | ||
11 | #include "speex/speex_echo.h" | ||
12 | #include "speex/speex_preprocess.h" | ||
13 | |||
14 | |||
15 | #define NN 128 | ||
16 | #define TAIL 1024 | ||
17 | |||
18 | int main(int argc, char **argv) | ||
19 | { | ||
20 | int echo_fd, ref_fd, e_fd; | ||
21 | short echo_buf[NN], ref_buf[NN], e_buf[NN]; | ||
22 | SpeexEchoState *st; | ||
23 | SpeexPreprocessState *den; | ||
24 | |||
25 | if (argc != 4) | ||
26 | { | ||
27 | fprintf (stderr, "testecho mic_signal.sw speaker_signal.sw output.sw\n"); | ||
28 | exit(1); | ||
29 | } | ||
30 | echo_fd = open (argv[2], O_RDONLY); | ||
31 | ref_fd = open (argv[1], O_RDONLY); | ||
32 | e_fd = open (argv[3], O_WRONLY | O_CREAT | O_TRUNC, 0644); | ||
33 | |||
34 | st = speex_echo_state_init(NN, TAIL); | ||
35 | den = speex_preprocess_state_init(NN, 8000); | ||
36 | int tmp = 8000; | ||
37 | speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &tmp); | ||
38 | speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st); | ||
39 | |||
40 | while (read(ref_fd, ref_buf, NN*2)) | ||
41 | { | ||
42 | read(echo_fd, echo_buf, NN*2); | ||
43 | speex_echo_cancellation(st, ref_buf, echo_buf, e_buf); | ||
44 | speex_preprocess_run(den, e_buf); | ||
45 | write(e_fd, e_buf, NN*2); | ||
46 | } | ||
47 | speex_echo_state_destroy(st); | ||
48 | speex_preprocess_state_destroy(den); | ||
49 | close(e_fd); | ||
50 | close(echo_fd); | ||
51 | close(ref_fd); | ||
52 | return 0; | ||
53 | } | ||
diff --git a/apps/codecs/libspeex/testenc.c b/apps/codecs/libspeex/testenc.c deleted file mode 100644 index eabd02cc76..0000000000 --- a/apps/codecs/libspeex/testenc.c +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <speex/speex.h> | ||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <speex/speex_callbacks.h> | ||
9 | |||
10 | #ifdef FIXED_DEBUG | ||
11 | extern long long spx_mips; | ||
12 | #endif | ||
13 | |||
14 | #define FRAME_SIZE 160 | ||
15 | #include <math.h> | ||
16 | int main(int argc, char **argv) | ||
17 | { | ||
18 | char *inFile, *outFile, *bitsFile; | ||
19 | FILE *fin, *fout, *fbits=NULL; | ||
20 | short in_short[FRAME_SIZE]; | ||
21 | short out_short[FRAME_SIZE]; | ||
22 | float sigpow,errpow,snr, seg_snr=0; | ||
23 | int snr_frames = 0; | ||
24 | char cbits[200]; | ||
25 | int nbBits; | ||
26 | int i; | ||
27 | void *st; | ||
28 | void *dec; | ||
29 | SpeexBits bits; | ||
30 | spx_int32_t tmp; | ||
31 | int bitCount=0; | ||
32 | spx_int32_t skip_group_delay; | ||
33 | SpeexCallback callback; | ||
34 | |||
35 | sigpow = 0; | ||
36 | errpow = 0; | ||
37 | |||
38 | st = speex_encoder_init(&speex_nb_mode); | ||
39 | dec = speex_decoder_init(&speex_nb_mode); | ||
40 | |||
41 | /* BEGIN: You probably don't need the following in a real application */ | ||
42 | callback.callback_id = SPEEX_INBAND_CHAR; | ||
43 | callback.func = speex_std_char_handler; | ||
44 | callback.data = stderr; | ||
45 | speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); | ||
46 | |||
47 | callback.callback_id = SPEEX_INBAND_MODE_REQUEST; | ||
48 | callback.func = speex_std_mode_request_handler; | ||
49 | callback.data = st; | ||
50 | speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); | ||
51 | /* END of unnecessary stuff */ | ||
52 | |||
53 | tmp=1; | ||
54 | speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp); | ||
55 | tmp=0; | ||
56 | speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp); | ||
57 | tmp=8; | ||
58 | speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp); | ||
59 | tmp=1; | ||
60 | speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp); | ||
61 | |||
62 | /* Turn this off if you want to measure SNR (on by default) */ | ||
63 | tmp=1; | ||
64 | speex_encoder_ctl(st, SPEEX_SET_HIGHPASS, &tmp); | ||
65 | speex_decoder_ctl(dec, SPEEX_SET_HIGHPASS, &tmp); | ||
66 | |||
67 | speex_encoder_ctl(st, SPEEX_GET_LOOKAHEAD, &skip_group_delay); | ||
68 | speex_decoder_ctl(dec, SPEEX_GET_LOOKAHEAD, &tmp); | ||
69 | skip_group_delay += tmp; | ||
70 | |||
71 | if (argc != 4 && argc != 3) | ||
72 | { | ||
73 | fprintf (stderr, "Usage: encode [in file] [out file] [bits file]\nargc = %d", argc); | ||
74 | exit(1); | ||
75 | } | ||
76 | inFile = argv[1]; | ||
77 | fin = fopen(inFile, "r"); | ||
78 | outFile = argv[2]; | ||
79 | fout = fopen(outFile, "w+"); | ||
80 | if (argc==4) | ||
81 | { | ||
82 | bitsFile = argv[3]; | ||
83 | fbits = fopen(bitsFile, "w"); | ||
84 | } | ||
85 | speex_bits_init(&bits); | ||
86 | while (!feof(fin)) | ||
87 | { | ||
88 | fread(in_short, sizeof(short), FRAME_SIZE, fin); | ||
89 | if (feof(fin)) | ||
90 | break; | ||
91 | speex_bits_reset(&bits); | ||
92 | |||
93 | speex_encode_int(st, in_short, &bits); | ||
94 | nbBits = speex_bits_write(&bits, cbits, 200); | ||
95 | bitCount+=bits.nbBits; | ||
96 | |||
97 | if (argc==4) | ||
98 | fwrite(cbits, 1, nbBits, fbits); | ||
99 | speex_bits_rewind(&bits); | ||
100 | |||
101 | speex_decode_int(dec, &bits, out_short); | ||
102 | speex_bits_reset(&bits); | ||
103 | |||
104 | fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout); | ||
105 | skip_group_delay = 0; | ||
106 | } | ||
107 | fprintf (stderr, "Total encoded size: %d bits\n", bitCount); | ||
108 | speex_encoder_destroy(st); | ||
109 | speex_decoder_destroy(dec); | ||
110 | speex_bits_destroy(&bits); | ||
111 | |||
112 | /* This code just computes SNR, so you don't need it either */ | ||
113 | rewind(fin); | ||
114 | rewind(fout); | ||
115 | |||
116 | while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) | ||
117 | && | ||
118 | FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) | ||
119 | { | ||
120 | float s=0, e=0; | ||
121 | for (i=0;i<FRAME_SIZE;++i) { | ||
122 | s += (float)in_short[i] * in_short[i]; | ||
123 | e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]); | ||
124 | } | ||
125 | seg_snr += 10*log10((s+160)/(e+160)); | ||
126 | sigpow += s; | ||
127 | errpow += e; | ||
128 | snr_frames++; | ||
129 | } | ||
130 | fclose(fin); | ||
131 | fclose(fout); | ||
132 | |||
133 | snr = 10 * log10( sigpow / errpow ); | ||
134 | seg_snr /= snr_frames; | ||
135 | fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr); | ||
136 | |||
137 | #ifdef FIXED_DEBUG | ||
138 | printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames)); | ||
139 | #endif | ||
140 | |||
141 | return 0; | ||
142 | } | ||
diff --git a/apps/codecs/libspeex/testenc_uwb.c b/apps/codecs/libspeex/testenc_uwb.c deleted file mode 100644 index e9bf18a667..0000000000 --- a/apps/codecs/libspeex/testenc_uwb.c +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <speex/speex.h> | ||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <speex/speex_callbacks.h> | ||
9 | |||
10 | #ifdef FIXED_DEBUG | ||
11 | extern long long spx_mips; | ||
12 | #endif | ||
13 | |||
14 | #define FRAME_SIZE 640 | ||
15 | #include <math.h> | ||
16 | int main(int argc, char **argv) | ||
17 | { | ||
18 | char *inFile, *outFile, *bitsFile; | ||
19 | FILE *fin, *fout, *fbits=NULL; | ||
20 | short in_short[FRAME_SIZE]; | ||
21 | short out_short[FRAME_SIZE]; | ||
22 | float in_float[FRAME_SIZE]; | ||
23 | float sigpow,errpow,snr, seg_snr=0; | ||
24 | int snr_frames = 0; | ||
25 | char cbits[200]; | ||
26 | int nbBits; | ||
27 | int i; | ||
28 | void *st; | ||
29 | void *dec; | ||
30 | SpeexBits bits; | ||
31 | spx_int32_t tmp; | ||
32 | int bitCount=0; | ||
33 | spx_int32_t skip_group_delay; | ||
34 | SpeexCallback callback; | ||
35 | |||
36 | sigpow = 0; | ||
37 | errpow = 0; | ||
38 | |||
39 | st = speex_encoder_init(&speex_uwb_mode); | ||
40 | dec = speex_decoder_init(&speex_uwb_mode); | ||
41 | |||
42 | callback.callback_id = SPEEX_INBAND_CHAR; | ||
43 | callback.func = speex_std_char_handler; | ||
44 | callback.data = stderr; | ||
45 | speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); | ||
46 | |||
47 | callback.callback_id = SPEEX_INBAND_MODE_REQUEST; | ||
48 | callback.func = speex_std_mode_request_handler; | ||
49 | callback.data = st; | ||
50 | speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); | ||
51 | |||
52 | tmp=0; | ||
53 | speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp); | ||
54 | tmp=0; | ||
55 | speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp); | ||
56 | tmp=7; | ||
57 | speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp); | ||
58 | tmp=1; | ||
59 | speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp); | ||
60 | |||
61 | speex_encoder_ctl(st, SPEEX_GET_LOOKAHEAD, &skip_group_delay); | ||
62 | speex_decoder_ctl(dec, SPEEX_GET_LOOKAHEAD, &tmp); | ||
63 | skip_group_delay += tmp; | ||
64 | |||
65 | |||
66 | if (argc != 4 && argc != 3) | ||
67 | { | ||
68 | fprintf (stderr, "Usage: encode [in file] [out file] [bits file]\nargc = %d", argc); | ||
69 | exit(1); | ||
70 | } | ||
71 | inFile = argv[1]; | ||
72 | fin = fopen(inFile, "r"); | ||
73 | outFile = argv[2]; | ||
74 | fout = fopen(outFile, "w+"); | ||
75 | if (argc==4) | ||
76 | { | ||
77 | bitsFile = argv[3]; | ||
78 | fbits = fopen(bitsFile, "w"); | ||
79 | } | ||
80 | speex_bits_init(&bits); | ||
81 | while (!feof(fin)) | ||
82 | { | ||
83 | fread(in_short, sizeof(short), FRAME_SIZE, fin); | ||
84 | if (feof(fin)) | ||
85 | break; | ||
86 | for (i=0;i<FRAME_SIZE;i++) | ||
87 | in_float[i]=in_short[i]; | ||
88 | speex_bits_reset(&bits); | ||
89 | |||
90 | speex_encode_int(st, in_short, &bits); | ||
91 | nbBits = speex_bits_write(&bits, cbits, 200); | ||
92 | bitCount+=bits.nbBits; | ||
93 | |||
94 | if (argc==4) | ||
95 | fwrite(cbits, 1, nbBits, fbits); | ||
96 | speex_bits_rewind(&bits); | ||
97 | |||
98 | speex_decode_int(dec, &bits, out_short); | ||
99 | speex_bits_reset(&bits); | ||
100 | |||
101 | fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout); | ||
102 | skip_group_delay = 0; | ||
103 | } | ||
104 | fprintf (stderr, "Total encoded size: %d bits\n", bitCount); | ||
105 | speex_encoder_destroy(st); | ||
106 | speex_decoder_destroy(dec); | ||
107 | |||
108 | rewind(fin); | ||
109 | rewind(fout); | ||
110 | |||
111 | while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) | ||
112 | && | ||
113 | FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) | ||
114 | { | ||
115 | float s=0, e=0; | ||
116 | for (i=0;i<FRAME_SIZE;++i) { | ||
117 | s += (float)in_short[i] * in_short[i]; | ||
118 | e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]); | ||
119 | } | ||
120 | seg_snr += 10*log10((s+1)/(e+1)); | ||
121 | sigpow += s; | ||
122 | errpow += e; | ||
123 | snr_frames++; | ||
124 | } | ||
125 | fclose(fin); | ||
126 | fclose(fout); | ||
127 | |||
128 | snr = 10 * log10( sigpow / errpow ); | ||
129 | seg_snr /= snr_frames; | ||
130 | fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr); | ||
131 | |||
132 | #ifdef FIXED_DEBUG | ||
133 | printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames)); | ||
134 | #endif | ||
135 | |||
136 | return 1; | ||
137 | } | ||
diff --git a/apps/codecs/libspeex/testenc_wb.c b/apps/codecs/libspeex/testenc_wb.c deleted file mode 100644 index 8e515cb13c..0000000000 --- a/apps/codecs/libspeex/testenc_wb.c +++ /dev/null | |||
@@ -1,143 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <speex/speex.h> | ||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <speex/speex_callbacks.h> | ||
9 | |||
10 | #ifdef FIXED_DEBUG | ||
11 | extern long long spx_mips; | ||
12 | #endif | ||
13 | |||
14 | #define FRAME_SIZE 320 | ||
15 | #include <math.h> | ||
16 | int main(int argc, char **argv) | ||
17 | { | ||
18 | char *inFile, *outFile, *bitsFile; | ||
19 | FILE *fin, *fout, *fbits=NULL; | ||
20 | short in_short[FRAME_SIZE]; | ||
21 | short out_short[FRAME_SIZE]; | ||
22 | float in_float[FRAME_SIZE]; | ||
23 | float sigpow,errpow,snr, seg_snr=0; | ||
24 | int snr_frames = 0; | ||
25 | char cbits[200]; | ||
26 | int nbBits; | ||
27 | int i; | ||
28 | void *st; | ||
29 | void *dec; | ||
30 | SpeexBits bits; | ||
31 | spx_int32_t tmp; | ||
32 | int bitCount=0; | ||
33 | spx_int32_t skip_group_delay; | ||
34 | SpeexCallback callback; | ||
35 | |||
36 | sigpow = 0; | ||
37 | errpow = 0; | ||
38 | |||
39 | st = speex_encoder_init(&speex_wb_mode); | ||
40 | dec = speex_decoder_init(&speex_wb_mode); | ||
41 | |||
42 | callback.callback_id = SPEEX_INBAND_CHAR; | ||
43 | callback.func = speex_std_char_handler; | ||
44 | callback.data = stderr; | ||
45 | speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); | ||
46 | |||
47 | callback.callback_id = SPEEX_INBAND_MODE_REQUEST; | ||
48 | callback.func = speex_std_mode_request_handler; | ||
49 | callback.data = st; | ||
50 | speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); | ||
51 | |||
52 | tmp=1; | ||
53 | speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp); | ||
54 | tmp=0; | ||
55 | speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp); | ||
56 | tmp=8; | ||
57 | speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp); | ||
58 | tmp=3; | ||
59 | speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp); | ||
60 | /*tmp=3; | ||
61 | speex_encoder_ctl(st, SPEEX_SET_HIGH_MODE, &tmp); | ||
62 | tmp=6; | ||
63 | speex_encoder_ctl(st, SPEEX_SET_LOW_MODE, &tmp); | ||
64 | */ | ||
65 | |||
66 | speex_encoder_ctl(st, SPEEX_GET_LOOKAHEAD, &skip_group_delay); | ||
67 | speex_decoder_ctl(dec, SPEEX_GET_LOOKAHEAD, &tmp); | ||
68 | skip_group_delay += tmp; | ||
69 | |||
70 | |||
71 | if (argc != 4 && argc != 3) | ||
72 | { | ||
73 | fprintf (stderr, "Usage: encode [in file] [out file] [bits file]\nargc = %d", argc); | ||
74 | exit(1); | ||
75 | } | ||
76 | inFile = argv[1]; | ||
77 | fin = fopen(inFile, "r"); | ||
78 | outFile = argv[2]; | ||
79 | fout = fopen(outFile, "w+"); | ||
80 | if (argc==4) | ||
81 | { | ||
82 | bitsFile = argv[3]; | ||
83 | fbits = fopen(bitsFile, "w"); | ||
84 | } | ||
85 | speex_bits_init(&bits); | ||
86 | while (!feof(fin)) | ||
87 | { | ||
88 | fread(in_short, sizeof(short), FRAME_SIZE, fin); | ||
89 | if (feof(fin)) | ||
90 | break; | ||
91 | for (i=0;i<FRAME_SIZE;i++) | ||
92 | in_float[i]=in_short[i]; | ||
93 | speex_bits_reset(&bits); | ||
94 | |||
95 | speex_encode_int(st, in_short, &bits); | ||
96 | nbBits = speex_bits_write(&bits, cbits, 200); | ||
97 | bitCount+=bits.nbBits; | ||
98 | |||
99 | if (argc==4) | ||
100 | fwrite(cbits, 1, nbBits, fbits); | ||
101 | speex_bits_rewind(&bits); | ||
102 | |||
103 | speex_decode_int(dec, &bits, out_short); | ||
104 | speex_bits_reset(&bits); | ||
105 | |||
106 | fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout); | ||
107 | skip_group_delay = 0; | ||
108 | } | ||
109 | fprintf (stderr, "Total encoded size: %d bits\n", bitCount); | ||
110 | speex_encoder_destroy(st); | ||
111 | speex_decoder_destroy(dec); | ||
112 | speex_bits_destroy(&bits); | ||
113 | |||
114 | rewind(fin); | ||
115 | rewind(fout); | ||
116 | |||
117 | while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) | ||
118 | && | ||
119 | FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) | ||
120 | { | ||
121 | float s=0, e=0; | ||
122 | for (i=0;i<FRAME_SIZE;++i) { | ||
123 | s += (float)in_short[i] * in_short[i]; | ||
124 | e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]); | ||
125 | } | ||
126 | seg_snr += 10*log10((s+160)/(e+160)); | ||
127 | sigpow += s; | ||
128 | errpow += e; | ||
129 | snr_frames++; | ||
130 | } | ||
131 | fclose(fin); | ||
132 | fclose(fout); | ||
133 | |||
134 | snr = 10 * log10( sigpow / errpow ); | ||
135 | seg_snr /= snr_frames; | ||
136 | fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr); | ||
137 | |||
138 | #ifdef FIXED_DEBUG | ||
139 | printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames)); | ||
140 | #endif | ||
141 | |||
142 | return 1; | ||
143 | } | ||
diff --git a/apps/codecs/libspeex/testresample.c b/apps/codecs/libspeex/testresample.c deleted file mode 100644 index 71392cc011..0000000000 --- a/apps/codecs/libspeex/testresample.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* Copyright (C) 2007 Jean-Marc Valin | ||
2 | |||
3 | File: testresample.c | ||
4 | Testing the resampling code | ||
5 | |||
6 | Redistribution and use in source and binary forms, with or without | ||
7 | modification, are permitted provided that the following conditions are | ||
8 | met: | ||
9 | |||
10 | 1. Redistributions of source code must retain the above copyright notice, | ||
11 | this list of conditions and the following disclaimer. | ||
12 | |||
13 | 2. Redistributions in binary form must reproduce the above copyright | ||
14 | notice, this list of conditions and the following disclaimer in the | ||
15 | documentation and/or other materials provided with the distribution. | ||
16 | |||
17 | 3. The name of the author may not be used to endorse or promote products | ||
18 | derived from this software without specific prior written permission. | ||
19 | |||
20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
24 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #ifdef HAVE_CONFIG_H | ||
34 | #include "config.h" | ||
35 | #endif | ||
36 | |||
37 | #include <stdio.h> | ||
38 | #include "speex/speex_resampler.h" | ||
39 | #include <math.h> | ||
40 | #include <stdlib.h> | ||
41 | |||
42 | #define NN 256 | ||
43 | |||
44 | int main() | ||
45 | { | ||
46 | spx_uint32_t i; | ||
47 | short *in; | ||
48 | short *out; | ||
49 | float *fin, *fout; | ||
50 | int count = 0; | ||
51 | SpeexResamplerState *st = speex_resampler_init(1, 8000, 12000, 10, NULL); | ||
52 | speex_resampler_set_rate(st, 96000, 44100); | ||
53 | speex_resampler_skip_zeros(st); | ||
54 | |||
55 | in = malloc(NN*sizeof(short)); | ||
56 | out = malloc(2*NN*sizeof(short)); | ||
57 | fin = malloc(NN*sizeof(float)); | ||
58 | fout = malloc(2*NN*sizeof(float)); | ||
59 | while (1) | ||
60 | { | ||
61 | spx_uint32_t in_len; | ||
62 | spx_uint32_t out_len; | ||
63 | fread(in, sizeof(short), NN, stdin); | ||
64 | if (feof(stdin)) | ||
65 | break; | ||
66 | for (i=0;i<NN;i++) | ||
67 | fin[i]=in[i]; | ||
68 | in_len = NN; | ||
69 | out_len = 2*NN; | ||
70 | /*if (count==2) | ||
71 | speex_resampler_set_quality(st, 10);*/ | ||
72 | speex_resampler_process_float(st, 0, fin, &in_len, fout, &out_len); | ||
73 | for (i=0;i<out_len;i++) | ||
74 | out[i]=floor(.5+fout[i]); | ||
75 | /*speex_warning_int("writing", out_len);*/ | ||
76 | fwrite(out, sizeof(short), out_len, stdout); | ||
77 | count++; | ||
78 | } | ||
79 | speex_resampler_destroy(st); | ||
80 | free(in); | ||
81 | free(out); | ||
82 | free(fin); | ||
83 | free(fout); | ||
84 | return 0; | ||
85 | } | ||
86 | |||