سؤال

I have a similar question on this topic :Writing musical notes to a wav file. 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.

Please let me explain my purpose and problem.

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.

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.

Here is my code that generates sine wave.

if (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE))
                {
                    for (countSin = 0;countSin < 65536;countSin ++){

                    SPI_I2S_SendData(SPI3, sample);
                    if (sampleCounter & 0x00000001) //this line for matching L&R channels
                    {

                        sample = (uint16_t) (32768+(2500*sin((2*3.14/48000)*countSin*8800)+2000*sin((2*3.14/48000)*countSin*11)));
}
                    sampleCounter++;

Many thanks!

هل كانت مفيدة؟

المحلول

The "timbre" should not change. A sine wave is a single pure tone; changing the frequency changes the pitch of the tone but only the pitch. If you're hearing anything else, either you aren't generating a sine wave or there's a problem somewhere in your sound chain which is distorting the signal.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top