# Generating Prefect Wave Tables ?

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

## 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 on other sites
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)

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×