[sdiy] sine wave floating point conversion issue
dan snazelle
subjectivity at hotmail.com
Sat Feb 25 03:36:02 CET 2012
If I have a value in my program that is putting out floating point values (to make a sine wave) between 0.0 and 1.0
I would like to get these values into an integer value of between 0 and 255 for my dac routine.
i tried changing the type and multiplying the value and then dividing it, but then i ended up with negative and positive values....
here is the routine which MAKES the sine
void loop () {
int FREQUENCY=25+analogRead(0);
float sample;
int j;
for(j = 0; j < NUM_SAMPLES; j++) {
sample = sin(2 * PI * FREQUENCY * j / SAMPLING_RATE);
sample is the value which is a float and puts out the number I want to transform into something usable for the dacOutput function.
This has shown me I need to get better and basic type conversion, etc
thanks
More information about the Synth-diy
mailing list