Example #1
0
 /* returns the milliseconds remaining until the timer fires,
  * and deactivates itself if the value <= 0.
  */
 internal int GetRemainingMillisToFireTime()
 {
     if (m_isSet && !m_isPaused)
     {
         return(m_estimatedFireTime - Logik.GetTimestampMillisElapsedSinceInitialisation());
     }
     else
     {
         return(999999);
     }
 }
Example #2
0
 // returns true if the timer is Set and the Threshold has been reached, false otherwise.
 internal bool ThresholdHasBeenReached()
 {
     if (m_isSet && !m_isPaused)
     {
         return(Logik.GetTimestampMillisElapsedSinceInitialisation() >= m_estimatedThresholdReachedTime);
     }
     else
     {
         return(false);
     }
 }
Example #3
0
        // this will play back the requested Snippet in delayInMilliseconds.
        // Playback of a scheduled Snippet cannot be canceled.
        internal void ScheduleSegmentPlayback(Segment snippet, int delayInMilliseconds)
        {
            #if !(PSAI_NOLOG)
            {
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("ScheduleSegmentPlayback() Segment=");
                    sb.Append(snippet.Name);
                    sb.Append("  delayInMilliseconds=");
                    sb.Append(delayInMilliseconds);
                    Logger.Instance.Log(sb.ToString(), LogLevel.debug);
                }
            }
            #endif


            if (delayInMilliseconds < 0)
            {
                #if !(PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("delayInMilliseconds was negative, thus set to 0", LogLevel.debug);
                }
                #endif
                delayInMilliseconds = 0;
            }

            if (snippet != Segment)
            {
                LoadSegment(snippet);
            }

            m_stoppedExplicitly        = false;
            m_playbackIsScheduled      = true;
            m_timeStampOfPlaybackStart = Logik.GetTimestampMillisElapsedSinceInitialisation() + delayInMilliseconds;


            if (m_audioPlaybackLayerChannel != null)
            {
                m_audioPlaybackLayerChannel.ScheduleSegmentPlayback(snippet, delayInMilliseconds);
            }
            else
            {
                #if !(PSAI_NOLOG)
                {
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("m_audioPlaybackLayerChannel is null!", LogLevel.errors);
                    }
                }
                #endif
            }
        }
Example #4
0
        internal void LoadSegment(Segment snippet)
        {
            Segment = snippet;
            m_timeStampOfSnippetLoad = Logik.GetTimestampMillisElapsedSinceInitialisation();
            m_playbackIsScheduled    = false;
            m_stoppedExplicitly      = false;

            if (m_audioPlaybackLayerChannel != null)
            {
                m_audioPlaybackLayerChannel.LoadSegment(snippet);
            }
        }
Example #5
0
        PsaiResult IAudioPlaybackLayerChannel.ScheduleSegmentPlayback(Segment segment, int delayMilliseconds)
        {
            if (_segmentToLoad != null && _segmentToLoad.Id == segment.Id)
            {
                bool readyToPlay = IsReadyToPlay();

                #if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log(string.Format("ScheduleSegmentPlayback() Segment: {0}  isReadyToPlay: {1}", segment.Name, readyToPlay), LogLevel.debug);
                }
                #endif

                // new method PlayDelayed introduced in Unity Version 4.1.0.
                if (readyToPlay)
                {
                    PlayBufferedClip(delayMilliseconds);

                    #if (!PSAI_NOLOG)
                    if (LogLevel.debug <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log(string.Format("_audioSource.PlayDelayed() fired, delayInMs:{0}", delayMilliseconds), LogLevel.debug);
                    }
                    #endif

                    return(PsaiResult.OK);
                }
                else
                {
                    TargetPlaybackTimestamp = Logik.GetTimestampMillisElapsedSinceInitialisation() + delayMilliseconds;
                    PlaybackIsPending       = true;

                    #if (!PSAI_NOLOG)
                    if (LogLevel.debug <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("... play has not fired yet, PlaybackIsPending is now set to true.  TargetPlaybackTimestamp=" + TargetPlaybackTimestamp, LogLevel.debug);
                    }
                    #endif
                }

                return(PsaiResult.OK);
            }
            else
            {
                Logger.Instance.Log("ScheduleSegmentPlayback(): COULD NOT PLAY! No Segment loaded, or Segment Id to play did not match! Segment loaded: " + _segmentToLoad, LogLevel.errors);
            }

            return(PsaiResult.notReady);
        }
Example #6
0
        internal void Log(string argText, LogLevel logLevel)
        {
            if (logLevel <= LogLevel)
            {
                StringBuilder sb = new StringBuilder();

                sb.Append("[");
                sb.Append(Logik.GetTimestampMillisElapsedSinceInitialisation().ToString());
                sb.Append("]");

                switch (logLevel)
                {
                case LogLevel.info:
                    sb.Append("[INFO]: ");
                    break;

                case LogLevel.warnings:
                    sb.Append("[WARNING]: ");
                    break;

                case LogLevel.errors:
                    sb.Append("[ERROR]:");
                    break;

                case LogLevel.debug:
                    sb.Append("     [INTERNAL]: ");
                    break;
                }
                sb.Append(argText);


                WriteToLoggerOutputs(sb.ToString(), logLevel);


                if (logLevel == LogLevel.warnings || logLevel == LogLevel.errors)
                {
                    if (m_lastErrorStringBuilder == null || m_lastErrorNewMessageAvailable == false)
                    {
                        m_lastErrorStringBuilder = new StringBuilder();
                    }

                    m_lastErrorStringBuilder.AppendLine(argText);
                    m_lastErrorNewMessageAvailable = true;
                }
            }
        }
