예제 #1
0
    // Member Functions

    void Awake()
    {
        s_cInstance = this;

        s_activeAudio = new List <ClipInfo>();
        m_listener    = (AudioListener)FindObjectOfType(typeof(AudioListener));

        occludeState = OcclusionState.OCCLUSION_FALSE;
    }
예제 #2
0
파일: CAudioSystem.cs 프로젝트: nulhax/VOID
	// Member Functions
	
	void Awake() 
	{
		s_cInstance = this;
       		
		s_activeAudio = new List<ClipInfo>();
		m_listener = (AudioListener) FindObjectOfType(typeof(AudioListener));
		
		occludeState = OcclusionState.OCCLUSION_FALSE;
    }
예제 #3
0
파일: CAudioCue.cs 프로젝트: dacuster/VOID
    //As implied, stops all sounds that are currently playing.
    public void StopAllSound()
    {
        if (m_arAttachedAudioSource != null)
        {
            foreach (AudioSource audioSource in m_arAttachedAudioSource)
            {
                if (audioSource != null && audioSource.isPlaying)
                {
                    CAudioSystem.StopSound(audioSource);
                }
            }

            m_arAttachedAudioSource.Clear();
        }
    }
예제 #4
0
    void DecodingUpdate()
    {
        if (s_decodedFrames.Count > 0)
        {
            //Take data from the queue to add to the audioclip.
            DecodeInformation decodedFrame    = s_decodedFrames.Dequeue();
            short[]           saDecodedFrames = decodedFrame.saDecodedData;
            int            numSamples         = decodedFrame.iNumSamples;
            int            frequency          = decodedFrame.iFrequency;
            CNetworkViewId senderViewID       = decodedFrame.cSenderViewID;

            float[] faDecodedAudioData = new float[numSamples];

            for (int i = 0; i < faDecodedAudioData.Length; ++i)
            {
                faDecodedAudioData[i] = (float)((float)saDecodedFrames[i] / 32767.0f);
            }

            // Play audio at location of sender
            GameObject  senderNetworkView = CNetworkView.FindUsingViewId(senderViewID).gameObject;
            AudioSource senderAudioSource = senderNetworkView.gameObject.GetComponent <AudioSource>();

            AudioClip newClip = AudioClip.Create("Test", faDecodedAudioData.Length, 1, frequency, true, false);
            newClip.SetData(faDecodedAudioData, 0);

            senderAudioSource.clip   = newClip;
            senderAudioSource.volume = 1.0f;

            //AudioSystem.GetInstance.Play(newClip, senderNetworkView.gameObject.transform.position, 1.0f, 1.0f, false, 0.0f, AudioSystem.SoundType.SOUND_EFFECTS, true);
            CAudioSystem.Play(senderAudioSource, 1.0f, 1.0f, false, 0.0f, CAudioSystem.SoundType.SOUND_EFFECTS, true);
        }

        if (s_framesToDecode.Count > 0)
        {
            for (int i = 0; i < m_kiNumDecodeThreads; i++)
            {
                if (m_DecodeThreads[i].IsAlive == false)
                {
                    m_DecodeThreads[i] = new Thread(new ParameterizedThreadStart(DecodeAudio));
                    m_DecodeThreads[i].Start((object)s_framesToDecode.Dequeue());
                    break;
                }
            }
        }
    }
예제 #5
0
파일: CAudioCue.cs 프로젝트: dacuster/VOID
    //Will play specified sound if one is set. Otherwise, a random clip will be used.
    //A random sound can be specified be setting the index to negative one (-1).
    //Will only work if object already has an audiosource, else use the overloaded method
    public void Play(float volumeScale, bool loop, int index)
    {
        AudioSource newAudioSource = GetComponent <AudioSource>();

        //Make sure fade in times are set. If not, assign default values.
        if (m_fFadeInTimeList.Length < m_arAudioClipPool.Length)
        {
            m_fFadeInTimeList = new float[m_arAudioClipPool.Length];
            for (int i = 0; i < m_arAudioClipPool.Length; i++)
            {
                m_fFadeInTimeList[i] = 0.0f;
            }
        }

        //Make sure fade out times are set. If not, assign default values.
        if (m_fFadeOutTimeList.Length < m_arAudioClipPool.Length)
        {
            m_fFadeOutTimeList = new float[m_arAudioClipPool.Length];
            for (int i = 0; i < m_arAudioClipPool.Length; i++)
            {
                m_fFadeOutTimeList[i] = 0.0f;
            }
        }

        //Assign a random index if one is not set.
        if (index == -1)
        {
            index = Random.Range(0, m_arAudioClipPool.Length);
        }

        newAudioSource.clip = m_arAudioClipPool[index];

        //Allow the AudioSystem to handle the new audio source.
        CAudioSystem.Play(newAudioSource, Random.Range(m_fVolumeMin, m_fVolumeMax) * volumeScale,
                          Random.Range(m_fPitchMin, m_fpitchMax), loop,
                          m_fFadeInTimeList[index],
                          m_eSoundType, true);

        //Add this to the list of attached audio sources.
        m_arAttachedAudioSource.Add(newAudioSource);
    }
예제 #6
0
파일: CAudioCue.cs 프로젝트: dacuster/VOID
    //If there is relevant information set, this function will fade out sounds over time, then stop them.
    public void FadeOut()
    {
        if (m_fFadeOutTimeList.Length > 0 && m_arAttachedAudioSource != null)
        {
            for (int i = 0; i < m_arAttachedAudioSource.Count; i++)
            {
                if (m_arAttachedAudioSource[i] != null && m_arAttachedAudioSource[i].isPlaying && i < m_fFadeOutTimeList.Length)
                {
                    CAudioSystem.FadeOut(m_arAttachedAudioSource[i], m_fFadeOutTimeList[i]);
                }
                else if (m_arAttachedAudioSource[i] != null && m_arAttachedAudioSource[i].isPlaying)
                {
                    //If the correct fadeout information cannot be found, simply stop the sound.
                    CAudioSystem.StopSound(m_arAttachedAudioSource[i]);
                }
            }

            m_arAttachedAudioSource.Clear();
        }
        else
        {
            StopAllSound();
        }
    }