示例#1
0
    // Cache sound methods

    /**
     * Cache the sound for speedy playback.
     * If a callback is passed in, the caching will be done asynchronously, taking maxTimePerFrame milliseconds
     * per frame to cache, them calling the callback when it's done.
     * If not, the whole sound is cached immediately - can freeze the player for a few seconds, especially in debug mode.
     * @param   callback            Function to call when the caching is complete
     * @param   maxTimePerFrame     Maximum time in milliseconds the caching will use per frame
     */
    public void CacheSound(Action __callback = null, bool __isFromCoroutine = false)
    {
        Stop();

        if (_cachingAsync && !__isFromCoroutine)
        {
            return;
        }

        if (__callback != null)
        {
            _mutation      = false;
            _cachingNormal = true;
            _cachingAsync  = true;

            GameObject         _surrogateObj = new GameObject("SfxrGameObjectSurrogate-" + (Time.realtimeSinceStartup));
            SfxrCacheSurrogate _surrogate    = _surrogateObj.AddComponent <SfxrCacheSurrogate>();
            _surrogate.CacheSound(this, __callback);
        }
        else
        {
            Reset(true);

            _cachedWave = new float[_envelopeFullLength];

            SynthWave(_cachedWave, 0, _envelopeFullLength);

            _cachingNormal = false;
            _cachingAsync  = false;
        }
    }
示例#2
0
    /**
     * Caches a series of mutations on the source sound.
     * If a callback is passed in, the caching will be done asynchronously, taking maxTimePerFrame milliseconds
     * per frame to cache, them calling the callback when it's done.
     * If not, the whole sound is cached immediately - can freeze the player for a few seconds, especially in debug mode.
     * @param   mutationsNum        Number of mutations to cache
     * @param   mutationAmount      Amount of mutation
     * @param   callback            Function to call when the caching is complete
     * @param   maxTimePerFrame     Maximum time in milliseconds the caching will use per frame
     */
    public void CacheMutations(uint __mutationsNum = 15, float __mutationAmount = 0.05f, Action __callback = null, bool __isFromCoroutine = false)
    {
        Stop();

        if (_cachingAsync && !__isFromCoroutine)
        {
            return;
        }

        _cachedMutationsNum = __mutationsNum;
        _cachedMutations    = new float[_cachedMutationsNum][];

        if (__callback != null)
        {
            _mutation     = true;
            _cachingAsync = true;

            GameObject         _surrogateObj = new GameObject("SfxrGameObjectSurrogate-" + (Time.realtimeSinceStartup));
            SfxrCacheSurrogate _surrogate    = _surrogateObj.AddComponent <SfxrCacheSurrogate>();
            _surrogate.CacheMutations(this, __mutationsNum, __mutationAmount, __callback);
        }
        else
        {
            Reset(true);

            SfxrParams original = _params.Clone();

            for (uint i = 0; i < _cachedMutationsNum; i++)
            {
                _params.Mutate(__mutationAmount);
                CacheSound();
                _cachedMutations[i] = _cachedWave;
                _params.CopyFrom(original);
            }

            _cachingAsync    = false;
            _cachingMutation = -1;
        }
    }