II. Phase
Phase refers to a specific point in a waveforms cycle. A sine wave peaks at a phase value of 90 degrees. Phase may also refer to the difference between two or more similar waveforms. For example, sin( x ) is 90 degrees out of phase with cos( x ).
Initial Phase Value
The oscil opcode allows users to set an optional fourth parameter for setting the initial phase value of the waveform being generated. The range of this parameter is in fractions of a cycle (0 to 1) as related to the degrees of a single cycle waveform. 0 translates to 0 degrees, .5 translates to 180 degrees and 1 translates to 360 degrees. One more important aspect of the phase parameter is that it can be fed a negative number. When a negative number is used, oscil will retain the ending phase value of the last instance, and use it for the initial phase for the new instance. This assures there is no break in the waveform between two contiguous instances.

Anytime a signal makes a significant jump from one value to another, a transient artifact is introduced. When starting a sine wave at phase zero, no jump is made, thus no artifact is created. However, gradually increasing the initial phase value will generate louder transients as the value approaches .25, the peak of a sine wave.

instr 1
iphase = p4
kenv linseg 1, p3 *.75, 1, p3 *.25, 0
aosc oscil 32000 * kenv, 262, 1, iphase
out aosc
endin
f1 0 8192 10 1 i1 1 1 0 i1 3 1 .0625 i1 5 1 .125 i1 7 1 .1875 i1 9 1 .25
Initial Phase Value for Panning
The following example uses a low-frequency square wave to hard pan the position of a tone in a stereo field. The values for the stereo field range from 0 for the left and 1 for the right. First, the square wave is generated, and then biased, so that the first half of the cycle has a value of 0, while the second half equals 1. When the initial phase value for the square wave is zero, the stereo bouncing of the tone begins on the left. When the phase is set to .5, the bouncing begins on the right.

instr 1
iphase = p4
kosc oscil 1, 1, 2, iphase
kosc = (kosc + 1) * 0.5
aosc oscil 10000, 440, 1
outs aosc * sqrt(1-kosc), aosc * sqrt(kosc)
endin
f1 0 8192 10 1 0.5 0.333 0.25 f2 0 2 -2 -1 1 i1 0 2 0 i1 3 2 .5
Phase Cancellation
Audio signals that are out-of-phase can cause frequencies to add or cancel-out. In this demonstration, two sine waves of equal frequency are used, and mixed into a mono-channel. The first sine wave has a fixed initial phase of 0. The second sine wave has a variable initial phase. This second phase value begins at 0, and is incremented by .125 for each new instance until it reaches 1.

instr 1
iphase = p4
aosc1 oscil 10000, 440, 1
aosc2 oscil 10000, 440, 1, iphase
amix = aosc1 + aosc2
out amix
endin
f1 0 8192 10 1 i1 0 2 0 i1 3 2 .125 i1 6 2 .25 i1 9 2 .375 i1 12 2 .5 i1 15 2 .625 i1 18 2 .75 i1 21 2 .875 i1 25 2 1
Legato
To create a smooth legato instrument with oscil, it is necessary to set the phase parameter to -1. This assures the phase of the oscil isn't reset between new note events, maintaining a continuous waveform.
Figure 2.8 compares two oscil sine waves. The first has a phase value of 0 and contains vertical jumps between each new note event. The second oscil has a phase value of -1 and contains no breaks between instances.

In this example, the melody is played first with the phase parameter set to 0 and then again utilizing a phase value of -1.
instr 1
ipch = cpspch(p4)
iphase = p5
aosc oscil 10000, ipch, 1, iphase
out aosc
endin
f1 0 8192 10 1 i1 0 .25 7.00 0 i1 + . . . i1 + . . . i1 + . 7.02 . i1 + . 7.03 . i1 + . . . i1 + . . . i1 + . 7.05 . i1 + .333 7.07 . i1 + . 7.05 . i1 + . 7.03 . i1 + . 7.05 . i1 + . 7.03 . i1 + . 6.10 . i1 + 1 7.00 . i1 6 .25 7.00 0 i1 + . . -1 i1 + . . . i1 + . 7.02 . i1 + . 7.03 . i1 + . . . i1 + . . . i1 + . 7.05 . i1 + .333 7.07 . i1 + . 7.05 . i1 + . 7.03 . i1 + . 7.05 . i1 + . 7.03 . i1 + . 6.10 . i1 + 1 7.00 . e
Stereo Phase Manipulation
This example is almost identical to the phase cancellation example mentioned previously. The difference being, instead of combining the signals into a mono channel, two sine waves with varying degrees of phase are played back in stereo. The effects of the phase difference will greatly depend on where the listener is in relation to the two speakers. Place yourself so that your head is centered between the speakers, and then move left and right. Listen carefully for any differences in the audio. Try headphones as well.

You may want to take the time now to check if your speakers are properly wired. Speakers wired 180 degrees out of phase is more common than most people realize.
instr 1
iphase = p4
aosc1 oscil 10000, 262, 1
aosc2 oscil 10000, 262, 1, iphase
outs aosc1, aosc2
endin
f1 0 8192 10 1 i1 0 2 0 i1 3 2 .125 i1 6 2 .25 i1 9 2 .375 i1 12 2 .5 i1 15 2 .625 i1 18 2 .75 i1 21 2 .875 i1 25 2 1
Here is something extra to try. Take a mono soundfile, such as a mono drum loop, send it to left channel unaltered and to the right channel multiplied by -1.
Crossfading
By using a sine lfo and another sine lfo 180 degrees out of phase, we can construct an instrument that continually crossfades between two audio sources.
We begin with creating two k-rate sine wave lfos using oscil with amplitudes of .5. The first lfo's phase is set to 0, while the second lfo's phase is set to .5, 180 degrees out of phase with the first. Bias both signals by adding a constant .5 to them, so the range values fall between 0 and 1. Multiply each lfo with a different audio signal and sum them together. This produces a single tone with a cyclic, evolving timbre.
As a side note, if you were to use this technique with a legato instrument as discussed earlier, be sure to set the phase values of the lfos with a negative number.

instr 1
idur = p3
iamp = p4
ipch = cpspch(p5)
kenv expseg 1, idur * .25, 6, idur * .5, 6, idur * .25, 1
klfo1 oscil .5, kenv, 1, 0
klfo2 oscil .5, kenv, 1, .5
klfo1 = klfo1 + .5
klfo2 = klfo2 + .5
aosc1 oscil 10000, ipch, 2, -1
aosc2 oscil 10000, ipch, 3, -1
amix = aosc1 * klfo1 + aosc2 * klfo2
out amix
endin
f1 0 8192 10 1 f2 0 8192 10 1 0 1 0 1 0 1 0 f3 0 8192 10 0 1 0 1 0 1 0 1 i1 0 1 10000 7.04 i1 + . . 6.11 i1 + 2 . 6.04 i1 + 1 . 7.06 i1 + . . 7.01 i1 + 2 . 6.06 i1 + 2 . 7.04