Hi,
Running the following code on Due does not produce the expected sinewave table, instead I get a lot of 0's and one 4096.
Running the same code in processing with minimal adjustments for the different environment correctly draws a sinewave.
Am I missing something or does the sin function have a problem on the Due ?
Code -
// Create a table to hold the phase increments we need to generate midi note frequencies at our 44.1Khz sample rate
#define WAVE_SAMPLES 600
uint32_t nSineSamples[WAVE_SAMPLES];
void createSineTable()
{
for(uint32_t nIndex = 0;nIndex < WAVE_SAMPLES;nIndex++)
{
// tried PI, also tried 22/7
// 600 is the sample rate, 4096 is 1 in 12bit fixed point we want for DAC output
// code needs to be rewritten to account for -1 to 1 output range of sine function
// incorrectly assumes 0-1 at the moment, but sin function does not seem to be generating anything
// at the moment
nSineSamples[nIndex] = (uint32_t)sin(((2.0*(22.0/7.0))/600.0) * (float)nIndex)*4096.0;
Serial.println(nSineSamples[nIndex]);
Serial.println(sin((float)nIndex)*1000);
}
}
Duane B
rcarduino.blogspot.com