Beispiel #1
0
    // Token: 0x0600371D RID: 14109 RVA: 0x0011A608 File Offset: 0x00118A08
    private void Acquire()
    {
        if (!this.audioSource)
        {
            return;
        }
        this.panLevel = this.audioSource.spatialBlend;
        this.spread   = this.audioSource.spread;
        if (this.context == -1)
        {
            this.context = OSPManager.AcquireContext(base.GetInstanceID());
        }
        if (this.context == -1)
        {
            return;
        }
        float spatialBlend = 1f;

        if (OSPManager.GetUseInverseSquareAttenuation())
        {
            spatialBlend = 0f;
        }
        this.audioSource.spatialBlend = spatialBlend;
        this.audioSource.spread       = 180f;
    }
    /// <summary>
    /// Plays the time scheduled relative to current AudioSettings.dspTime.
    /// </summary>
    /// <param name="time">Time.</param>
    public void PlayScheduled(double time)
    {
        if (!audioSource)
        {
            Debug.LogWarning("PlayScheduled - Warning: No AudioSource assigned");
            return;
        }

        // Bail if manager has not even started
        if (OSPManager.IsInitialized() == false)
        {
            return;
        }

        // We will grab a context at this point, and set the right values
        // to allow for spatialization to take effect
        Aquire();

        // We will set the relative position of this sound now before we start playing
        SetRelativeSoundPos(true);

        // We are ready to play the sound
        audioSource.PlayScheduled(time);

        lock (this) isPlaying = true;
    }
Beispiel #3
0
 // Token: 0x0600375D RID: 14173 RVA: 0x0011AFF0 File Offset: 0x001193F0
 private void Awake()
 {
     if (OSPManager.sInstance == null)
     {
         OSPManager.sInstance = this;
         bool flag             = true;
         int  outputSampleRate = AudioSettings.outputSampleRate;
         int  num;
         int  num2;
         AudioSettings.GetDSPBufferSize(out num, out num2);
         Debug.LogWarning(string.Format("OSP: Queried SampleRate: {0:F0} BufferSize: {1:F0}", outputSampleRate, num));
         if (flag)
         {
         }
         Debug.LogWarning(string.Format("OSP: sample rate: {0:F0}", outputSampleRate));
         Debug.LogWarning(string.Format("OSP: buffer size: {0:F0}", num));
         Debug.LogWarning(string.Format("OSP: num buffers: {0:F0}", num2));
         OSPManager.sOSPInit = OSPManager.OSP_Init(outputSampleRate, num);
         OSPManager.OSP_SetBypass(this.bypass);
         OSPManager.OSP_SetGlobalScale(this.globalScale);
         OSPManager.OSP_SetGain(this.gain);
         OSPManager.OSP_SetFalloffRangeGlobal(this.falloffNear, this.falloffFar);
         this.dirtyReflection = true;
         return;
     }
     Debug.LogWarning(string.Format("OSPManager-Awake: Only one instance of OSPManager can exist in the scene.", new object[0]));
 }
Beispiel #4
0
 // Token: 0x06003769 RID: 14185 RVA: 0x0011B155 File Offset: 0x00119555
 public static void Spatialize(int context, float[] ioBuf, bool useInvSq, float near, float far)
 {
     if (!OSPManager.sOSPInit)
     {
         return;
     }
     OSPManager.OSP_Spatialize(context, ioBuf, useInvSq, near, far);
 }
