Skip to content

Commit 2d6d67a

Browse files
committed
Further tweaks, to pull levels, etc. from self texture.
1 parent adb2015 commit 2d6d67a

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.shader

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLinkSpectrumUI.shader

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI"
2727
_X1("X1", Range(0.242, 0.387)) = 0.25
2828
_X2("X2", Range(0.461, 0.628)) = 0.5
2929
_X3("X3", Range(0.704, 0.953)) = 0.75
30-
_Threshold0("Threshold 0", Range(0.0, 1.0)) = 0.45
31-
_Threshold1("Threshold 1", Range(0.0, 1.0)) = 0.45
32-
_Threshold2("Threshold 2", Range(0.0, 1.0)) = 0.45
33-
_Threshold3("Threshold 3", Range(0.0, 1.0)) = 0.45
3430

3531
}
3632
SubShader
@@ -67,10 +63,6 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI"
6763
uniform float _X1;
6864
uniform float _X2;
6965
uniform float _X3;
70-
uniform float _Threshold0;
71-
uniform float _Threshold1;
72-
uniform float _Threshold2;
73-
uniform float _Threshold3;
7466

7567
float _SpectrumGain;
7668
float _SpectrumColorMix;
@@ -121,13 +113,14 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI"
121113
fixed4 frag(v2f IN) : SV_Target
122114
{
123115
float2 iuv = IN.uv;
124-
float audioBands[4] = {_X0, _X1, _X2, _X3};
125-
float audioThresholds[4] = {_Threshold0, _Threshold1, _Threshold2, _Threshold3};
126116
float4 intensity = 0;
127117
uint totalBins = AUDIOLINK_EXPBINS * AUDIOLINK_EXPOCT;
128118
uint noteno = AudioLinkRemap(iuv.x, 0., 1., AUDIOLINK_4BAND_FREQFLOOR * totalBins, AUDIOLINK_4BAND_FREQCEILING * totalBins);
129119
float notenof = AudioLinkRemap(iuv.x, 0., 1., AUDIOLINK_4BAND_FREQFLOOR * totalBins, AUDIOLINK_4BAND_FREQCEILING * totalBins);
130120

121+
float4 audioBands = AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 1, 0 ) );
122+
float4 audioSetLevels = AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 1, 1 ) );
123+
131124
{
132125
float4 spectrum_value_lower = AudioLinkData(float2(fmod(noteno, 128), (noteno/128)+4.0));
133126
float4 spectrum_value_higher = AudioLinkData(float2(fmod(noteno+1, 128), ((noteno+1)/128)+4.0));
@@ -153,13 +146,7 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI"
153146
band += (iuv.x > audioBands[j]);
154147
}
155148

156-
float tHoldLevel = audioThresholds[band];
157-
158-
//ALPASS_FILTEREDVU_LEVELTIMING
159-
if( AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING ).y )
160-
{
161-
tHoldLevel -= AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 0, band ) ).z;
162-
}
149+
float tHoldLevel = AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 0, band ) ).z;
163150
threshold += saturate(_ThresholdThickness - abs(iuv.y - lerp(minHeight, maxHeight, tHoldLevel))) * 1000.;
164151
threshold = saturate(threshold) * (1. - round((iuv.x % _ThresholdDottedLine) / _ThresholdDottedLine));
165152
threshold *= (iuv.x > _X0);

0 commit comments

Comments
 (0)