Hey,
I'm working on a project where I'll be writing many PCM .wav files. Each .wav file is of a sine wave with varying frequency.
I'm using the sin() function found in <cmath> to emulate the sine waves, however, I've been getting unexpected results, so I've written a small test program to confirm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <cmath>
constdouble pi = 3.1415926535;
int main() {
double param=180.0;
double result=sin(param*pi/180);
std::cout << "The sine of " << param << " degrees is " << result << "." << std::endl;
std::cin.get();
return 0;
}
My problem is this: When the sine should be 0 (abs(cosine)=1, you get the idea), it gives me trash values like -3.5917e-010. I know it's something tiny I'm missing, probably because I'm a silly goose.
You need to watch your domain for input values. The trigonometric functions don't necessarily adjust for stuff outside of 0..pi, IIRC. [edit]Well, that domain for the sine function, anyway.