Beispiel #5
0
 // Token: 0x06003768 RID: 14184 RVA: 0x0011B13F File Offset: 0x0011953F
 public static void SetPositionRel(int context, float x, float y, float z)
 {
     if (!OSPManager.sOSPInit)
     {
         return;
     }
     OSPManager.OSP_SetPositonRelXYZ(context, x, y, z);
 }
    //* * * * * * * * * * * * *
    // Private functions
    //* * * * * * * * * * * * *

    /// <summary>
    /// Aquire resources for spatialization
    /// </summary>
    private void Aquire()
    {
        if (!audioSource)
        {
            return;
        }

        // Cache pan and spread
#if (!UNITY5)
        panLevel = audioSource.spatialBlend;
#else
        panLevel = audioSource.spatialBlend;
#endif
        spread = audioSource.spread;

        // override to use simple spatializer
        bool prevUseSimple = OSPManager.GetUseSimple();

        if (useSimple == true)
        {
            OSPManager.SetUseSimple(useSimple);
        }

        // Reserve a context in OSP that will be used for spatializing sound
        // (Don't grab a new one if is already has a context attached to it)
        if (context == sNoContext)
        {
            context = OSPManager.AquireContext();
        }

        OSPManager.SetUseSimple(prevUseSimple);          // reset

        // We don't have a context here, so bail
        if (context == sNoContext)
        {
            return;
        }

        // Set pan to full (spread at 180 will keep attenuation curve working, but all 2D
        // panning will be removed)

        // We want to remove FMod curve attenuation if we are doing our
        // own internal calc
        float pl = sSetPanLevel;
        if (OSPManager.GetUseInverseSquareAttenuation() == true)
        {
            pl = sSetPanLevelInvSq;
        }

                #if (!UNITY5)
        audioSource.spatialBlend = pl;
#else
        audioSource.spatialBlend = pl;
#endif

        // set spread to 180
        audioSource.spread = sSetSpread;
    }
Beispiel #7
0
 // Token: 0x0600371E RID: 14110 RVA: 0x0011A6A4 File Offset: 0x00118AA4
 private void Release()
 {
     if (!this.audioSource)
     {
         return;
     }
     this.audioSource.spatialBlend = this.panLevel;
     this.audioSource.spread       = this.spread;
     if (this.context != -1)
     {
         OSPManager.ReleaseContext(base.GetInstanceID(), this.context);
         this.context = -1;
     }
 }
Beispiel #8
0
    // Token: 0x0600372A RID: 14122 RVA: 0x0011ABB0 File Offset: 0x00118FB0
    private void UpdateLocalInvSq()
    {
        float nearRange = 0f;
        float farRange  = 0f;

        if (this.useInverseSquare)
        {
            nearRange = this.falloffNear;
            farRange  = this.falloffFar;
        }
        else if (OSPManager.sInstance != null)
        {
            OSPManager.sInstance.GetNearFarFalloffValues(ref nearRange, ref farRange);
        }
        OSPManager.SetFalloffRangeLocal(this.context, nearRange, farRange);
    }
    //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    // OnAudioFilterRead (separate thread)
    //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    /// <summary>
    /// Raises the audio filter read event.
    /// We will spatialize the audio here
    /// NOTE: It's important that we get the audio attenuation curve for volume,
    /// that way we can feed it into our spatializer and have things sound match
    /// with bypass on/off
    /// </summary>
    /// <param name="data">Data.</param>
    /// <param name="channels">Channels.</param>
    ///
    void OnAudioFilterRead(float[] data, int channels)
    {
#if DEBUG_AudioSource
        if (debugOn)
        {
            if (audioFrames > 0)
            {
                audioFrames--;
            }
        }
#endif
        // Problem: We cannot read timer here.
        // However, we can read time-stamp via plugin
        // This is required to smooth out the position,
        // since the main loop is only allowed to update position
        // of sound, but is running at a different frequency then
        // the audio loop.
        //
        // Therefore, we will need to dead reckon the position of the sound.

        // Do not spatialize if we are not playing
        if ((isPlaying == false) ||
            (Bypass == true) ||
            (OSPManager.GetBypass() == true) ||
            (OSPManager.IsInitialized() == false))
        {
            return;
        }


        float dTime = GetTime(true) - relPosTime;
        lock (this)
        {
            relPos    += relVel * dTime;
            relPosTime = GetTime(true);
        }

        // TODO: Need to ensure that sound is not played before context is
        // legal
        if (context != sNoContext)
        {
            // Set the position for this context and sound
            OSPManager.SetPositionRel(context, relPos.x, relPos.y, relPos.z);
            //Spatialize (local override of InvSq is passed in)
            OSPManager.Spatialize(context, data, useInverseSquare, falloffNear, falloffFar);
        }
    }
