How to look up sine of different frequencies from a fixed sized lookup table?

前端 未结 5 2039
孤城傲影
孤城傲影 2021-02-08 11:06

I am sampling a sine wave at 48 kHz, the frequency range of my sine wave can vary from 0 to 20000 Hz with a step of about 100 Hz. I am using a lookup table approach. So I genera

5条回答
  •  借酒劲吻你
    2021-02-08 11:38

    Very good answer, this is classic software DDS. Facing the same problem these days. There is no need to use floats

            UInt16 f = 400; // Hz, up to 16384 :)
            UInt16 delta = (UInt16)(((UInt32)f * LUT_SIZE ) / fmt_SamplesPerSec);
            UInt16 phase = 0;
    
            for (int i = 0; i < BUFF_SIZE; ++i)
            {
                buff[i] = LUT[phase];
                phase += delta;
                phase &= LUT_SIZE-1;
            }
    

    Let phase wraparound LUT size as mask. And don't care about using quadrants since for my purpose I have a huge MIPS for this requirements already.

提交回复
热议问题