Example #1
0
 public void Release(AudioSource source)
 {
     source.loop = false;
     source.clip = null;
     audioClip   = null;
     AudioClip.DestroyImmediate(audioClip, false);
 }
Example #2
0
        public void Preload()
        {
            if (textElement != null && text != textElement.Text)
            {
                text = textElement.Text;
            }

            if (text != lastText ||
                voiceName != lastVoiceName ||
                speakingRate != lastSpeakingRate ||
                pitch != lastPitch)
            {
                lastText         = text;
                lastVoiceName    = voiceName;
                lastSpeakingRate = speakingRate;
                lastPitch        = pitch;
                if (clip != null)
                {
                    clip.DestroyImmediate();
                    clip = null;
                }

                LoadTask();
            }
        }
        private static List <AudioClip> clipPool = new List <AudioClip>();       //a pool of audio clips

        #endregion

        #region Static Methods

        /// <summary>
        /// Play the given clip at the given point in space, with a delay of given samples
        /// </summary>
        /// <param name="clip">The clip to play</param>
        /// <param name="position">Where to play it from</param>
        /// <param name="delay">How many samples to delay</param>
        /// <param name="calcPan">Whether to calculate speaker pan based on position</param>
        public static void PlayClipAtPoint(AudioClip clip, Vector3 position, ulong delay, bool calcPan = false, bool usePooledClips = true)
        {
            AudioSource src = GetAudioSource();

            src.transform.position = position;
            if (usePooledClips)
            {
                if (src.clip != null)
                {
                    PoolAudioClip(src.clip);
                }
            }
            else
            {
                if (src.clip != null)
                {
                    AudioClip.DestroyImmediate(src.clip);
                }
            }
            src.clip = clip;
            if (calcPan)
            {
                src.panStereo = -Vector3.Dot(Vector3.Cross(Camera.main.transform.forward, Vector3.up).normalized, (position - Camera.main.transform.position).normalized);
            }
            src.PlayDelayed(delay * 44100.0f);
        }
Example #4
0
        void Dispose(bool allowDestroyingAssets)
        {
            int cnt = _items.Count;

            for (int i = 0; i < cnt; i++)
            {
                PackageItem pi = _items[i];
                if (pi.texture != null)
                {
                    if (pi.texture.alphaTexture != null)
                    {
                        pi.texture.alphaTexture.Dispose(allowDestroyingAssets);
                        pi.texture.alphaTexture = null;
                    }

                    if (pi.texture != NTexture.Empty)
                    {
                        pi.texture.Dispose(allowDestroyingAssets);
                    }
                    else
                    {
                        pi.texture.DestroyMaterials();
                    }
                    pi.texture = null;
                }
                else if (pi.audioClip != null)
                {
                    if (allowDestroyingAssets)
                    {
                        if (_fromBundle)
                        {
                            AudioClip.DestroyImmediate(pi.audioClip);
                        }
                        else
                        {
                            Resources.UnloadAsset(pi.audioClip);
                        }
                    }
                    pi.audioClip = null;
                }
                else if (pi.bitmapFont != null)
                {
                    FontManager.UnregisterFont(pi.bitmapFont);
                }
            }
            _items.Clear();

            if (_resBundle != null)
            {
                _resBundle.Unload(true);
            }
        }
Example #5
0
 public override void Shutdown()
 {
     if (audioClip != null)
     {
         if (Application.isEditor)
         {
             AudioClip.DestroyImmediate(audioClip);
         }
         else
         {
             AudioClip.Destroy(audioClip);
         }
     }
 }
Example #6
0
    private void StartRecord()
    {
        currentRecordingState.Value = recordingStates.Value[2];
        if (audioClip != null)
        {
            AudioClip.DestroyImmediate(audioClip);
        }

        // Maximum record length is one hour
        audioClip = Microphone.Start(null, false, 3599, 44100);

        recordingTimerText.text = "00:00:00";

        StartCoroutine(WhileRecording());
    }
Example #7
0
    private void ClipAudio(ref AudioClip clip, int endPos)
    {
        // from https://answers.unity.com/questions/544264/record-dynamic-length-from-microphone.html
        // Capture the current clip data
        var soundData = new float[endPos * clip.channels];

        clip.GetData(soundData, 0);

        // One does not simply shorten an AudioClip,
        //    so we make a new one with the appropriate length
        var newClip = AudioClip.Create(clip.name,
                                       endPos,
                                       clip.channels,
                                       clip.frequency,
                                       false);

        newClip.SetData(soundData, 0);        // Give it the data from the old clip

        // Replace the old clip
        AudioClip.DestroyImmediate(clip);
        clip = newClip;
    }