[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 

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 = 
I've also made RECOPLAY_MARK(name) to synchronize the process.

#ifdef RECORD
#include <stdio.h>

extern FILE *recordFile;

    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\
      int recordDefault[]={\n");\
      atexit (CloseRecordFile); \
    } \

    if (recordFile) fprintf (recordFile, "}, record"#name"[] = {\n"); \

#define RECOPLAY(x) ({ \
    int v = (x); \
    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)
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' */

More information about the Speex-dev mailing list