diff options
author | bnewbold <bnewbold@robocracy.org> | 2012-12-24 15:39:35 +0100 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2012-12-24 15:39:35 +0100 |
commit | 2403b07ec0a7586108798271fa04eb034445f51d (patch) | |
tree | 805f1ac5b46b484799c7c585f46b626da890dd96 /sine_lookup.c | |
parent | 4818443a6a7abb9fe3976dd5846d42816e9d2328 (diff) | |
download | bytetunes-2403b07ec0a7586108798271fa04eb034445f51d.tar.gz bytetunes-2403b07ec0a7586108798271fa04eb034445f51d.zip |
updates to documentation, code cleanup, comments
Diffstat (limited to 'sine_lookup.c')
-rw-r--r-- | sine_lookup.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/sine_lookup.c b/sine_lookup.c index 1d12f76..a6e41a5 100644 --- a/sine_lookup.c +++ b/sine_lookup.c @@ -1,7 +1,19 @@ +/* + * This crude interpolated sine lookup table implementation is useful for + * testing PWM audio output from microcontrollers. + * + * If you want something that will actually sound like a sine wave, you should + * bump up to 128 or more samples and higher bit resolution. + */ #include <stdio.h> - +/* +# python generator code for the below table +from math import sin +count = 64 +print [int(127+127*sin(3.14159268*2*i/count)) for i in range(count)] +*/ unsigned char sine_lookup[] = {127, 139, 151, 163, 175, 186, 197, 207, 216, 225, 232, 239, 244, 248, 251, 253, 254, 253, 251, 248, 244, 239, 232, 225, 216, 207, 197, 186, 175, 163, 151, 139, 126, 114, 102, 90, 78, 67, 56, 46, @@ -16,7 +28,8 @@ unsigned char sin_8bit(int counter, int period) { float weight = (63*t) - (int)(63*t); low = sine_lookup[(int)(63*t)]; if (63*t >= 62) - high = sine_lookup[0]; + //high = sine_lookup[0]; + high = 118; // not sure why sine_lookup[0] creates a glitch... else high = sine_lookup[1+(int)(63*t)]; //printf("\tl=%d h=%d w=%f\n", low, high, weight); @@ -29,3 +42,4 @@ void main() { printf("%d\t%d\n", i, sin_8bit(i, 800)); } } + |