Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Chunity Boilerplate/Assets/Chunity/Scripts/ChuckMainInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public class ChuckMainInstance : MonoBehaviour
private bool clearChuckOnSceneLoad = false;


// ----------------------------------------------------
// name: useBuiltInAudioFilter
// desc: when true (default), OnAudioFilterRead advances
// this VM. Set false when an external audio driver
// (e.g. Unity Scriptable Audio Generator) owns the
// ManualAudioCallback so FilterRead does not run
// a second time.
// ----------------------------------------------------
[Tooltip( "Whether OnAudioFilterRead drives this ChucK VM. Set false when an external audio driver advances the VM instead." )]
public bool useBuiltInAudioFilter = true;



// ----------------------------------------------------
Expand Down Expand Up @@ -1094,6 +1105,26 @@ public bool HasInit()
return hasInit;
}

// ----------------------------------------------------
// name: GetMicClip
// desc: AudioClip started by SetupMic(), or null when
// the microphone is unused / unavailable.
// ----------------------------------------------------
public AudioClip GetMicClip()
{
return micClip;
}

// ----------------------------------------------------
// name: GetMicDevice
// desc: device name passed to Microphone.Start /
// GetPosition (empty string = default device).
// ----------------------------------------------------
public string GetMicDevice()
{
return myMicDevice;
}

private void SetupMic()
{
// default device
Expand Down Expand Up @@ -1165,6 +1196,11 @@ public string GetUniqueVariableName( string prefix )
#else
void OnAudioFilterRead( float[] data, int channels )
{
if( !useBuiltInAudioFilter )
{
return;
}

// check whether channels is correct | added buffer length check (v2.2.0) eito
if( channels != myNumChannels || data.Length != myOutBuffer.Length )
{
Expand Down
38 changes: 38 additions & 0 deletions Chunity Boilerplate/Assets/Chunity/Scripts/ChuckSubInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public class ChuckSubInstance : MonoBehaviour
// ================= PUBLIC FACING ================== //


// ----------------------------------------------------
// name: useBuiltInAudioFilter
// desc: when true (default), OnAudioFilterRead pulls
// this Sub's replacement-DAC UGen. Set false when
// an external audio driver reads the UGen instead.
// ----------------------------------------------------
[Tooltip( "Whether OnAudioFilterRead drives this Sub. Set false when an external audio driver reads OutputUgen instead." )]
public bool useBuiltInAudioFilter = true;



// ----------------------------------------------------
// name: chuckMainInstance
// desc: ChuckSubInstance relies on a ChuckMainInstance
Expand Down Expand Up @@ -1176,6 +1187,11 @@ void UpdateSpatialize()
#else
void OnAudioFilterRead( float[] data, int channels )
{
if( !useBuiltInAudioFilter )
{
return;
}

if( !chuckMainInstance.HasInit() )
{
// my chuck is not ready. be silent.
Expand Down Expand Up @@ -1213,6 +1229,28 @@ void OnAudioFilterRead( float[] data, int channels )
#endif


// ----------------------------------------------------
// name: OutputUgen
// desc: global UGen name used as this Sub's replacement
// DAC (e.g. __dac__N). External drivers can pass
// this to GetUGenSamples.
// ----------------------------------------------------
public string OutputUgen
{
get { return myOutputUgen; }
}

// ----------------------------------------------------
// name: IsRunning
// desc: true after Awake finishes Sub setup; false after
// teardown. Matches the running gate used by
// OnAudioFilterRead.
// ----------------------------------------------------
public bool IsRunning
{
get { return running; }
}

public string GetUniqueVariableName()
{
return chuckMainInstance.GetUniqueVariableName();
Expand Down