# line~

## Constant power panning using square root of intensity

The intensity of sound is proportional to the square of its amplitude. So if we want to have a linear change in intensity as we go from 0 to 1 or 1 to 0, we need to use the square root of that linear change to calculate the amplitude. This example patch is exactly like "Linear amplitude panning", except that we consider the linearly changing signal from line~ to be the intensity rather than the amplitude, and we take the square root of that value to obtain the actual amplitude for each speaker.

## Linear amplitude panning

The simplest and most common way to localize a sound in a stereo field is to vary the relative intensity between the two speakers. To make a sound seem to move from one side to the other, for example, you can start with the level of one speaker set to 1 and the other speaker set to 0, then gradually turn one down to 0 as you bring the other up to 1. This patch demonstrates a direct linear pan from one speaker to the other.

## Switching and mixing audio

As you get more involved in programming audio, it's likely that you'll want to have multiple sound possibilities available in your program, that you can switch on and off as needed. You might want to take a look at MSP Tutorial 5: Turning signals On and Off to learn about some basic ways of doing that. However, that chapter leaves out the following pretty crucial issue.

## Live capture in sound file

This shows how to record into a sound file, and how to play back the contents of the file. The example also demonstrates how you can use a quick fade-in and fade-out to avoid clicks when doing realtime capture during a performance.

## Live capture in buffer~

This shows how to record into a RAM (random-access memory) buffer, and how to play back the contents of the buffer at any rate (even backward by using a negative rate) starting at any point in the buffer. A timer is used to keep track of the duration of the recording. The example also demonstrates how one might use a quick fade-in and fade-out to avoid clicks when doing realtime capture during a performance.

## Linear interpolation of audio

For linear interpolation of a MSP signal, the line~ object sends out a signal that progress to some new value over a certain amount of time interpolating sample-by-sample along the way. The input to line~ is a pair of numbers representing a destination value (where it should eventually arrive) and a transition time (how long it should take to get there). It can receive multiple pairs of numbers in a single message, and it will use the pairs in order, starting each new pair when the previous transition has finished.

## Interpolation with line or line~

The line~ object outputs a signal and interpolates sample-by-sample from wherever it currently is to wherever you tell it to go, in the amount of time you specify. So, if it is currently sending out a signal value of 0.5 and you tell it to go to 0.8 in 10 ms, it will start going to 0.8 and get there in 441 samples (assuming a sample rate of 44,100), sending out signal values like 0.50068, 0.50136, etc. till it arrives at 0.8, then it will stay there till it gets a new message.

## Envelope function without a fixed starting point

The function object permits you to design a shape made up of line segments, and then you can send that information (out the second outlet) to a line~ object to cause a changing signal with that shape over a specified amount of time. When the function object receives a bang, first it sends out its initial value as a float (0. in this case), then it sends out a list of subsequent values and destination times.