• Advertisement
Sign in to follow this  

Wavetable Lookup Problem

This topic is 4366 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I made a wavetable (array) where I keep one full cycle of a wave (sin for now) and I get output samples at any frequency like this: #define sample_rate 44100 #define wave_table_size 4096 #define wave_table_mask 4095 float wave_scale=(float)wave_table_size/(float)sample_rate; // get 100 samples at 440hz freq=440.0f; base_freq=freg*wave_scale; phase=0.0f; for(i=0;i<100;i++){ // no interpolation or even rounding o=wavetable[(int)phase & wave_table_mask]; phase+=base_freq; } That works great for getting values equivalent to sin(). But I run into a big problem when I want to get values like this: a=sin(f*t); // no problem with lookup table b=sin(f*t+a); // I can't figure out how to add the 'a' using the lookup table scheme. I've been working on this for a few days and just can't seem to get it right. Please help.

Share this post


Link to post
Share on other sites
Advertisement
The usage of base_freq suggestions that it should be unrealated to the size of the buffer, however you seem to calculate base_freq using the buffers size.

If you are recording at 44100hz and you want to pluck a 440hz stream out of it, the stride between samples would be:

stride = (44100 / 440) = (sample_rate / freq)


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement