Exemplo n.º 1
0
    public void Awake()
    {
        director.Evaluate();
#if !UNITY_EDITOR
        loadedAudio = NativeAudio.Load(noteToPlay);
#endif
    }
Exemplo n.º 2
0
 public void Awake()
 {
     normalColor = image.color;
     mainLogic   = GameObject.FindObjectOfType <MainLogic>();
     if (NativeAudio.OnSupportedPlatform())
     {
         loadedNativeAudio = NativeAudio.Load(selfSource.clip);
     }
 }
Exemplo n.º 3
0
 private void LoadAudio(AudioClip ac)
 {
     if (NotRealDevice())
     {
         return;
     }
     nativeAudioPointer = NativeAudio.Load(ac);
     Debug.Log("Loaded audio of length " + nativeAudioPointer.Length);
 }
Exemplo n.º 4
0
    private void LoadAudio(AudioClip ac)
    {
        if (NotRealDevice())
        {
            return;
        }

        //Loading via AudioClip will pull out and send the audio byte array to C side directly.
        UnloadIfLoaded();
        nativeAudioPointer = NativeAudio.Load(ac);
        Debug.Log("Loaded audio of length " + nativeAudioPointer.Length);
    }
Exemplo n.º 5
0
    public void LoadAudioSA()
    {
        if (NotRealDevice())
        {
            return;
        }

        //Loading via ScriptableAssets will have to ask Java to read out the file, then send that audio byte array to C.
        UnloadIfLoaded();
        nativeAudioPointer = NativeAudio.Load("NativeAudioDemoSA.wav");
        Debug.Log("Loaded audio of length " + nativeAudioPointer.Length + " from ScriptableAssets");
    }
Exemplo n.º 6
0
    private void LoadAudio(string name)
    {
#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
        nativeAudioPointer = NativeAudio.Load(name);
        if (nativeAudioPointer == null)
        {
            Debug.LogError("You have either Load-ed a nonexistent audio file or allocated over the Android's AudioTrack hard limit. Check your StreamingAssets folder for the correct name, or call nativeAudioPointer.Unload() to free up the quota.");
        }
#endif
    }
    public void Start()
    {
        // var pl = PlayerLoop.GetDefaultPlayerLoop();
        // foreach(var subsystem in pl.subSystemList)
        // {
        //  if(subsystem.GetType() == typeof(Initialization))
        //  {
        //         var npl = new PlayerLoopSystem[1];
        //      npl.updateDelegate = TimeCaptureUpdate;
        //      subsystem.subSystemList = subsystem.subSystemList.Concat(npl);
        //  }
        // }
#if !UNITY_EDITOR
        NativeAudio.Initialize();
        pointer = NativeAudio.Load("NativeAudioDemo1.wav");
#endif
    }
Exemplo n.º 8
0
        public NativeAudioCase(string fileName, AudioController.AudioType type)
        {
            audioName = fileName;
            audioType = type;

#if UNITY_EDITOR
            AudioController.LoadAudioClipFromStreamingAssets(fileName, OnClipLoaded);
#elif UNITY_ANDROID
            float currentVolume = type == AudioController.AudioType.Sound ? AudioController.GetSoundVolume() : AudioController.GetMusicVolume();
            //var adjustment = new NativeAudio.PlayAdjustment { volume = currentVolume, pan = 1f };
            //playOptions = new NativeAudio.PlayOptions { playAdjustment = adjustment };
            //Debug.Log("Created native audio case for:" + fileName + "  volume: " + currentVolume);

            audioEnabled = currentVolume == 0 ? false : true;

            nativeAudioPointer = NativeAudio.Load(fileName);
#endif
        }
Exemplo n.º 9
0
    public void StopLatestPlay()
    {
#if NATIVE_TOUCH_INTEGRATION
        Debug.Log("Native touch started!!");
        staticPointer = nativeAudioPointer;
        NativeTouch.RegisterCallback(NTCallback);
        NativeTouch.Start(new NativeTouch.StartOption {
            disableUnityTouch = true
        });
        NativeTouch.WarmUp();
        return;
#endif
        if (NotRealDevice())
        {
            return;
        }
        if (nativeAudioController != null)
        {
            nativeAudioController.Stop();
        }
    }
