Lace
Reaction score
0

Profile posts Postings Media Albums About

  • The horizontal lines should be equal length and the high ones should be equal height, but after the detail I put into the sawtooth one, I'm a bit tired of being meticulous.
    Looks a little something like this:

    ATiyI.png
    One such waveform is a square wave (sometimes called a rectangular wave) where the waveform jumps directly from its highest point to its lowest point and back with nothing in between.
    Now, this is all well and good if all we want is a bunch of sawtooth waves. In practice, though, we'd like a variety of different waveforms.
    The oscillator is basically a device that takes a speed as input, and cycles through the real numbers in the interval [0,1) at that speed. In theory, it's continuous, and hits every real number in that interval, but in practice, it's discrete, and only hits a finite number of them.

    You can think of it like a clock with only an hour hand, where the input tells it how fast to spin.
    This is convenient because it means that our pitch input is simply the number of cycles per second, which is the frequency of the sound we want in Hz.
    We can figure out such a calculation using dimensional analysis, like so:

    (cycles/second) / (sample frames/second) = (cycles/sample frame)
    To summarize, we need to do some calculation involving the sampling rate (sample frames/second), which gives us the input to the oscillator (cycles/sample frame).
    In order make the outputted pitch independent of the sampling rate, we will need to take the sampling rate into consideration. We will need to introduce a new device which takes no inputs and constantly outputs the sampling rate in sample frames per second.
    The thing to note about the oscillator device is that its input is measured in cycles per sample frame. For example, if you send it a constant input of .1, you are saying that you want it to move one tenth of the way through its cycle every sample frame.
    One issue with the way pitch is currently set up is that it's dependent on the sampling rate. In other words, changing the sampling rate will change the pitch of the note produced, even if the inputs remain exactly the same. This should be avoided.
    The way this is currently set up, controlling the volume is fairly intuitive; you simply specify a number from 0 to 1. Pitch, however, is not so intuitive. Let's see if we can make it more so.
    If you open that wav file in a program that allows you to see the waveform (i.e. Audacity, ptnoise), you'll notice it never drops below the midpoint (0), since our oscillator outputs values in the interval [0,1), but really should go all the way down to -1. To fix this we simply take the output from the oscillator, double it and subtract 1.
    Note that, rather than using integer values to represent sample frames (as is done in the actual wav file), we are using floating point values in the interval [-1,1). To convert these to their integer counterparts would be a simple matter of multiplying them by either 128 or 32768, depending on the bit depth.
  • Loading…
  • Loading…
  • Loading…
  • Loading…
Top