Beispiel #10
0
 // Token: 0x0600376C RID: 14188 RVA: 0x0011B180 File Offset: 0x00119580
 private void UpdateEarlyReflections()
 {
     OSPManager.RoomModel roomModel;
     roomModel.Enable          = this.enableReflections;
     roomModel.ReverbOn        = this.enableReverb;
     roomModel.ReflectionOrder = 0;
     roomModel.DimensionX      = this.dimensions.x;
     roomModel.DimensionY      = this.dimensions.y;
     roomModel.DimensionZ      = this.dimensions.z;
     roomModel.Reflection_K0   = this.rK01.x;
     roomModel.Reflection_K1   = this.rK01.y;
     roomModel.Reflection_K2   = this.rK23.x;
     roomModel.Reflection_K3   = this.rK23.y;
     roomModel.Reflection_K4   = this.rK45.x;
     roomModel.Reflection_K5   = this.rK45.y;
     OSPManager.OSP_UpdateRoomModel(ref roomModel);
 }
Beispiel #11
0
    /// <summary>
    /// Reset cached variables and free the sound context back to OSPManger
    /// </summary>
    private void Release()
    {
        if (!audioSource)
        {
            return;
        }

        // Reset all audio variables that were changed during play
        //audioSource.spatialBlend = panLevel;
        //audioSource.spread   = spread;

        // Put context back into pool
        if (context != sNoContext)
        {
            OSPManager.ReleaseContext(GetInstanceID(), context);
            context = sNoContext;
        }
    }
Beispiel #12
0
    // Token: 0x06003728 RID: 14120 RVA: 0x0011AAB0 File Offset: 0x00118EB0
    private void OnAudioFilterRead(float[] data, int channels)
    {
        if (!this.isPlaying || this.Bypass || OSPManager.GetBypass() || !OSPManager.IsInitialized())
        {
            return;
        }
        float d = this.GetTime(true) - this.relPosTime;

        lock (this)
        {
            this.relPos    += this.relVel * d;
            this.relPosTime = this.GetTime(true);
        }
        if (this.context != -1)
        {
            OSPManager.SetPositionRel(this.context, this.relPos.x, this.relPos.y, this.relPos.z);
            OSPManager.Spatialize(this.context, data, this.useInverseSquare, this.falloffNear, this.falloffFar);
        }
    }
Beispiel #13
0
 // Token: 0x06003722 RID: 14114 RVA: 0x0011A96C File Offset: 0x00118D6C
 public void PlayScheduled(double time)
 {
     if (!this.audioSource)
     {
         Debug.LogWarning("PlayScheduled - Warning: No AudioSource assigned");
         return;
     }
     if (!OSPManager.IsInitialized())
     {
         return;
     }
     this.Acquire();
     this.SetRelativeSoundPos(true);
     this.audioSource.PlayScheduled(time);
     lock (this)
     {
         this.isPlaying = true;
     }
 }
Beispiel #14
0
    //* * * * * * * * * * * * *
    // Private functions
    //* * * * * * * * * * * * *

    /// <summary>
    /// Acquire resources for spatialization
    /// </summary>
    private void Acquire()
    {
        if (!audioSource)
        {
            return;
        }

        // Cache pan and spread
        //panLevel = audioSource.spatialBlend;
        //spread = audioSource.spread;

        // Reserve a context in OSP that will be used for spatializing sound
        // (Don't grab a new one if is already has a context attached to it)
        if (context == sNoContext)
        {
            context = OSPManager.AcquireContext(GetInstanceID());
        }

        // We don't have a context here, so bail
        if (context == sNoContext)
        {
            return;
        }

        // Set pan to full (spread at 180 will keep attenuation curve working, but all 2D
        // panning will be removed)

        // We want to remove FMod curve attenuation if we are doing our
        // own internal calc
        float pl = sSetPanLevel;

        if (OSPManager.GetUseInverseSquareAttenuation() == true)
        {
        }
        //pl = sSetPanLevelInvSq;

        //audioSource.spatialBlend = pl;

        // set spread to 180
        //audioSource.spread = sSetSpread;
    }
    /// <summary>
    /// Updates the local inv sq.
    /// </summary>
    void UpdateLocalInvSq()
    {
        float near = 0.0f;
        float far  = 0.0f;

        // We will set the current sound to the local inverse square value
        if (useInverseSquare == true)
        {
            near = falloffNear;
            far  = falloffFar;
        }
        else
        {
            if (OSPManager.sInstance != null)
            {
                OSPManager.sInstance.GetNearFarFalloffValues(ref near, ref far);
            }
        }

        OSPManager.SetFalloffRangeLocal(context, near, far);
    }
    /// <summary>
    /// Reset cached variables and free the sound context back to OSPManger
    /// </summary>
    private void Release()
    {
        if (!audioSource)
        {
            return;
        }

        // Reset all audio variables that were changed during play
#if (!UNITY5)
        audioSource.spatialBlend = panLevel;
#else
        audioSource.spatialBlend = panLevel;
#endif
        audioSource.spread = spread;

        // Put context back into pool
        if (context != sNoContext)
        {
            OSPManager.ReleaseContext(context);
            context = sNoContext;
        }
    }
