Sound2Light (S2L) |
Print Previous Next |
Functionality
The First S2L Example The following example for the MAS Script Effect analyses the left and the right audio channel. Lines will be drawn onto the matrix to indicate the average frequency. const color LEFT_CHANNEL = {255, 0, 0, 128}; const color RIGHT_CHANNEL= {0, 255, 0, 128};
void InitEffect() { }
float avgFrequ(float array[]) { float result;
//to avoid division by zero later on if(array.length > 0) { for(int i = 0; i < array.length; i++) result += array[i];
result /= (float)array.length; }
return(result); }
void RenderEffect() { int valL = (int)(GetSoundLevel(0)*255.0); int valR = (int)(GetSoundLevel(1)*255.0); color c = {valL, valR, (valL * valR) % 255, (valR + valL) / 2, 0};
float iHL = (float)avgFrequ(SOUND_DATA_LEFT); float iHR = (float)avgFrequ(SOUND_DATA_RIGHT);
Clear();
DrawVectorLine(c, 0.0, iHL, 1.0, iHL); DrawVectorLine(c, iHL, 0.0, iHL, 1.0);
DrawVectorLine(c, 0.0, 1.0-iHL, 1.0, 1.0-iHL); DrawVectorLine(c, 1.0-iHL, 0.0, 1.0-iHL, 1.0);
DrawVectorLine(c, 0.0, iHR, 1.0, iHR); DrawVectorLine(c, iHR, 0.0, iHR, 1.0);
DrawVectorLine(c, 0.0, 1.0-iHR, 1.0, 1.0-iHR); DrawVectorLine(c, 1.0-iHR, 0.0, 1.0-iHR, 1.0); }
|
MADRIX Version: 3.6j | Script Version: 2.22 |
[Ctrl & +/-] = Zoom In/Out | [Ctrl & 0] = 100% |
Print Previous Next |