public void PlayAudio1() { if (NotRealDevice()) { return; } nativeAudioController = nativeAudioPointer.Play(); }
/// <summary> /// If you overwrite the pointer without unloading, you lose a way of unloading that audio permanently! /// </summary> private void UnloadIfLoaded() { if (nativeAudioPointer != null) { nativeAudioPointer.Unload(); nativeAudioController = null; } }
public void PlayAudio1() { #if UNITY_EDITOR //You should have a fallback to normal AudioSource playing in your game so you can also hear sounds while developing. Debug.Log("Please try this in a real device!"); #else nativeAudioController = nativeAudioPointer.Play(); #endif }
// PLAY 0 or 1 public void PlaySound(int soundIndex) { #if UNITY_EDITOR Debug.Log("TRY ON PHONE"); #elif UNITY_IOS if (audioPointers[soundIndex] != null) { nativeAudioController = audioPointers[soundIndex].Play(0.5f, 0.0f); } #endif }
public void PlayAudio3() { if (NotRealDevice()) { return; } var options = NativeAudio.PlayOptions.defaultOptions; options.volume = 0.5f; options.trackLoop = true; nativeAudioController = nativeAudioPointer.Play(options); }
public void PlayAudio2() { if (NotRealDevice()) { return; } var options = NativeAudio.PlayOptions.defaultOptions; options.volume = 0.3f; options.pan = 1f; nativeAudioController = nativeAudioPointer.Play(options); }
IEnumerator PlottingRoutine() { float startTime = 0; double startDspTime = 0; actualTimeList.Clear(); unitySource.clip.LoadAudioData(); actualTime.positionCount = 0; unityTime.positionCount = 0; unityDspTime.positionCount = 0; nativeAudioTime.positionCount = 0; guideGrid.positionCount = 0; //Try to start the 4 timer together, however they can never be EXACTLY at the same time. startTime = Time.realtimeSinceStartup; startDspTime = AudioSettings.dspTime; unitySource.Play(); #if !UNITY_EDITOR NativeAudioController controller = pointer.Play(); #endif //Debug.Log("Started the test at real time : " + startTime + " dsp time : " + startDspTime); float timeProgression; int vertexCount = 0; do { //Research result : //All the API for each of 4 timers is very sensitive. Each one can change its value even in the same frame. //For example if you ask the time here VS at the end of do while, there is a chance that the value will change. //Also there is a chance that the value will NOT change. Indicating that the update is in a certain step of audio hardware. //The value changing means that "step" occur when we are drawing the graph. //However, if AudioSettings.dspTime changes unitySource.time also change with it. If the former stay still the latter also stay still. //Because those two timer are in the same update system, the audio DSP update. //GetPlaybackTime from native side also may or may not change between the beginning of do while and the end //But it is in a different cycle than Unity's DSP. (dspTime and audioSource.time change or not change together, but if those two stay still //GetPlaybackTime might still change or not change. //Finally Time.realtimeSinceStartup ALWAYS change in between lines of code. There is no instance that this value stay the same in any calls. //With that in mind, to make the graph plotting as fair as possible I will use the API to pre cache the data all together here. var realTime = Time.realtimeSinceStartup; var dspTime = AudioSettings.dspTime; var unitySourceTime = unitySource.time; #if !UNITY_EDITOR var nativeSourceTime = controller.GetPlaybackTime(); #endif //You can uncomment this and its pair at the end of do while to see what I have said // #if !UNITY_EDITOR // Debug.Log("Test time BEFORE " + Time.realtimeSinceStartup + " " + AudioSettings.dspTime + " " + unitySource.time + " " + controller.GetPlaybackTime()); // #endif vertexCount++; timeProgression = (realTime - startTime) / timeLimit; PlotNextVertex(actualTime, vertexCount, timeProgression, timeProgression); PlotNextVertex(unityDspTime, vertexCount, timeProgression, (float)((dspTime - startDspTime) / timeLimit)); PlotNextVertex(unityTime, vertexCount, timeProgression, unitySourceTime / timeLimit); #if !UNITY_EDITOR PlotNextVertex(nativeAudioTime, vertexCount, timeProgression, nativeSourceTime / timeLimit); #endif //Draw frame guide grid PlotNextVertex(guideGrid, ((3 * (vertexCount - 1)) + 1), timeProgression, 0); PlotNextVertex(guideGrid, ((3 * (vertexCount - 1)) + 2), timeProgression, 1); PlotNextVertex(guideGrid, ((3 * (vertexCount - 1)) + 3), timeProgression, 0); // #if !UNITY_EDITOR // Debug.Log("Test time AFTER " + Time.realtimeSinceStartup + " " + AudioSettings.dspTime + " " + unitySource.time + " " + controller.GetPlaybackTime()); // #endif yield return(null); }while (timeProgression < 1); //Debug.Log("Ended the test at " + Time.realtimeSinceStartup); }