[Speex-dev] Precomputing the remaining floating point operations.
Nic Roets
speex at rational.co.za
Mon Sep 26 08:34:43 PDT 2005
I see there are still some floating point operations left in the codec
init(ialization) code. Changing that code to fixed point is not only
difficult (due to the trigonometric functions etc) but may also degrade the
precision.
Here is an idea whereby we can easily precompute (record) all those values
on a powerful processor and then use (replay) them on an embedded processor
/ DSP. The only requirement is that 'xxx_init_xxx' should be called in
exactly the same environment in both cases (e.g. FIXED_POINT and with the
same mode or sequence of modes).
All that's needed is to include the code segment below in one of the .h
files and wrap all those float calculations in RECOPLAY, e.g. int sqrt2 =
RECOPLAY(sqrt(2)*16384)
I've also made RECOPLAY_MARK(name) to synchronize the process.
#ifdef RECORD
#include <stdio.h>
extern FILE *recordFile;
#define _RECOPLAY_FOPEN \
if (!recordFile && (recordFile = fopen ("precompute.c", "w")) != NULL)
{ \
fprintf (recordFile, "#include \"config.h\"\n\
#ifndef EMBEDDED\n\
#include <stdio.h>\n\
FILE *recordFile = NULL;\n\
#else\n\
int recordDefault[]={\n");\
atexit (CloseRecordFile); \
} \
#define RECOPLAY_MARK(name) { _RECOPLAY_FOPEN; \
if (recordFile) fprintf (recordFile, "}, record"#name"[] = {\n"); \
}
#define RECOPLAY(x) ({ \
int v = (x); \
_RECOPLAY_FOPEN; \
fprintf (recordFile, " %d,\n", v); \
v; \
})
static void CloseRecordFile (void)
{
if (recordFile) {
fprintf (recordFile, "}, *recordPtr = recordDefault;\n #endif\n");
fclose (recordFile);
}
}
#else /* Not recording */
#ifndef EMBEDDED
#define RECOPLAY_MARK(x)
#define RECOPLAY(x) (x)
#else
extern int *recordPtr;
#define RECOPLAY_MARK(x) {extern int record ## x[]; recordPtr = record ##
x; }
#define RECOPLAY(x) *recordPtr++
/* Embedded version of RECOPLAY does not evaluate 'x' */
#endif
#endif
More information about the Speex-dev
mailing list