Back to main

Lab 4 for Audio Programming

Exercises:

Exercise 11: look-up table (full)

Background

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.

Maths homework

Do this homework on paper. I know that writing stuff on paper by hand is a drag, but it will save you a lot of time and effort in the long run.

Answer these questions, assuming you are creating CD-quality audio (44100 Hz, 16-bit samples, stereo channels).


Your task...

Stop! Before you try to write a program, you must finish the maths homework.

Let the user specify a frequency, then generate a sine wave at that frequency

... show your work to a demonstrator


Exercise 12: look-up table (quarter)

Background

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.

Maths homework

Do this homework on paper. I know that writing stuff on paper by hand is a drag, but it will save you a lot of time and effort in the long run.

Your task...

Stop! Before you try to write a program, you must finish the maths homework.

Let the user specify a frequency, then generate a sine wave at that frequency

... show your work to a demonstrator

Move on to Lab 5

Back to main


Creative Commons LicenseUnless otherwise noted, all materials on these pages are licenced under a Creative Commons Licence.