Beispiel #17
0
 // Token: 0x06003765 RID: 14181 RVA: 0x0011B127 File Offset: 0x00119527
 public static bool GetUseInverseSquareAttenuation()
 {
     return(OSPManager.OSP_GetUseInverseSquareAttenuation());
 }
Beispiel #18
0
 // Token: 0x06003764 RID: 14180 RVA: 0x0011B120 File Offset: 0x00119520
 public static bool GetBypass()
 {
     return(OSPManager.OSP_GetBypass());
 }
Beispiel #19
0
 // Token: 0x06003719 RID: 14105 RVA: 0x0011A360 File Offset: 0x00118760
 private void Update()
 {
     if (!this.audioSource)
     {
         return;
     }
     if (!this.isPlaying && this.audioSource.isPlaying)
     {
         if (!OSPManager.IsInitialized())
         {
             return;
         }
         this.Acquire();
         this.SetRelativeSoundPos(true);
         lock (this)
         {
             this.isPlaying = true;
         }
         this.drain = false;
     }
     if (this.isPlaying)
     {
         if (!this.audioSource.isPlaying)
         {
             lock (this)
             {
                 this.isPlaying = false;
             }
             this.Release();
             return;
         }
         if (this.Bypass || OSPManager.GetBypass())
         {
             this.audioSource.spatialBlend = this.panLevel;
             this.audioSource.spread       = this.spread;
         }
         else
         {
             float spatialBlend = 1f;
             if (OSPManager.GetUseInverseSquareAttenuation() || this.useInverseSquare)
             {
                 spatialBlend = 0f;
             }
             this.audioSource.spatialBlend = spatialBlend;
             this.audioSource.spread       = 180f;
         }
         if (this.context != -1)
         {
             OSPManager.SetDisableReflectionsOnSound(this.context, this.disableReflections);
         }
         if (this.audioSource.time == 0f && this.audioSource.loop)
         {
             this.SetRelativeSoundPos(false);
         }
         else if (this.audioSource.time >= this.audioSource.clip.length && !this.audioSource.loop)
         {
             this.drainTime = OSPManager.GetDrainTime(this.context);
             this.drain     = true;
         }
         else
         {
             this.SetRelativeSoundPos(false);
         }
         if (this.drain)
         {
             this.drainTime -= Time.deltaTime;
             if (this.drainTime < 0f)
             {
                 this.drain = false;
                 lock (this)
                 {
                     this.isPlaying = false;
                 }
                 this.Stop();
             }
         }
     }
 }
Beispiel #20
0
 // Token: 0x06003762 RID: 14178 RVA: 0x0011B10F File Offset: 0x0011950F
 public static int AcquireContext(int audioSourceInstanceID)
 {
     return(OSPManager.OSP_AcquireContext(audioSourceInstanceID));
 }
	// OnEnable
	void OnEnable()
	{
		m_Component = (OSPManager)target;
	}
