internal void CreateInternalPlayback(SoundToolKitPlayback playback)
        {
            if (playback.SoundToolKitSample == null)
            {
                return;
            }

            if (m_source != null)
            {
                var resourcesFactory = SoundToolKitManager.Instance.StkAudioEngine.ResourcesFactory;
                var samplesBuffer    = playback.SoundToolKitSample.GetSamplesBuffer();

                SoundToolKitDebug.Assert(samplesBuffer != null, "SamplesBuffer is missing. Logical error.");
                SoundToolKitDebug.Assert(samplesBuffer.Length > 0, "SamplesBuffer doesn't have samples.");

                var playbackSample = resourcesFactory.CreateSampleStatic(samplesBuffer, playback.SoundToolKitSample.AudioClip.channels);

                if (playback.Looped)
                {
                    playback.Playback = resourcesFactory.CreatePlayback(playbackSample, m_source, new PlaybackParameters(0, 1, PlaybackParameters.Looped));
                }
                else
                {
                    playback.Playback = resourcesFactory.CreatePlayback(playbackSample, m_source);
                }

                playback.Playback.OnDispose += (sender, e) =>
                {
                    playbackSample.Dispose();
                };

                playback.Name = playback.SoundToolKitSample.name;
            }
        }
        internal void StartPlayback(SoundToolKitPlayback playback)
        {
            if (playback.Playback == null)
            {
                CreateInternalPlayback(playback);
            }

            if (!playback.IsPlaying)
            {
                playback.Playback.Play();
            }
        }
Exemple #3
0
        public void Remove(SoundToolKitPlayback playback)
        {
            SoundToolKitDebug.Assert(playback != null, "Playback is null");

            if (Playbacks.Contains(playback))
            {
                m_playbacks.Remove(playback);
            }
            else
            {
                SoundToolKitDebug.LogWarning("Playback wasn't registered.");
            }
        }
Exemple #4
0
        public void Add(SoundToolKitPlayback playback)
        {
            // <STK.LITE> - What's the point of it all?
            if (Playbacks.Count >= StkLite.AvailableSources())
            {
                return;
            }
            // </STK.LITE>

            SoundToolKitDebug.Assert(playback != null, "Playback is null");

            if (!Playbacks.Contains(playback))
            {
                m_playbacks.Add(playback);
            }
            else
            {
                SoundToolKitDebug.LogWarning("Playback already registered.");
            }
        }
        internal void SynchronizePlaybackSamples(SoundToolKitPlayback playback)
        {
#if UNITY_EDITOR
            if (UnityEditor.EditorApplication.isPlaying && SoundToolKitManager.Instance.Initialized)
            {
                if (playback.Playback != null && playback.SoundToolKitSample == null)
                {
                    playback.Playback = null;
                    playback.Name     = "Not Initialized";
                }
                else if (playback.SoundToolKitSample != null && playback.Name != playback.SoundToolKitSample.name)
                {
                    CreateInternalPlayback(playback);

                    if (playback.Playback != null && playback.AutoPlay)
                    {
                        playback.Playback.Play();
                    }
                }
            }
#endif
        }
Exemple #6
0
 private void OnPlaybackEnded(SoundToolKitPlayback playback)
 {
     playback.Playback = null;
 }