• Advertisement
Sign in to follow this  

Generating Prefect Wave Tables ?

This topic is 4371 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'm trying to generate a perfect wave table (array), by perfect I mean perfectly loopable, but I can't figure out the best way. If I'm running at 44100 samples per second and want a 440hz wave that makes: 44100/440=100.23 samples. I guess it can't really be perfect but what's the best way to get it close ? If I assume the decimal is .25 instead I can make 4*100.25=401 samples and then just repeat them, but maybe there is a better way ? Also, let's say it's a sin wave and the first element is 0.0, then the new wave starts at 2*PI so should my array end with the value of sin for just a tiny bit less than 2*PI ? That part is a little confusing. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
By looping every 100 samples, you'll have a 441 Hz signal. This does seem to be as close as you can get with a buffer of 100 samples. You could get closer by using a bigger buffer containing values for more than one wave, for example by filling a buffer of 401 samples with 4 waves you'd have a frequency of about 339.9 Hz. But I doubt being off by 1 Hz would make much of a difference.

All you need to do is interpolate from 0 to 2pi in increments of 1/[buffer size]. So with a buffer of 100 samples, you could do something like

for (i = 0 to 99){
f = i * 2pi / 100.0
buffer = sin(f)
}

buffer[0] would be 0, and buffer[99] would be sin(2pi*99/100)

Share this post


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

  • Advertisement