Calling sin(x) requires a lot of CPU power (relatively speaking). Implementing trig functions in hardware takes a lot of silicon. Can we reduce this burden?
Yes, and the answer is a look-up table. Before starting our program, we pre-calculate one full cycle of a sine wave. We store that in memory, and then when we want to calculate sin(x) during our program, we look at the table in memory instead of calculating it fresh each time. When dealing with silicon, the look-up table can be written in ROM (read-only memory) instead of calculated.
There are some notes here: mcm.pdf. Skip over chapter 1, and read chapter 2 up to and including section 2.3 Determining the Table Length. A print-out of this material will be handed out in class.
Answer these questions, assuming you are creating CD-quality audio (44100 Hz, 16-bit samples, stereo channels).
f(x) = sin(x) g(x) = sin(2*x)Suppose you wanted to create a look-up table for g(x). How large should that table be?
Assume that you are producing audio at 10 hz (yes, ridiculously low!).
Index 0 1 2 ... Value 0 0.588 0.951 ...
Let the user specify a frequency, then generate a sine wave at that frequency
Storing a full sine wave in ROM requires a bunch of silicon. Can we reduce this burden?
Yes, and the answer is a partial look-up table. In particular, a sine wave can be re-created using only one quarter of a cycle; the other three quarters are simple the original quarter flipped across the y axis and/or mirrored around the x axis.
There are some notes here: mcm.pdf. Skip over chapter 1, and read chapter 2 up to and including section 2.4 Shortening the Lookup Table. A print-out of this material will be handed out in class.
Assume that you are producing audio at 10 hz (yes, ridiculously low!).
Index 0 1 2 ... Value 0 0.156 0.309 ...
Let the user specify a frequency, then generate a sine wave at that frequency
Unless otherwise noted, all materials on these pages are licenced under a Creative Commons Licence.