[xiph-cvs] cvs commit: speex/libspeex cb_search.c misc.h quant_lsp.c testenc_uwb.c
Jean-Marc Valin
jm at xiph.org
Thu Nov 6 13:35:31 PST 2003
jm 03/11/06 16:35:31
Modified: libspeex cb_search.c misc.h quant_lsp.c testenc_uwb.c
Log:
fixed-point: some ARM work
Revision Changes Path
1.101 +3 -3 speex/libspeex/cb_search.c
Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- cb_search.c 2 Nov 2003 06:59:48 -0000 1.100
+++ cb_search.c 6 Nov 2003 21:35:30 -0000 1.101
@@ -164,7 +164,7 @@
{
/*"erase" nbest list*/
for (j=0;j<N;j++)
- ndist[j]=-1;
+ ndist[j]=-2;
/*For all n-bests of previous subvector*/
for (j=0;j<N;j++)
@@ -213,7 +213,7 @@
for (m=i*subvect_size;m<(i+1)*subvect_size;m++)
err += t[m]*t[m];
/*update n-best list*/
- if (err<ndist[N-1] || ndist[N-1]<-.5)
+ if (err<ndist[N-1] || ndist[N-1]<-1)
{
/*previous target (we don't care what happened before*/
@@ -247,7 +247,7 @@
for (m=0;m<N;m++)
{
- if (err < ndist[m] || ndist[m]<-.5)
+ if (err < ndist[m] || ndist[m]<-1)
{
for (n=N-1;n>m;n--)
{
<p><p>1.42 +24 -2 speex/libspeex/misc.h
Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- misc.h 2 Nov 2003 07:44:35 -0000 1.41
+++ misc.h 6 Nov 2003 21:35:30 -0000 1.42
@@ -70,7 +70,19 @@
#define ADD32(a,b) (spx_mips++,(a)+(b))
#define SUB32(a,b) (spx_mips++,(a)-(b))
#define MULT16_16_16(a,b) (spx_mips++,((short)(a))*((short)(b)))
-#define MULT16_16(a,b) (spx_mips++,((int)(a))*((short)(b)))
+
+#ifdef ARM_ASM
+static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) {
+ int res;
+ spx_mips++;
+ asm volatile("smulbb %0,%1,%2;\n"
+ : "=&r"(res)
+ : "%r"(x),"r"(y));
+ return(res);
+}
+#else
+#define MULT16_16(a,b) (spx_mips++,((short)(a))*((short)(b)))
+#endif
#else
@@ -82,7 +94,17 @@
/* result fits in 16 bits */
#define MULT16_16_16(a,b) (((short)(a))*((short)(b)))
/* Kludge: just making sure results are on 32 bits */
-#define MULT16_16(a,b) (((int)(a))*((short)(b)))
+#ifdef ARM_ASM
+static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) {
+ int res;
+ asm volatile("smulbb %0,%1,%2;\n"
+ : "=&r"(res)
+ : "%r"(x),"r"(y));
+ return(res);
+}
+#else
+#define MULT16_16(a,b) (((short)(a))*((short)(b)))
+#endif
#endif
<p><p>1.31 +1 -1 speex/libspeex/quant_lsp.c
Index: quant_lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/quant_lsp.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- quant_lsp.c 3 Nov 2003 08:59:33 -0000 1.30
+++ quant_lsp.c 6 Nov 2003 21:35:30 -0000 1.31
@@ -56,7 +56,7 @@
static void compute_quant_weights(spx_lsp_t *qlsp, spx_word16_t *quant_weight, int order)
{
int i;
- float tmp1, tmp2;
+ spx_word16_t tmp1, tmp2;
for (i=0;i<order;i++)
{
if (i==0)
<p><p>1.4 +72 -34 speex/libspeex/testenc_uwb.c
Index: testenc_uwb.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc_uwb.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- testenc_uwb.c 8 Oct 2003 05:03:47 -0000 1.3
+++ testenc_uwb.c 6 Nov 2003 21:35:30 -0000 1.4
@@ -1,6 +1,11 @@
#include "speex.h"
#include <stdio.h>
#include <stdlib.h>
+#include "speex_callbacks.h"
+
+#ifdef COUNT_MIPS
+extern long long spx_mips;
+#endif
#define FRAME_SIZE 640
#include <math.h>
@@ -8,8 +13,11 @@
{
char *inFile, *outFile, *bitsFile;
FILE *fin, *fout, *fbits=NULL;
- short in[FRAME_SIZE];
- float input[FRAME_SIZE], bak[FRAME_SIZE], bak2[FRAME_SIZE];
+ short in_short[FRAME_SIZE];
+ short out_short[FRAME_SIZE];
+ float in_float[FRAME_SIZE];
+ float sigpow,errpow,snr, seg_snr=0;
+ int snr_frames = 0;
char cbits[200];
int nbBits;
int i;
@@ -18,34 +26,47 @@
SpeexBits bits;
int tmp;
int bitCount=0;
+ int skip_group_delay;
+ SpeexCallback callback;
+
+ sigpow = 0;
+ errpow = 0;
- for (i=0;i<FRAME_SIZE;i++)
- bak2[i]=0;
st = speex_encoder_init(&speex_uwb_mode);
dec = speex_decoder_init(&speex_uwb_mode);
-
+
+ callback.callback_id = SPEEX_INBAND_CHAR;
+ callback.func = speex_std_char_handler;
+ callback.data = stderr;
+ speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
+
+ callback.callback_id = SPEEX_INBAND_MODE_REQUEST;
+ callback.func = speex_std_mode_request_handler;
+ callback.data = st;
+ speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
+
tmp=0;
- /*speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
+ speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
tmp=0;
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
- tmp=10;
+ tmp=7;
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
- tmp=3;
+ tmp=1;
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
- tmp=3;
- speex_encoder_ctl(st, SPEEX_SET_HIGH_MODE, &tmp);
- tmp=6;
- speex_encoder_ctl(st, SPEEX_SET_LOW_MODE, &tmp);
- */
+
+ speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
+ fprintf (stderr, "frame size: %d\n", tmp);
+ skip_group_delay = tmp / 2;
+
if (argc != 4 && argc != 3)
- {
+ {
fprintf (stderr, "Usage: encode [in file] [out file] [bits file]\nargc = %d", argc);
exit(1);
}
inFile = argv[1];
fin = fopen(inFile, "r");
outFile = argv[2];
- fout = fopen(outFile, "w");
+ fout = fopen(outFile, "w+");
if (argc==4)
{
bitsFile = argv[3];
@@ -54,41 +75,58 @@
speex_bits_init(&bits);
while (!feof(fin))
{
- fread(in, sizeof(short), FRAME_SIZE, fin);
+ fread(in_short, sizeof(short), FRAME_SIZE, fin);
if (feof(fin))
break;
for (i=0;i<FRAME_SIZE;i++)
- bak[i]=input[i]=in[i];
+ in_float[i]=in_short[i];
speex_bits_reset(&bits);
- speex_encode(st, in, &bits);
+
+ speex_encode(st, in_short, &bits);
nbBits = speex_bits_write(&bits, cbits, 200);
bitCount+=bits.nbBits;
- printf ("Encoding frame in %d bits\n", nbBits*8);
+
if (argc==4)
fwrite(cbits, 1, nbBits, fbits);
- {
- float enoise=0, esig=0, snr;
- for (i=0;i<FRAME_SIZE;i++)
- {
- enoise+=(bak2[i]-input[i])*(bak2[i]-input[i]);
- esig += bak2[i]*bak2[i];
- }
- snr = 10*log10((esig+1)/(enoise+1));
- printf ("real SNR = %f\n", snr);
- }
speex_bits_rewind(&bits);
-
- speex_decode(dec, &bits, in);
+ speex_decode(dec, &bits, out_short);
speex_bits_reset(&bits);
- fwrite(in, sizeof(short), FRAME_SIZE, fout);
+
+ fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
+ skip_group_delay = 0;
}
-
fprintf (stderr, "Total encoded size: %d bits\n", bitCount);
speex_encoder_destroy(st);
speex_decoder_destroy(dec);
- speex_bits_destroy(&bits);
+
+ rewind(fin);
+ rewind(fout);
+
+ while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin)
+ &&
+ FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) )
+ {
+ float s=0, e=0;
+ for (i=0;i<FRAME_SIZE;++i) {
+ s += (float)in_short[i] * in_short[i];
+ e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]);
+ }
+ seg_snr += 10*log10((s+1)/(e+1));
+ sigpow += s;
+ errpow += e;
+ snr_frames++;
+ }
fclose(fin);
fclose(fout);
+
+ snr = 10 * log10( sigpow / errpow );
+ seg_snr /= snr_frames;
+ fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr);
+
+#ifdef COUNT_MIPS
+ printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames));
+#endif
+
return 1;
}
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list