Assignment 1: Basic Sound Production
Goal
To understand the basic parameters of digital sound:
waveform, sampling rate, frequency, sample size, number of channels and
encoding method.
Task list
- Write a C program to generate a sine wave with these
parameters
- sampling rate 44100 samples per sec.
- frequency 440 cycles per sec (A above middle C)
- one channel (mono)
- 2 signed bytes per sample
- linear encoding
- length 4 secs.
- 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?
- Use aplay again, but vary the playback parameters. What
happens when you alter the sampling rate? What happens when you change the
number of channels to 2? What happens when you change the number of bytes
per sample to three?
- Alter the program to 'clip' the output. i.e. if the
numbers grow larger than two bytes will hold, keep the output value at the
maximum value. Play it with aplay. What sound do you hear?
- Alter the original version to add in the second third and
fourth harmonics with amplitude in inverse proportion to the number of the
harmonic. Play the file again with aplay. What sound do you hear?
Hints
- Use the formula discussed in class to generate a sine wave
using the math function with prototype double sin(double).
- Use an array to hold the samples and use fwrite to output
the array values into an output file in binary format.
- 'man aplay' will tell you how to use aplay's parameters.
- The constants for maximum values of short ints are SHRT_MAX
and SHRT_MIN.
Deliverables
- Three source code files for parts 1, 4 and 5.
- A text file with the nswers to the questions in parts 2, 3, 4 and 5.
Due Date
February 6th . before midnight. Please submit your assignment
using the homework submission page.