From 2403b07ec0a7586108798271fa04eb034445f51d Mon Sep 17 00:00:00 2001 From: bnewbold Date: Mon, 24 Dec 2012 15:39:35 +0100 Subject: updates to documentation, code cleanup, comments --- sine_lookup.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'sine_lookup.c') 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 - +/* +# 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)); } } + -- cgit v1.2.3