public void Play(float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None) { delay = (float)(AudioPlayerOld.GetDelayToSync(syncMode) + AudioPlayerOld.GetAdjustedDelay(delay, syncMode)); Instance.coroutineHolder.AddCoroutine("PDPlayerPlayAfterDelay", PlayAfterDelay(delay)); }
public static AudioSource Play(string instrumentName, int midiNote, float velocity, GameObject sourceObject = null, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None) { AudioSource audioSource; Instrument instrument = Instruments[instrumentName]; AudioInfoOld audioInfo = AudioPlayerOld.AudioInfos[instrument.referenceClips[midiNote].name]; AudioClip audioClip = null; float initVolume = audioInfo.volume; midiNote = GetAdjustedNote(midiNote, velocity, instrument); if (!string.IsNullOrEmpty(instrument.originalClips[midiNote])) { audioClip = instrument.audioClips[midiNote]; } else { if (instrument.generateMode == Instrument.GenerateModes.None || instrument.generateMode == Instrument.GenerateModes.PreGenerateAll) { audioClip = instrument.audioClips[midiNote]; } else if (instrument.generateMode == Instrument.GenerateModes.GenerateAtRuntime) { if (instrument.audioClips[midiNote] != null) { audioClip = instrument.audioClips[midiNote]; } if (audioClip == null) { audioClip = CreateAudioClip(instrument, midiNote); } if (!audioInfo.loop && instrument.destroyIdle) { Instance.coroutineHolder.RemoveCoroutines(instrumentName + midiNote); Instance.coroutineHolder.AddCoroutine(instrumentName + midiNote, RemoveAfterDelay(audioClip, instrument.idleThreshold, (float)(AudioPlayerOld.GetAdjustedDelay(audioInfo.delay, audioInfo.syncMode) + AudioPlayerOld.GetAdjustedDelay(delay, syncMode)))); } } } if (instrument.velocityAffectsVolume) { audioInfo.volume *= instrument.velocityCurve.Evaluate(velocity / 127); } audioSource = AudioPlayerOld.Play(audioClip, audioInfo, sourceObject, delay, syncMode); if (instrument.sendToPD) { audioSource.gameObject.GetOrAddComponent <AudioGainManager>().Initialize(instrument.name + "~"); } instrument.activeVoices.Add(audioSource); audioInfo.volume = initVolume; return(audioSource); }