Assignment 2: Sound Generation using Wavetables

Goal

To understand how wavetables work and how they can be used to produce different frequencies and different waveshapes.

Task list

  1. Alter your sine wave program (or write a new one) that uses a wavetable for generation. Set the initial parameters as follows
    1. sampling rate 48,000 samples per sec (note, not 44,100)
    2. frequency 480 cycles per sec (between B flat and B natural above middle C)
    3. wavetable length 1,000 samples
    4. one channel (mono)
    5. 2 signed bytes per sample
    6. linear encoding
    7. length 4 secs.
  2. Use a for loop to place samples for one cycle of a sine wave into the wavetable.
  3. Use the formula f×nt/sr to calculate the wavetable increment and generate 4 secs of sound by multiplying the increment by the output sample number and using the result as an index into the table. (Use rounding and the mod operation to ensure that the index is an integer.) In this first case, the increment is 10 so we are skipping 9 samples and taking every tenth.
  4. Verify that your program works by using the utility aplay with the same parameters as above on the file that the program produces. What sound do you hear?
  5. Change the frequency to 960 and reduce the table size to 100 samples. Again load a sine wave into the table, and use it to generate 4 secs. of sound. The sound should change to an octave above the first sound. The increment is now 2.
  6. Change the sampling rate to 44,100, keeping table length and frequency the same. Generate 4 secs. of sound. It should not alter even though we have a non-integral table increment.
  7. Change the frequency to 120, go back to a smpling rate of 48,000,  and keep the table size at 100. Now the increment is 0.25, so we are reusing samples. Generate 4 secs. of sound. Describe the quality of the sound.
  8. Alter the index calculation to use linear interpolation instead of rounding. Generate 4 secs. of sound. It should be somewhat cleaner sounding.
  9. Go back to f = 480, and table size = 1,000. Generate values in the wavetable for a sawtooth wave and describe the quality of the sound.
  10. Generate values for a square wave in the wavetable and describe the quality of the sound.
  11. Generate random values in the table using the function random(), and describe the quality of that sound.

Hints