Beispiel #22
0
    // * * * * * * * * * * * * *
    // MonoBehaviour overrides

    /// <summary>
    /// Awake this instance.
    /// </summary>
    void Awake()
    {
        // We can only have one instance of OSPManager in a scene (use this for local property query)
        if (sInstance == null)
        {
            sInstance = this;
        }
        else
        {
            Debug.LogWarning(System.String.Format("OSPManager-Awake: Only one instance of OSPManager can exist in the scene."));
            return;
        }

        int samplerate;
        int bufsize;
        int numbuf;

#if (!UNITY5)
        // Used to override samplerate and buffer size with optimal values
        bool setvalues = true;

        // OSX is picky with samplerate and buffer sizes, so leave it alone
#if (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX)
        setvalues = false;
#endif
#endif
        // Get the current sample rate
        samplerate = AudioSettings.outputSampleRate;
        // Get the current buffer size and number of buffers
        AudioSettings.GetDSPBufferSize(out bufsize, out numbuf);

        Debug.LogWarning(System.String.Format("OSP: Queried SampleRate: {0:F0} BufferSize: {1:F0}", samplerate, bufsize));

        // We only know if OpenSL has been enabled if sample rate is 48K.
        // We need to check another setting.
#if (UNITY_ANDROID && !UNITY_EDITOR)
        if ((samplerate == 48000))
        {
            Debug.LogWarning("OSP: Android OpenSL ENABLED (based on 48KHz sample-rate)");
#if (!UNITY5)
            setvalues = false;
#endif
        }
        else
        {
            Debug.LogWarning("OSP: Android OpenSL DISABLED");
        }
#endif

// We will only set values IF we are not Unity 5 (the ability to set DSP settings does not exist)
// NOTE: Unity 4 does not switch DSP buffer sizes using ProjectSettings->Audio, but Unity 5 does.
// At some point along Unity 5 maturity, the functionality to set DSP values directly might be removed.
#if (!UNITY5)
        if (setvalues == true)
        {
// NOTE: When setting DSP values in Unity 4, there may be a situation where using PlayOnAwake on
// non-spatitalized audio objects will fail to play.
// Uncomment this code for achieving the best possibly latency with spatialized audio, but
// USE AT YOUR OWN RISK!

/*
 *                      // Set the ideal sample rate
 *                      AudioSettings.outputSampleRate = SampleRate;
 *                      // Get the sample rate again (it may not take, depending on platform)
 *                      samplerate = AudioSettings.outputSampleRate;
 *                      // Set the ideal buffer size
 *                      AudioSettings.SetDSPBufferSize (BufferSize, numbuf);
 *                      // Get the current buffer size and number of buffers again
 *                      AudioSettings.GetDSPBufferSize (out bufsize, out numbuf);
 */
        }
#endif

        Debug.LogWarning(System.String.Format("OSP: sample rate: {0:F0}", samplerate));
        Debug.LogWarning(System.String.Format("OSP: buffer size: {0:F0}", bufsize));
        Debug.LogWarning(System.String.Format("OSP: num buffers: {0:F0}", numbuf));

        sOSPInit = OSP_Init(samplerate, bufsize);

        // Set global variables not set to dirty updates
        OSP_SetBypass(bypass);
        OSP_SetUseSimple(useSimple);
        OSP_SetGlobalScale(globalScale);
        OSP_SetGain(gain);
        OSP_SetFalloffRangeGlobal(falloffNear, falloffFar);

        // Update reflections for the first time
        dirtyReflection = true;
    }
Beispiel #23
0
 // Token: 0x06003763 RID: 14179 RVA: 0x0011B117 File Offset: 0x00119517
 public static void ReleaseContext(int audioSourceInstanceID, int context)
 {
     OSPManager.OSP_ReturnContext(audioSourceInstanceID, context);
 }
Beispiel #24
0
 // Token: 0x0600376A RID: 14186 RVA: 0x0011B16D File Offset: 0x0011956D
 public static void SetFalloffRangeLocal(int contextAndSound, float nearRange, float farRange)
 {
     OSPManager.OSP_SetFalloffRangeLocal(contextAndSound, nearRange, farRange);
 }
Beispiel #25
0
 // Token: 0x06003766 RID: 14182 RVA: 0x0011B12E File Offset: 0x0011952E
 public static void SetDisableReflectionsOnSound(int context, bool disable)
 {
     OSPManager.OSP_SetDisableReflectionsOnSound(context, disable);
 }
