1
/* Copyright (C) 2005 Psi Systems, Inc.
2
Author: Jean-Marc Valin
3
File: testenc-TI-C64x.c
4
Encoder/Decoder Loop Main file for TI TMS320C64xx processor
5
for use with TI Code Composer (TM) DSP development tools.
6
Modified from speexlib/testenc.c
9
Redistribution and use in source and binary forms, with or without
10
modification, are permitted provided that the following conditions
13
- Redistributions of source code must retain the above copyright
14
notice, this list of conditions and the following disclaimer.
16
- Redistributions in binary form must reproduce the above copyright
17
notice, this list of conditions and the following disclaimer in the
18
documentation and/or other materials provided with the distribution.
20
- Neither the name of the Xiph.org Foundation nor the names of its
21
contributors may be used to endorse or promote products derived from
22
this software without specific prior written permission.
24
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
28
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
#include <speex/speex.h>
44
#include <speex/speex_callbacks.h>
47
extern long long spx_mips;
51
#pragma DATA_SECTION(spxHeap, ".myheap");
52
static char spxHeap[SPEEX_PERSIST_STACK_SIZE];
54
#pragma DATA_SECTION(spxScratch, ".myheap");
55
static char spxScratch[SPEEX_SCRATCH_STACK_SIZE];
57
char *spxGlobalHeapPtr, *spxGlobalHeapEnd;
58
char *spxGlobalScratchPtr, *spxGlobalScratchEnd;
59
#endif /* MANUAL_ALLOC */
64
char *outFile, *bitsFile;
65
FILE *fout, *fbits=NULL;
74
short out_short[FRAME_SIZE];
76
short in_short[FRAME_SIZE];
77
float sigpow,errpow,snr, seg_snr=0;
89
SpeexCallback callback;
97
spxGlobalHeapPtr = spxHeap;
98
spxGlobalHeapEnd = spxHeap + sizeof(spxHeap);
100
spxGlobalScratchPtr = spxScratch;
101
spxGlobalScratchEnd = spxScratch + sizeof(spxScratch);
103
st = speex_encoder_init(&speex_nb_mode);
105
spxGlobalScratchPtr = spxScratch; /* Reuse scratch for decoder */
107
dec = speex_decoder_init(&speex_nb_mode);
109
callback.callback_id = SPEEX_INBAND_CHAR;
110
callback.func = speex_std_char_handler;
111
callback.data = stderr;
112
speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
114
callback.callback_id = SPEEX_INBAND_MODE_REQUEST;
115
callback.func = speex_std_mode_request_handler;
117
speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
120
speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
122
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
124
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
126
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
128
speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
129
fprintf (stderr, "frame size: %d\n", tmp);
130
skip_group_delay = tmp / 2;
133
bitsFile = "e:\\speextrunktest\\samples\\malebitsin54.dat";
134
fbits = fopen(bitsFile, "rb");
136
bitsFile = "e:\\speextrunktest\\samples\\malebits.dat";
137
fbits = fopen(bitsFile, "wb");
139
inFile = "e:\\speextrunktest\\samples\\male.snd";
140
fin = fopen(inFile, "rb");
141
outFile = "e:\\speextrunktest\\samples\\maleout.snd";
142
fout = fopen(outFile, "wb+");
144
dbgoutFile = "e:\\speextrunktest\\samples\\maledbgout.snd";
145
fdbgout = fopen(dbgoutFile, "wb+");
148
speex_bits_init(&bits);
152
fread(in_short, sizeof(short), FRAME_SIZE, fin);
154
fwrite(in_short, sizeof(short), FRAME_SIZE, fdbgout);
158
speex_bits_reset(&bits);
160
speex_encode_int(st, in_short, &bits);
161
nbBits = speex_bits_write(&bits, cbits, 200);
162
bitCount+=bits.nbBits;
164
fwrite(cbits, 1, nbBits, fbits);
165
speex_bits_rewind(&bits);
167
#else /* DECODE_ONLY */
170
fread(cbits, 1, 20, fbits);
175
speex_bits_read_from(&bits, cbits, 20);
179
speex_decode_int(dec, &bits, out_short);
180
speex_bits_reset(&bits);
182
fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
183
skip_group_delay = 0;
185
fprintf (stderr, "Bits so far: %d \n", bitCount);
188
fprintf (stderr, "Total encoded size: %d bits\n", bitCount);
189
speex_encoder_destroy(st);
190
speex_decoder_destroy(dec);
196
while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin)
198
FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) )
201
for (i=0;i<FRAME_SIZE;++i) {
202
s += (float)in_short[i] * in_short[i];
203
e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]);
205
seg_snr += 10*log10((s+160)/(e+160));
216
snr = 10 * log10( sigpow / errpow );
217
seg_snr /= snr_frames;
218
fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr);
221
printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames));