I’m having problems with some sample code I got from Boulanger and Lazzarini’s ‘The Audio Programming Book’. It’s supposed to generate values for a sine wave, but when I run it I’m just getting values of -0.0000000 and 0.0000000, instead of the expected values between -1.0 and +1.0. I’ve watched the values as it runs using breakpoints and it all looks good, but when it runs (in either debug or release mode) it gives me bad values.
I’m using Xcode 3.2.6 on MacOSX 10.6.8.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#define M_PI (3.141592654)
#endif
int main(int argc, char** argv) {
int i, nsamps;
double samp;
double twopi = 2.0 * M_PI;
double angleincr;
nsamps = 50;
angleincr = twopi * nsamps;
for (i=0; i < nsamps; i++) {
samp = sin(angleincr*i);
fprintf(stdout, "%lf\n", samp);
}
fprintf(stderr, "done\n");
return 0;
}
Thanks! 🙂
In your code
angleincr*iis always a multiple of 2π so the result will indeed be 0.