"Hold Me - Luigi Talluto"
The waveform from earlier but zoomed in to a particular portion of the sound. That waveform probably represents 1/500th of a second
amplitude: 0.3981... |
amplitude: 0.8912... |
* Those graphs are not accurate. They just show different amplitudes
http://fc03.deviantart.net/fs70/f/2010/006/9/c/Equalizer_by_dl33t.gif
For some amplitude, A, of the given sound:
You take the resulting c and multiply it with the signal for amplification or atenuation
440 Hz, -3 dBFS |
880 Hz, -3 dBFS |
Outputs the audio with amplitudes flipped
http://www.alsa-project.org/alsa-doc/alsa-lib/wave1.gif A sketch of an analog waveform |
http://www.alsa-project.org/alsa-doc/alsa-lib/wave2.gif A sketch of a digital waveform |
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/wav-sound-format.gif
An example in JavaScript
var context = new AudioContext();
var processor = context.createScriptProcessor(
// Chunk (buffer) size.
512,
// Number of input channels
1,
// Number of output channels
2
);
processor.onaudioprocess = function (e) {
var L = e.outputBuffer.getChannelData(0);
var R = e.outputBuffer.getChannelData(1);
// L and R are both mutable arrays of numbers. Do stuff with them.
}
Fourier's theorem: a wave form is the sum of many sine waves, each with different periods (a.k.a. frequencies), phases and amplitudes
These sine waves are also often called "harmonics"
http://upload.wikimedia.org/wikipedia/commons/6/64/Wavelength.png
sin
)
for (var x = 0; x < someLargeValue; x++) { y = sin(x); }
http://media.giphy.com/media/NKLdcqhwo2f8A/giphy.gif
sin(x) |
0.5sin(x) |
3sin(x) |
-sin(x) |
sin(x) |
sin(2x) |
sin(-x) |
sin(x) |
sin(x - 1) |
sin(x + 1) |
http://mathworld.wolfram.com/images/eps-gif/SquareWave_700.gif
http://www.audiocheck.net/download.php?filename=Audio/audiocheck.net_sqr_1000Hz_-3dBFS_3s.wav
Recall, fourier's theorem: a wave is a sum of its sine waves
http://i.stack.imgur.com/6yngK.gif
http://i.stack.imgur.com/JhZnq.png
Note: the green line represents the sum of the waves. All others represents the harmonics
http://upload.wikimedia.org/wikipedia/commons/0/0a/Synthesis_square.gif
http://upload.wikimedia.org/wikipedia/commons/d/d4/Synthesis_sawtooth.gif
http://www.audiocheck.net/download.php?filename=Audio/audiocheck.net_saw_1000Hz_-3dBFS_3s.wav
Discrete Fourier Transform (DFT)
http://nayuki.eigenstate.org/res/how-to-implement-the-discrete-fourier-transform/dft.js
var n = pcm.length;
var out = new Array(n);
for (var k = 0; k < n; k++) { // For each output element
var sumreal = 0;
var sumimag = 0;
for (var t = 0; t < n; t++) { // For each input element
var angle = 2 * Math.PI * t * k / n;
sumreal += inreal[t] * Math.cos(angle);
sumimag += inreal[t] * Math.sin(angle);
}
out[k] = {
real: sumreal,
imaginary: sumimag
};
}
The above algorithm is a proof of concept only. It should never be used for real-time DSP! (For anything that isn't real-time is fine.) Use a library that implements a fast Fourier transform (FFT), instead
out
array has two properties, they're actually related. They're in two properties because JavaScript lacks a "complex number" primitive
var amps = new Array(n);
for (var k = 0; k < n; k++) {
var real = out[k].real;
var imaginary = out[k].imaginary;
amps[k] = Math.sqrt(real*real + imaginary*imaginary)/n;
}
var phases = new Array(n);
for (var k = 0; k < n; k++) {
phases[k] = Math.atan2(out[k].imaginary, out[k].real);
}
var pcm = new Array(n);
for (var k = 0; k < n; k++) {
pcm[k] = 0;
for (var j = 0; j < n; j++) {
pcm[k] += Math.sin(2 * Math.PI * k/sampleRate + phases[j]) * amps[j];
}
}
Never use the above algorithm in any real-time DSP applications!
var SAMPLES_BUFFER_SIZE = 128; // Can be any powers of 2.
var buffer = new Uint8Array(SAMPLES_BUFFER_SIZE);
var audioContext = new AudioContext();
var fft = audioContext.createAnalyser();
fft.fftSize = SAMPLES_BUFFER_SIZE;
// We'll initialize some audio source, and call it `src`
// There you have it, we are now performing frequency analysis on the audio.
src.connect(fft);
fft.getByteFrequencyData(buffer);
// `buffer` should now be populated with frequency domain data, with the ranges
// representing amplitudes in a logarithmic scale.