topical media & game development
graphic-processing-site-examples-Libraries-Minim--Sound--UserDefinedSignal-MouseSaw.pde / pde
// this signal uses the mouseX and mouseY position to build a signal
class MouseSaw implements AudioSignal
{
void generate(float[] samp)
{
float range = map(mouseX, 0, width, 0, 1);
float peaks = map(mouseY, 0, height, 1, 20);
float inter = float(samp.length) / peaks;
for ( int i = 0; i < samp.length; i += inter )
{
for ( int j = 0; j < inter && (i+j) < samp.length; j++ )
{
samp[i + j] = map(j, 0, inter, -range, range);
}
}
}
// this is a stricly mono signal
void generate(float[] left, float[] right)
{
generate(left);
generate(right);
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.