Example #7
0
        internal void SetPaused(bool setPaused)
        {
            if (m_isSet)
            {
                if (setPaused)
                {
                    if (!m_isPaused)
                    {
                        m_isPaused             = true;
                        m_timerPausedTimestamp = Logik.GetTimestampMillisElapsedSinceInitialisation();
                    }
                }
                else
                {
                    if (m_isPaused)
                    {
                        m_isPaused = false;

                        int timePausedPeriod = Logik.GetTimestampMillisElapsedSinceInitialisation() - m_timerPausedTimestamp;
                        m_estimatedFireTime             += timePausedPeriod;
                        m_estimatedThresholdReachedTime += timePausedPeriod;


#if !(PSAI_NOLOG)
                        if (LogLevel.debug <= Logger.Instance.LogLevel)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append("timePausedPeriod=");
                            sb.Append(timePausedPeriod);
                            sb.Append("   m_estimatedFireTime=");
                            sb.Append(m_estimatedFireTime);
                            sb.Append("   estimatedThresholdReachedTime=");
                            sb.Append(m_estimatedThresholdReachedTime);

                            Logger.Instance.Log(sb.ToString(), LogLevel.debug);
                        }
#endif
                    }
                }
            }
        }
Example #8
0
        /** Sets the timer.
         * /* @param delayMillis - the milliseconds from now, when the timer should report fired.
         * @param remainingThresholdMilliseconds - the milliseconds backwards from the firing time,
         *  when the method ThresholdHasBeenReached() shall reports true. Pass 0 if not needed.
         */
        internal void SetTimer(int delayMillis, int remainingThresholdMilliseconds)
        {
            m_estimatedFireTime             = Logik.GetTimestampMillisElapsedSinceInitialisation() + delayMillis;
            m_estimatedThresholdReachedTime = m_estimatedFireTime - remainingThresholdMilliseconds;

            m_isSet = true;

            #if !(PSAI_NOLOG)
            {
                /*
                 * if (LogLevel.debug <= Logger.Instance.LogLevel)
                 * {
                 *      StringBuilder sb = new StringBuilder();
                 *      sb.Append("SetTimer() delay=");
                 *      sb.Append(delayMillis);
                 *      sb.Append("  estimatedFireTime=");
                 *      sb.Append(m_estimatedFireTime);
                 *      Logger.Instance.Log(sb.ToString(), psaiCoreDotNet.LogLevel.debug);
                 * }
                 */
            }
            #endif
        }
Example #9
0
        private IEnumerator LoadSegmentAsync_Coroutine(AudioPlaybackLayerChannelUnity audioPlaybackChannel)
        {
            ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClip, typeof(AudioClip));

            yield return(request);

            #if (!PSAI_NOLOG)
            if (LogLevel.debug <= Logger.Instance.LogLevel)
            {
                string logMessage = "LoadSegmentAsync_Coroutine complete, asset=" + request.asset.name;
                logMessage += "  PlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending + "   audioPlaybackChannel.GetHashCode()" + audioPlaybackChannel.GetHashCode();
                Logger.Instance.Log(logMessage, LogLevel.debug);
            }
            #endif

            AudioClip clip = request.asset as AudioClip;

            if (clip == null)
            {
                #if (!PSAI_NOLOG)
                if (LogLevel.errors <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("The AudioClip '" + audioPlaybackChannel.PathToClip + "' was not found!", LogLevel.errors);
                }
                #endif
            }
            else
            {
                audioPlaybackChannel.AudioClip = clip;
                audioPlaybackChannel.AudioClip.LoadAudioData();
            }


            if (audioPlaybackChannel.PlaybackIsPending)
            {
                while (!audioPlaybackChannel.IsReadyToPlay())
                {
                    yield return(null);

                    #if (!PSAI_NOLOG)
                    if (LogLevel.debug <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("Playback is pending but AudioClip is not ready to play!", LogLevel.debug);
                    }
                    #endif
                }

                int delayMillis = audioPlaybackChannel.TargetPlaybackTimestamp - Logik.GetTimestampMillisElapsedSinceInitialisation();

                if (delayMillis < 0 && Time.timeSinceLevelLoad > 1.0f)
                {
                    #if (!PSAI_NOLOG)
                    if (LogLevel.warnings <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log(string.Format("playback timing problem detected! Missing milliseconds: {0} ", delayMillis), LogLevel.warnings);
                    }

                    if (clip.loadType == AudioClipLoadType.Streaming)
                    {
                        Logger.Instance.Log("Please note: playback timing problems may occur when starting a Scene or when the Log Output in the PsaiCoreManager is set to Debug. If the warning shows up frequently during the game, please increase the 'Max Playback Latency' in PsaiCoreManager for the current target platform.", LogLevel.warnings);
                    }
                    else
                    {
                        Logger.Instance.Log("We highly recommend setting the 'Load Type' of all psai Audio Clips to 'Streaming'.", LogLevel.warnings);
                    }
                    #endif
                }

                audioPlaybackChannel.PlayBufferedClip(delayMillis);
            }
        }
Example #10
0
 // returns the remaining milliseconds until playback start
 internal int GetCountdownToPlaybackInMilliseconds()
 {
     return(m_timeStampOfPlaybackStart - Logik.GetTimestampMillisElapsedSinceInitialisation());
 }
Example #11
0
 internal int GetMillisecondsSinceSegmentLoad()
 {
     return(Logik.GetTimestampMillisElapsedSinceInitialisation() - m_timeStampOfSnippetLoad);
 }