Beispiel #26
0
 // Token: 0x0600376B RID: 14187 RVA: 0x0011B177 File Offset: 0x00119577
 public static int GetMaxNumSpatializedSources()
 {
     return(OSPManager.OSP_GetMaxNumSpatializedSounds());
 }
    /// <summary>
    /// Update this instance.
    /// </summary>
    void Update()
    {
        if (!audioSource)
        {
            return;
        }

        // If user called Play on the acutal AudioSource, account for this
        // NOTE: There may be a potential issue with calling AudioSource.Stop on a
        // looping sound, since the Update may not catch this. We might need to catch
        // this edge case at some point; a one-shot sound will stop automatically and
        // return spatialization resources.
        if ((isPlaying == false) && (audioSource.isPlaying))
        {
            // This is a copy of OSPAudioSource Play function, minus
            // calling Play on audio source since it's already been called

            // Bail if manager has not even started
            if (OSPManager.IsInitialized() == false)
            {
                return;
            }

            // We will grab a context at this point, and set the right values
            // to allow for spatialization to take effect
            Aquire();

            // We will set the relative position of this sound now before we start playing
            SetRelativeSoundPos(true);

            // We are ready to play the sound
            // Commented out, kept for readability
            // audioSource.Play();

            lock (this) isPlaying = true;
        }

        // If sound is playing on it's own and dies off, we need to
        // Reset
        if (isPlaying == true)
        {
            // If we stopped the sound using AudioSource, Release resources
            if (audioSource.isPlaying == false)
            {
                lock (this) isPlaying = false;
                Release();
                return;
            }

            // We will go back and forth between spatial processing
            // and native 2D panning
            if ((Bypass == true) || (OSPManager.GetBypass() == true))
            {
#if (!UNITY5)
                audioSource.spatialBlend = panLevel;
#else
                audioSource.spatialBlend = panLevel;
#endif
                audioSource.spread = spread;
            }
            else
            {
                // We want to remove FMod curve attenuation if we are doing our
                // own internal calc
                float pl = sSetPanLevel;
                if (OSPManager.GetUseInverseSquareAttenuation() == true)
                {
                    pl = sSetPanLevelInvSq;
                }
#if (!UNITY5)
                audioSource.spatialBlend = pl;
#else
                audioSource.spatialBlend = pl;
#endif
                audioSource.spread = sSetSpread;
            }

            // Update FrequencyHints and local reflection enable/disable
            if (context != sNoContext)
            {
                OSPManager.SetFrequencyHint(context, frequencyHint);
                OSPManager.SetDisableReflectionsOnSound(context, disableReflections);
            }

            // return the context when the sound has finished playing
            if ((audioSource.time >= audioSource.clip.length) && (audioSource.loop == false))
            {
                // One last pass to allow for the tail portion of the sound
                // to finish
                drainTime = OSPManager.GetDrainTime(context);
                drain     = true;
            }
            else
            {
                // We must set all positional properties here, not in
                // OnAudioFilterRead. We might consider a better approach
                // to interpolate the current location for better localization,
                // should the resolution of setting it here sound jittery due
                // to thread frequency mismatch.
                SetRelativeSoundPos(false);

#if DEBUG_AudioSource
                // Time main thread and audio thread
                if (debugOn)
                {
                    // Get audio frequency
                    if (audioFrames == 0)
                    {
                        float ct = 1.0f / (GetTime(false) - dTimeMainLoop);
                        Debug.LogWarning(System.String.Format("U: {0:F0}", ct));
                        ct = 100.0f / (GetTime(true) - PrevAudioTime);
                        Debug.LogWarning(System.String.Format("A: {0:F0}", ct));
                        audioFrames   = 100;
                        PrevAudioTime = (float)GetTime(true);
                    }

                    dTimeMainLoop = (float)GetTime(false);
                }
#endif
            }

            if (drain == true)
            {
                // Keep playing until we safely drain out the early reflections
                drainTime -= Time.deltaTime;
                if (drainTime < 0.0f)
                {
                    drain = false;

                    lock (this) isPlaying = false;
                    // Stop will both stop audio from playing (keeping OnAudioFilterRead from
                    // running with a held audio source) as well as release the spatialization
                    // resources via Release()
                    Stop();
                }
            }
        }
    }
