title: Frequency related sine wave generator on embedded system
body: <p>I have a similar question on this topic :<a href="https://stackoverflow.com/questions/4974531/writing-musical-notes-to-a-wav-file">Writing musical notes to a wav file</a>. But, I am a beginner in stackoverflow.com and I have not enough reputation to add command and I am not sure posting a Q under a Q is allowed.</p>
  
  <p>Please let me explain my purpose and problem. </p>
  
  <p>I want to send 16-bit 48kHz sample rate sine wave with I2S from stm32f4 microcontroller to a DAC. I generate a wave with math library of C and sin() function. After generating, I am testing sound with headphone. However, it does not seem to related frequency but also it does. Something changes when freq. parameter changes but there is no difference on timbre. May be I need a FIR low-pass filter but I'm not sure. I also tried to use a FIR low-pass filter actually(from Andreas Finkelmeyer's web site, mind-dump.net). However, it didn't change anything meaningful on my sine wave generator code.</p>
  
  <p>Finally, I mainly tried to follow Eric's wise advices (in that topic) on my code but I am doing something that is wrong. Please help! I would appreciate any response. </p>
  
  <p>Here is my code that generates sine wave.</p>
  
  <pre><code>if (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE))
                  {
                      for (countSin = 0;countSin &lt; 65536;countSin ++){
  
                      SPI_I2S_SendData(SPI3, sample);
                      if (sampleCounter &amp; 0x00000001) //this line for matching L&amp;R channels
                      {
  
                          sample = (uint16_t) (32768+(2500*sin((2*3.14/48000)*countSin*8800)+2000*sin((2*3.14/48000)*countSin*11)));
  }
                      sampleCounter++;
  </code></pre>
  
  <p>Many thanks!</p>