@@ -147,12 +147,12 @@ Shader "AudioLink/Internal/AudioLink"
147147 );
148148 }
149149
150- inline float Compute4BandRaw ( int band, bool enableAutoLevel )
150+ inline float Compute4BandRaw ( int band )
151151 {
152152 const float audioThresholds[4 ] = {_Threshold0, _Threshold1, _Threshold2, _Threshold3};
153153 const float audioBands[4 ] = {_X0, _X1, _X2, _X3};
154- float threshold = audioThresholds[ band] ;
155-
154+ float threshold = AudioLinkGetSelfPixelData ( ALPASS_FILTEREDVU_LEVELTIMING + uint2 ( 0 , band ) ).z ;
155+
156156 // Get average of samples in the band
157157 float total = 0 .;
158158 uint totalBins = AUDIOLINK_EXPBINS * AUDIOLINK_EXPOCT;
@@ -166,11 +166,6 @@ Shader "AudioLink/Internal/AudioLink"
166166 }
167167 float magnitude = total / (binEnd - binStart);
168168
169- if ( enableAutoLevel )
170- {
171- threshold -= AudioLinkGetSelfPixelData ( ALPASS_FILTEREDVU_LEVELTIMING + uint2 ( 0 , band ) ).z;
172- }
173-
174169 // Log attenuation
175170 magnitude = (magnitude * (log (1.1 ) / (log (1.1 + pow (_LogAttenuation, 4 ) * (1.0 - magnitude))))) / pow (threshold, 2 );
176171
@@ -344,7 +339,7 @@ Shader "AudioLink/Internal/AudioLink"
344339 if (delay == 0 )
345340 {
346341 // Is left-most pixel.
347- float magnitude = saturate ( Compute4BandRaw ( band, _EnableAutoLevel ) );
342+ float magnitude = saturate ( Compute4BandRaw ( band ) );
348343
349344 // Fade
350345 float lastMagnitude = AudioLinkGetSelfPixelData (ALPASS_AUDIOLINK + int2 (0 , band)).y;
@@ -1270,12 +1265,22 @@ Shader "AudioLink/Internal/AudioLink"
12701265
12711266 // Split into 4 columns. Each row is a band.
12721267 int band = coordinateLocal.y;
1268+ const float4 audioBands = {_X0, _X1, _X2, _X3};
1269+ const float4 audioThresholds = {_Threshold0, _Threshold1, _Threshold2, _Threshold3};
1270+
12731271 switch ( coordinateLocal.x )
12741272 {
12751273 case 8 :
12761274 {
12771275 // A basic recomputation of the 4-band. Except raw.
1278- float magnitude = Compute4BandRaw (band, true );
1276+ // This first column of 4 rows is:
1277+ // R: Current raw band magnitude.
1278+ // G: Parameters
1279+ // Row 0: "Is Autoleveling Enabled"
1280+ // B: Threshold amount from auto-level.
1281+ // A: "Confidence" in this. If confidence is low, threshold will fall.
1282+
1283+ float magnitude = Compute4BandRaw (band);
12791284 float4 self = AudioLinkGetSelfPixelData ( ALPASS_FILTEREDVU + coordinateLocal.xy );
12801285
12811286 float para = 0.0 ;
@@ -1288,26 +1293,40 @@ Shader "AudioLink/Internal/AudioLink"
12881293 float amt = self.z;
12891294 float confidence = self.w;
12901295
1291- // Compare the current value to "Magnitude" if it's very low, need to boost it.
1292- if ( magnitude < 0.5 )
1293- {
1294- confidence = ( confidence - 0.05 * unity_DeltaTime .x );
1295- amt = lerp ( amt + 0.1 * unity_DeltaTime .x, amt, saturate ( confidence ) );
1296- }
1297- else
1298- {
1299- // When we are above the threshold.
1300- confidence = 1.1 ; // Make sure it can't slop down for a few seconds.
1301- amt -= 0.5 * unity_DeltaTime .x;
1302- }
1303- amt = clamp ( amt, 0 , 0.4 );
1296+ if ( _EnableAutoLevel )
1297+ {
1298+ // Compare the current value to "Magnitude" if it's very low, need to boost it.
1299+ if ( magnitude < 0.5 )
1300+ {
1301+ confidence = ( confidence - 0.05 * unity_DeltaTime .x );
1302+ amt = lerp ( amt - 0.1 * unity_DeltaTime .x, amt, saturate ( confidence ) );
1303+ }
1304+ else
1305+ {
1306+ // When we are above the threshold.
1307+ confidence = 1.1 ; // Make sure it can't slop down for a few seconds.
1308+ amt += 0.5 * unity_DeltaTime .x;
1309+ }
1310+ amt = clamp ( amt, 0.1 , audioThresholds[band] );
1311+ }
1312+ else
1313+ {
1314+ amt = audioThresholds[band];
1315+ }
13041316
13051317 return float4 ( magnitude, para, amt, confidence );
13061318 }
1307- case 9 :
1319+ case 9 :
1320+ {
1321+ // Include configured bands and threshold.
1322+ if ( band == 0 ) return audioBands;
1323+ if ( band == 1 ) return audioThresholds;
1324+ return 0.0 ;
1325+ }
13081326 case 10 :
13091327 case 11 :
1310- return 1.0 ;
1328+ // Reserved
1329+ return 0.0 ;
13111330 }
13121331 }
13131332 return 1 ;
0 commit comments