Skip to content

Commit 044b956

Browse files
committed
Fix spatializer gui showing incorrect values when first loading scene
1 parent 5ad1cb2 commit 044b956

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

Binaural/BuildUnityWrapperPackage/Assets/3DTuneIn/APIScripts/API_3DTI_Spatializer.cs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class API_3DTI_Spatializer : MonoBehaviour
8383

8484
// Set this to the 3DTI mixer containing the SpatializerCore3DTI effect.
8585
public AudioMixer spatializereCoreMixer;
86-
86+
private bool isInitialized = false;
8787

8888

8989

@@ -242,30 +242,40 @@ private string[] binaryResourcePaths(BinaryResourceRole role)
242242
private static extern bool Reset3DTISpatializerIfNeeded(int sampleRate, int dspBufferSize);
243243

244244

245+
245246
private void Awake()
246247
{
247-
// Check a missized array hasn't been saved from a previous version
248-
if (spatializerParameters.Length != NumParameters)
248+
initialize();
249+
}
250+
251+
// This function is called automatically when the scene starts. It is made public so the Inspector GUI can call it.
252+
public void initialize()
253+
{
254+
if (!isInitialized)
249255
{
250-
int originalLength = spatializerParameters.Length;
251-
Array.Resize(ref spatializerParameters, NumParameters);
252-
if (spatializerParameters.Length > originalLength)
256+
// Check a missized array hasn't been saved from a previous version
257+
if (spatializerParameters.Length != NumParameters)
253258
{
254-
for (int i = originalLength; i < spatializerParameters.Length; i++)
259+
int originalLength = spatializerParameters.Length;
260+
Array.Resize(ref spatializerParameters, NumParameters);
261+
if (spatializerParameters.Length > originalLength)
255262
{
256-
spatializerParameters[i] = ((SpatializerParameter)i).GetAttribute<SpatializerParameterAttribute>().defaultValue;
263+
for (int i = originalLength; i < spatializerParameters.Length; i++)
264+
{
265+
spatializerParameters[i] = ((SpatializerParameter)i).GetAttribute<SpatializerParameterAttribute>().defaultValue;
266+
}
257267
}
258268
}
259-
}
260269

261-
AudioSettings.GetDSPBufferSize(out int dspBufferSize, out _);
262-
Reset3DTISpatializerIfNeeded(AudioSettings.outputSampleRate, dspBufferSize);
263-
sendAllBinaryResourcePathsToPlugin();
264-
for (int i = 0; i < NumParameters; i++)
265-
{
266-
if (!Set3DTISpatializerFloat(i, spatializerParameters[i]))
270+
AudioSettings.GetDSPBufferSize(out int dspBufferSize, out _);
271+
Reset3DTISpatializerIfNeeded(AudioSettings.outputSampleRate, dspBufferSize);
272+
sendAllBinaryResourcePathsToPlugin();
273+
for (int i = 0; i < NumParameters; i++)
267274
{
268-
Debug.LogError($"Failed to set 3DTI parameter {i}.", this);
275+
if (!Set3DTISpatializerFloat(i, spatializerParameters[i]))
276+
{
277+
Debug.LogError($"Failed to set 3DTI parameter {i}.", this);
278+
}
269279
}
270280
}
271281
}

Binaural/BuildUnityWrapperPackage/Assets/3DTuneIn/Editor/AudioPlugin3DTISpatializerGUI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public override void OnInspectorGUI()
4444
{
4545

4646

47-
4847
toolkit = (API_3DTI_Spatializer)target; // Get access to API script
48+
toolkit.initialize();
49+
4950
Common3DTIGUI.InitStyles(); // Init styles
5051

5152
// Show 3D-Tune-In logo

0 commit comments

Comments
 (0)