dsp_basics_01: what is dsp?
what is sound?
Sound is made of waves of pressure moving through some medium (typically air). Usually you make these by hitting things. Those things shake and then in turn shake the air.
A microphone turns this pressure wave into a voltage wave.
how do we represent sound on the computer?
An Analog to Digital Converter (ADC) measures this voltage at some fixed frequency. These measurements are often called samples and the frequency with which the measurements are taken is called the sample rate. The sample rate is usually 44100, 48000, 96000, measurements per second. Although, other sample rates are used.
The computer stores these samples as numbers. Often these are floating point numbers between -1 and 1. So one way to think of an audio file is a big list of numbers that represent samples.
When the computer makes sound it sends these numbers to an Digital Analog Converter (DAC) that turns them back into voltages. The amplifier then uses these voltages to make the speaker cone shake.
what is a dsp algorithm?
DSP stands for digital signal processing. Its a big topic that includes the manipulation of all kinds of digital signals. A music DSP algorithm processes the list of numbers before they get sent out to the speaker. Here is a dsp algorithm for changing the loudness of a signal:
float amp(float x, float gain){
return x*gain;
}
Its a function named amp that takes in a sample value (called x above) and multiplies it by some gain factor.
Sometimes you will need to work with lists of samples instead one sample at a time. In that case, the algorithm above might look like this:
void amp(float* in, float* out, int blocksize, float gain){
for(int i=0; i<blocksize; ++i){
out[i] = in[i]*gain;
}
}