sinegen.c
来自「Fax and soft modem source code. - Slow m」· C语言 代码 · 共 59 行
C
59 行
/* Modem for MIPS AJF January 1995
Sine generator */
#include <stdio.h>
#include <math.h>
#include "private.h"
#include "complex.h"
#include "sinegen.h"
#include "myaudio.h"
#define SLENK 11 // ??? was 15
#define SINELEN (1 << SLENK)
#define TWO32 4.294967296e9 /* 2^32 */
#define TWOPI (2.0 * M_PI)
static struct Init_Sines
{ Init_Sines();
}
init_sines;
static float *sinetab;
Init_Sines::Init_Sines()
{ /* once-only initialization, done before main() is called */
sinetab = new float[SINELEN];
if (sinetab == NULL)
{ fprintf(stderr, "No room! Init_Sines\r\n");
exit(1);
}
for (int k = 0; k < SINELEN; k++)
{ float th = TWOPI * (float) k / (float) SINELEN;
sinetab[k] = sin(th);
}
}
sinegen::sinegen(float f)
{ setfreq(f);
resetphase();
}
void sinegen::setfreq(float f)
{ phinc = (int) (f * TWO32 / (float) SAMPLERATE);
}
float sinegen::fnext()
{ float x = sinetab[ptr >> (32-SLENK)]; /* keep top SLENK bits */
ptr += phinc;
return x;
}
complex sinegen::cnext()
{ complex z = complex(sinetab[ptr >> (32-SLENK)],
sinetab[(ptr + (1 << 30)) >> (32-SLENK)]);
ptr += phinc;
return z;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?