Difference between revisions of "Signal generator hints"
From CCRMA Wiki
|Line 6:||Line 6:|
* a distributed random number generator.
Revision as of 09:56, 23 September 2010
These are listed in some what easiest-to-hardest. As we did the sine wave in class, it's first!
- Use the <math.h> library sine function to compute the sine wave. You'll have to make sure to normalize the input to the sine wave by the sampling rate.
- For class one simple way to do it was: sin( 2 * pi * fc * t / fs ) where fc is the center frequency, t is a time increment increasing by 1 each sample, and fs is the sample rate.
- For simplicity, you can use a uniform distributed random number generator. If you want, try to find a Gaussian distributed random number generator!
- Use the center frequency to the fundamental period (T) in samples. The signal should be all zeros, except have a value of 1.0 at the period T.
- Compute the period (T) as above. Now divide up the period into two sections proportional to the width control (e.g., width=.5 should result in a square wave). You should probably disallow width of exactly 1.0 or 0.0 as this could create a constant amplitude signal (DC)..and you won't hear anything.
- This will be very similar to the saw
- The saw wave output should visually look the the teeth of a saw. The width (w) is a number between 0.0 and 1.0 the determines the period as well as the shape of the wave (e.g., width=.5 should result in a triangle wave, width=0 has shoots straight up to 1, and then has a negative slope downward, etc). First use the center frequency to determine how many sample you need to create the correct time period (T) in samples. Then use the width control to divide up the period into two section lengths (left and right) proportional to the width value. From there, "draw" a line with the correct slopes within each section.