Skip to content

Commit

Permalink
Merge pull request #318 from fundale/audiolink-dual-mono
Browse files Browse the repository at this point in the history
Add support for dual mono setups (AVPro)
  • Loading branch information
pema99 authored Aug 9, 2024
2 parents cca066e + 9b8f276 commit f0d0c8f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Packages/com.llealloo.audiolink/Runtime/Scripts/AudioLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public partial class AudioLink : MonoBehaviour
[Header("Main Settings")]
[Tooltip("Should be used with AudioLinkInput unless source is 2D. WARNING: if used with a custom 3D audio source (not through AudioLinkInput), audio reactivity will be attenuated by player position away from the Audio Source")]
public AudioSource audioSource;
[Tooltip("Optional Right Audio Source for Dual Mono setups (AVPro video players)")]
public AudioSource optionalRightAudioSource;

[Header("Basic EQ")]
[Range(0.0f, 2.0f)]
Expand Down Expand Up @@ -843,6 +845,12 @@ public void SendAudioOutputData()

audioSource.GetOutputData(_audioFramesL, 0); // left channel

#if UDONSHARP
bool hasDualMono = VRC.SDKBase.Utilities.IsValid(optionalRightAudioSource);
#else
bool hasDualMono = optionalRightAudioSource != null;
#endif

if (_rightChannelTestCounter > 0)
{
if (_ignoreRightChannel)
Expand All @@ -851,15 +859,21 @@ public void SendAudioOutputData()
}
else
{
audioSource.GetOutputData(_audioFramesR, 1);
if (hasDualMono)
{
optionalRightAudioSource.GetOutputData(_audioFramesR, 0);
} else audioSource.GetOutputData(_audioFramesR, 1);
}
_rightChannelTestCounter--;
}
else
{
_rightChannelTestCounter = _rightChannelTestDelay; // reset test countdown
_audioFramesR[0] = 0f; // reset tested array element to zero just in case
audioSource.GetOutputData(_audioFramesR, 1); // right channel test
_rightChannelTestCounter = _rightChannelTestDelay; // reset test countdown
_audioFramesR[0] = 0f; // reset tested array element to zero just in case
if (hasDualMono) // check if dual mono is present
{
optionalRightAudioSource.GetOutputData(_audioFramesR, 0); // right channel test
} else audioSource.GetOutputData(_audioFramesR, 1); // right channel test
_ignoreRightChannel = (_audioFramesR[0] == 0f) ? true : false;
}

Expand Down

0 comments on commit f0d0c8f

Please sign in to comment.