Ejemplo n.º 1
0
        public void Refresh()
        {
            AudioSourcePlaybackDebugger editorTarget;

            try {
                editorTarget = target as AudioSourcePlaybackDebugger;
            }
            catch (System.Exception e) {
                Debug.Log("Not ready");
                return;
            }
            if (editorTarget == null)
            {
                return;
            }
            MicrophoneAudioSource source = editorTarget.source;

            if (source == null)
            {
                return;
            }
            AudioSource audioSource = source.GetComponent <AudioSource>();

            readHeadLabel.text  = $"READ: {audioSource.timeSamples}";
            writeHeadLabel.text = $"WRITE: {Microphone.GetPosition(source.deviceName)}";
            if (audioSource.clip == null) //.
            {
                return;
            }

            readHead.style.left  = (int)((double)audioSource.timeSamples / audioSource.clip.samples * 300);
            writeHead.style.left = (int)((double)Microphone.GetPosition(source.deviceName) / audioSource.clip.samples * 300);
        }
Ejemplo n.º 2
0
        public void Refresh()
        {
            AudioSourcePlaybackDebugger editorTarget;

            try {
                editorTarget = target as AudioSourcePlaybackDebugger;
            }
            catch (System.Exception e) {
                Debug.Log("Not ready");
                return;
            }
            if (editorTarget == null)
            {
                return;
            }
            MicrophoneAudioSource source = editorTarget.source;

            if (source == null)
            {
                return;
            }
            AudioSource audioSource = source.GetComponent <AudioSource>();

            readHeadLabel.text  = $"READ: {audioSource.timeSamples}";
            writeHeadLabel.text = $"WRITE: {Microphone.GetPosition(source.deviceName)}";
            if (audioSource.clip == null) //.
            {
                return;
            }

            readHead.style.left  = (int)((double)audioSource.timeSamples / audioSource.clip.samples * GetVisualizerWidth());
            writeHead.style.left = (int)((double)Microphone.GetPosition(source.deviceName) / audioSource.clip.samples * GetVisualizerWidth());

            int sampleDiff = Microphone.GetPosition(source.deviceName) - audioSource.timeSamples;

            if (sampleDiff < 0)
            {
                sampleDiff += audioSource.clip.samples; //If it wrapped
            }
            double sampleDiffMS = sampleDiff * (1.0 / audioSource.clip.frequency) * 1000;

            latencyLabel.text = $"{sampleDiffMS.ToString("n0")}ms";
        }