Beispiel #28
0
	// * * * * * * * * * * * * *
	// MonoBehaviour overrides

	/// <summary>
	/// Awake this instance.
	/// </summary>
	void Awake () 
	{	
		// We can only have one instance of OSPManager in a scene (use this for local property query)
		if(sInstance == null)
		{
			sInstance = this;
		}
		else
		{
			Debug.LogWarning (System.String.Format ("OSPManager-Awake: Only one instance of OSPManager can exist in the scene."));
			return;
		}

		int samplerate;
		int bufsize;
		int numbuf;

#if (!UNITY5)
		// Used to override samplerate and buffer size with optimal values
		bool setvalues = true;

		// OSX is picky with samplerate and buffer sizes, so leave it alone
#if (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX)
		setvalues = false;
#endif
#endif
		// Get the current sample rate
		samplerate = AudioSettings.outputSampleRate;
		// Get the current buffer size and number of buffers
		AudioSettings.GetDSPBufferSize (out bufsize, out numbuf);

		Debug.LogWarning (System.String.Format ("OSP: Queried SampleRate: {0:F0} BufferSize: {1:F0}", samplerate, bufsize));

		// We only know if OpenSL has been enabled if sample rate is 48K. 
		// We need to check another setting. 
#if (UNITY_ANDROID && !UNITY_EDITOR)
		if((samplerate == 48000))
		{
			Debug.LogWarning("OSP: Android OpenSL ENABLED (based on 48KHz sample-rate)");
#if (!UNITY5)
			setvalues = false;
#endif
		}
		else
		{
			Debug.LogWarning("OSP: Android OpenSL DISABLED");
		}
#endif

// We will only set values IF we are not Unity 5 (the ability to set DSP settings does not exist)
// NOTE: Unity 4 does not switch DSP buffer sizes using ProjectSettings->Audio, but Unity 5 does.
// At some point along Unity 5 maturity, the functionality to set DSP values directly might be removed.
#if (!UNITY5)
		if(setvalues == true)
		{
// NOTE: When setting DSP values in Unity 4, there may be a situation where using PlayOnAwake on 
// non-spatitalized audio objects will fail to play.
// Uncomment this code for achieving the best possibly latency with spatialized audio, but
// USE AT YOUR OWN RISK!
/*
			// Set the ideal sample rate
			AudioSettings.outputSampleRate = SampleRate;
			// Get the sample rate again (it may not take, depending on platform)
			samplerate = AudioSettings.outputSampleRate;
			// Set the ideal buffer size
			AudioSettings.SetDSPBufferSize (BufferSize, numbuf);
			// Get the current buffer size and number of buffers again
			AudioSettings.GetDSPBufferSize (out bufsize, out numbuf);
*/
	}
#endif

		Debug.LogWarning (System.String.Format ("OSP: sample rate: {0:F0}", samplerate));
		Debug.LogWarning (System.String.Format ("OSP: buffer size: {0:F0}", bufsize));
		Debug.LogWarning (System.String.Format ("OSP: num buffers: {0:F0}", numbuf));

		sOSPInit = OSP_Init(samplerate, bufsize);

		// Set global variables not set to dirty updates
		OSP_SetBypass             (bypass);
		OSP_SetGlobalScale        (globalScale);
		OSP_SetGain               (gain);
		OSP_SetFalloffRangeGlobal (falloffNear, falloffFar);

		// Update reflections for the first time
		dirtyReflection = true;
	}
Beispiel #29
0
 /// <summary>
 /// Sets the reflection values. This is done when exiting a zone (use popped values).
 /// </summary>
 /// <param name="rm">Rm.</param>
 void SetReflectionValues(ref OSPManager.RoomModel rm)
 {
     OSPManager.sInstance.Dimensions = new Vector3(rm.DimensionX, rm.DimensionY, rm.DimensionZ);
     OSPManager.sInstance.RK01       = new Vector3(rm.Reflection_K0, rm.Reflection_K1);
     OSPManager.sInstance.RK23       = new Vector3(rm.Reflection_K2, rm.Reflection_K3);
     OSPManager.sInstance.RK45       = new Vector3(rm.Reflection_K4, rm.Reflection_K5);
 }
 // OnEnable
 void OnEnable()
 {
     m_Component = (OSPManager)target;
 }
Beispiel #31
0
 // Token: 0x06003767 RID: 14183 RVA: 0x0011B137 File Offset: 0x00119537
 public static float GetDrainTime(int context)
 {
     return(OSPManager.OSP_GetDrainTime(context));
 }