[sdiy] sine wave floating point conversion issue
Jay Schwichtenberg
jays at aracnet.com
Sat Feb 25 04:20:24 CET 2012
Dan,
Try:
sine_int = (int) ((((sine_float + 1.0) * 256.0) - 1.0) / 2.0);
Jay S.
-----Original Message-----
From: synth-diy-bounces at dropmix.xs4all.nl
[mailto:synth-diy-bounces at dropmix.xs4all.nl] On Behalf Of dan snazelle
Sent: Sunday, December 31, 2000 4:52 PM
To: synthdiy diy
Subject: [sdiy] sine wave floating point conversion issue
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
_______________________________________________
Synth-diy mailing list
Synth-diy at dropmix.xs4all.nl
http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
More information about the Synth-diy
mailing list