hi there:
i have been experimenting with simple saw-tooth oscillator emulation before i actually do the DSP code. its essentially working out the phase increment value and just accumulate that into a float. repeat the process once the accumulator (phase) is larger than 1.
my question is that, in theory, once i know how much phase should increase by each time, i should be able to know in advance the last value of phase before it goes over 1, right?
but, as it turns out in my code, the perdicted last phase value is different from the actual value of the accumulator.
is this the precision problem with floats or am i doing something wrong in my code?
cheers
CHUN
PHP Code:main()
{
float freq = 200;
float phaseinc = freq * (1./44100);
float phase;
float last_value;
printf("freq ->%f\n", freq);
printf("phase increased by -> %f\n",phaseinc);
printf("perdict last phase value -> %f\n", 1-phaseinc);
for(phase = 0; phase < 1.; phase += phaseinc)
{
//printf("%f\n", phase);
last_value = phase;
}
printf("actual last phase value -> %f\n", last_value);
}



LinkBack URL
About LinkBacks