Exemplo n.º 10
0
    IEnumerator LoadSounds()
    {
        audioPointers.Clear();

        int soundsCount = audioNames.Length;
        int soundNum    = 0;

        Debug.Log("LOAD " + soundsCount + " SOUNDS:");

        while (soundNum < soundsCount)
        {
            Debug.Log("LOADING SOUND " + audioNames[soundNum] + "  " + Time.time);
            NativeAudioPointer nativeAudioPointer = NativeAudio.Load(audioNames[soundNum]);
            audioPointers.Add(nativeAudioPointer);
            if (nativeAudioPointer == null)
            {
                Debug.Log("ERROR: " + audioNames[soundNum] + " NOT LOADED ");
            }
            yield return(new WaitForSeconds(1.0f));

            if (nativeAudioPointer != null)
            {
                Debug.Log("PREPARE SOUND " + audioNames[soundNum] + "  " + Time.time);
                nativeAudioPointer.Prepare();
            }
            else
            {
                Debug.Log("CAN'T PREPARE NULL SOUND " + audioNames[soundNum] + "  " + Time.time);
            }
            yield return(new WaitForSeconds(1.0f));

            soundNum += 1;
        }

        Debug.Log("LOADING DONE " + +Time.time);
        yield return(null);
    }
Exemplo n.º 11
0
    public IEnumerator PerformanceTest()
    {
        running = true;
        sw      = new Stopwatch();
        pr      = new PerformanceResult();
        audioSource.clip.UnloadAudioData();
        UnityEngine.Debug.Log("Performance test : AudioSource..");
        UnityEngine.Debug.Log("Performance test : AudioSource loading..");

        sw.Start();
        audioSource.clip.LoadAudioData();
        sw.Stop();
        pr.asLoad = sw.ElapsedTicks;
        sw.Reset();

        yield return(new WaitForSeconds(0.5f));

        UnityEngine.Debug.Log("Performance test : AudioSource playing..");

        for (int i = 0; i < framesOfPlay; i++)
        {
            UnityEngine.Debug.Log("Performance test : AudioSource frame " + i);
            sw.Start();
            audioSource.Play();
            yield return(null);

            sw.Stop();
            pr.asTicks.Add(sw.ElapsedTicks);
            sw.Reset();
        }

        yield return(new WaitForSeconds(0.5f));

        if (!Application.isEditor)
        {
            UnityEngine.Debug.Log("Performance test : NativeAudio initializing..");

            sw.Start();
            //This force the "crash prevention mechanism" to activates. If it crashes then... it is a bug.
            NativeAudio.Initialize(new NativeAudio.InitializationOptions {
                androidAudioTrackCount = 3
            });
            sw.Stop();
            pr.naInitialize = sw.ElapsedTicks;
            sw.Reset();

            yield return(new WaitForSeconds(0.5f));

            UnityEngine.Debug.Log("Performance test : NativeAudio silently analyzing..");

            NativeAudioAnalyzer analyzer = NativeAudio.SilentAnalyze();
            yield return(new WaitUntil(() => analyzer.Analyzed));

            pr.silenceAnalysis = analyzer.AnalysisResult.averageFps;

            UnityEngine.Debug.Log("Performance test : NativeAudio loading..");

            sw.Start();
            loaded = NativeAudio.Load("NativeAudioDemo1.wav");
            yield return(null);

            sw.Stop();
            pr.naLoad = sw.ElapsedTicks;
            sw.Reset();

            yield return(new WaitForSeconds(0.5f));

            UnityEngine.Debug.Log("Performance test : NativeAudio playing..");

            for (int i = 0; i < framesOfPlay; i++)
            {
                UnityEngine.Debug.Log("Performance test : NativeAudio frame " + i);
                sw.Start();
                loaded.Play();
                yield return(null);

                sw.Stop();
                pr.naTicks.Add(sw.ElapsedTicks);
                sw.Reset();
            }

            yield return(new WaitForSeconds(0.5f));
        }

        UnityEngine.Debug.Log("Performance test : Ending..");

        resultText.text = pr.AnalysisText;

        running = false;
    }