Sign in to follow this  
Endemoniada

Wavetable Lookup Problem

Recommended Posts

Endemoniada    430
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
Rockoon1    104
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this