-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnWebAudioVuD.js
163 lines (142 loc) · 5.47 KB
/
nWebAudioVuD.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Konfiguration
// =============
nWebAudio['vud'] = [];
nWebAudio['vud']['canvas'] = 'nWebAudioCanvasVuD'; // ID des <canvas>-Elements
nWebAudio['vud']['delay'] = 50; // Programmgeschwindigkeit
// Größeneinstellungen
// -------------------
nWebAudio['vud']['config'] = new Array();
nWebAudio['vud']['config']['width'] = 170;
nWebAudio['vud']['config']['height'] = 60;
nWebAudio['vud']['config']['randLinks'] = 15;
nWebAudio['vud']['config']['randRechts'] = 5;
nWebAudio['vud']['config']['randOben'] = 14;
nWebAudio['vud']['config']['randUnten'] = 14;
nWebAudio['vud']['config']['abstandMitte'] = 22;
nWebAudio['vud']['config']['balkenWidth'] = 7;
nWebAudio['vud']['config']['balkenHeight'] = 5;
nWebAudio['vud']['config']['balkenSpace'] = 2;
nWebAudio['vud']['timer'];
function nWebAudio_vudRun()
{
if( nWebAudio['routing']['audioElement'].paused == false )
{
// Audiodaten ins Daten-Array laden
// ================================
nWebAudio['routing']['analyser_left'].getByteTimeDomainData(nWebAudio['routing']['vuDataArrLeft']);
nWebAudio['routing']['analyser_right'].getByteTimeDomainData(nWebAudio['routing']['vuDataArrRight']);
// Linker Kanal
// ============
avg = Math.avg( nWebAudio['routing']['vuDataArrLeft'] );
if( avg >= 128 )
{
freqPeak = Math.max.apply(null, nWebAudio['routing']['vuDataArrLeft']);
valuePeak = freqPeak - 128;
nVuAvgLeft = ( valuePeak > 0 ) ? ( valuePeak / 128 * 100 ) : 0;
} else
{
freqPeak = Math.min.apply(null, nWebAudio['routing']['vuDataArrLeft']);
valuePeak = 128 - freqPeak;
nVuAvgLeft = ( valuePeak > 0 ) ? ( valuePeak / 128 * 100 ) : 0;
}
// Rechter Kanal
// =============
avg = Math.avg( nWebAudio['routing']['vuDataArrRight'] );
if( avg >= 128 )
{
freqPeak = Math.max.apply(null, nWebAudio['routing']['vuDataArrRight']);
valuePeak = freqPeak - 128;
nVuAvgRight = ( valuePeak > 0 ) ? ( valuePeak / 128 * 100 ) : 0;
} else
{
freqPeak = Math.min.apply(null, nWebAudio['routing']['vuDataArrRight']);
valuePeak = 128 - freqPeak;
nVuAvgRight = ( valuePeak > 0 ) ? ( valuePeak / 128 * 100 ) : 0;
}
// Summierter Kanal als Mittelwert
// ===============================
nVuAvgCommon = Math.round( ( nVuAvgLeft + nVuAvgRight ) / 2 );
} else
{
nVuAvgLeft = 0;
nVuAvgRight = 0;
nVuAvgCommon = 0;
}
// Canvas zeichnen
// ===============
var nCVFreq = document.getElementById(nWebAudio['vud']['canvas']);
if( nCVFreq.getContext )
{
nCVFreq = nCVFreq.getContext('2d');
// Hintergrund
// ===========
nCVFreq.fillStyle = '#000000';
nCVFreq.clearRect(0, 0, nWebAudio['vud']['config']['width'], nWebAudio['vud']['config']['height']);
nCVFreq.fillRect( 0, 0, nWebAudio['vud']['config']['width'], nWebAudio['vud']['config']['height']);
// Beschriftungen
// ==============
nCVFreq.font = 'normal 10px Arial,sans-serif';
nCVFreq.fillStyle = '#00FFFF';
nCVFreq.fillText('L', 4, 20);
nCVFreq.fillText('R', 4, 48);
nCVFreq.font = 'normal 9px Arial,sans-serif';
nCVFreq.fillText('-20', 14, 34);
nCVFreq.fillText('-10', 30, 34);
nCVFreq.fillText('-7', 48, 34);
nCVFreq.fillText('-5', 62, 34);
nCVFreq.fillText('-3', 76, 34);
nCVFreq.fillText('-2', 90, 34);
nCVFreq.fillText('-1', 104, 34);
nCVFreq.fillText('0', 120, 34);
nCVFreq.fillText('1', 132, 34);
nCVFreq.fillText('2', 142, 34);
nCVFreq.fillText('3', 152, 34);
for( h = 0; h < 16; h++ )
{
myValue = 6.25 * h; // Alle 16 LED's
myValue = 7.50 * h; // Nur bis zur ersten roten LED
// Linker Kanal
// ============
if( nVuAvgLeft > myValue )
{
if( nVuAvgLeft > ( 6.25 * 13 ) && h > 12 )
{
nCVFreq.fillStyle = '#FF0000';
} else
if( nVuAvgLeft > ( 6.25 * 10 ) && h > 9 )
{
nCVFreq.fillStyle = '#FFFF00';
} else
{
nCVFreq.fillStyle = '#00FF00';
}
} else
{
nCVFreq.fillStyle = '#303030';
}
nCVFreq.fillRect( nWebAudio['vud']['config']['randLinks'] + ( h * ( nWebAudio['vud']['config']['balkenWidth'] + nWebAudio['vud']['config']['balkenSpace'] ) ), nWebAudio['vud']['config']['randOben'], nWebAudio['vud']['config']['balkenWidth'], nWebAudio['vud']['config']['balkenHeight']);
// Rechter Kanal
// =============
if( nVuAvgRight > myValue )
{
if( nVuAvgRight > ( 6.25 * 13 ) && h > 12 )
{
nCVFreq.fillStyle = '#FF0000';
} else
if( nVuAvgRight > ( 6.25 * 10 ) && h > 9 )
{
nCVFreq.fillStyle = '#FFFF00';
} else
{
nCVFreq.fillStyle = '#00FF00';
}
} else
{
nCVFreq.fillStyle = '#303030';
}
nCVFreq.fillRect( nWebAudio['vud']['config']['randLinks'] + ( h * ( nWebAudio['vud']['config']['balkenWidth'] + nWebAudio['vud']['config']['balkenSpace'] ) ), ( nWebAudio['vud']['config']['randOben']+nWebAudio['vud']['config']['balkenWidth']+nWebAudio['vud']['config']['abstandMitte'] ), nWebAudio['vud']['config']['balkenWidth'], nWebAudio['vud']['config']['balkenHeight']);
}
}
nWebAudio['frequenz']['timer'] = window.setTimeout("nWebAudio_vudRun()", nWebAudio['vud']['delay']);
}
document.onload = window.setTimeout("nWebAudio_vudRun()", 250);