Example #1
0
 protected void RaiseStateChangeEvent(AudioStates oldState, AudioStates newState)
 {
     if (OnStateChanged != null)
     {
         OnStateChanged(this, oldState, newState);
     }
 }
    void AudioTester()
    {
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            thisSource.loop = true;
            thisSource.clip = WalkClip;
            thisSource.Play();
            currentAudio = AudioStates.Walking;
        }
        if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            thisSource.loop = true;
            thisSource.clip = RunClip;
            thisSource.Play();
            currentAudio = AudioStates.Running;
        }
        if (Input.GetKeyDown(KeyCode.Keypad4))
        {
            thisSource.loop = false;
            thisSource.clip = AlertClip;
            thisSource.Play();

            Alerted = true;
            //EnviromentalSource.Stop();

            currentAudio = AudioStates.Alert;
        }
        if (Input.GetKeyDown(KeyCode.Keypad7))
        {
            thisSource.Stop();
            thisSource.clip = null;
        }
    }
Example #3
0
        /// <summary>
        /// Copies another AudioItem.
        /// </summary>
        /// <param name="reference"> The AudioItem to copy. </param>
        public void Copy(AudioItemBase reference)
        {
            identifier      = reference.identifier;
            itemManager     = reference.itemManager;
            state           = reference.state;
            spatializer     = reference.spatializer;
            parent          = reference.parent;
            scheduledTime   = reference.scheduledTime;
            scheduleStarted = reference.scheduleStarted;
            volumeModifier.Copy(reference.volumeModifier);
            pitchModifier.Copy(reference.pitchModifier);
            rampVolumeTweener.Copy(reference.rampVolumeTweener);
            rampParentVolumeTweener.Copy(reference.rampParentVolumeTweener);
            rampPitchTweener.Copy(reference.rampPitchTweener);
            rampParentPitchTweener.Copy(reference.rampParentPitchTweener);
            fadeTweener.Copy(reference.fadeTweener);
            pausedState = reference.pausedState;
            hasFaded    = reference.hasFaded;
            hasBreak    = reference.hasBreak;
            Copier <AudioDelayedOption> .Default.CopyTo(reference.delayedOptions, delayedOptions);

            OnPlay         = reference.OnPlay;
            OnPause        = reference.OnPause;
            OnResume       = reference.OnResume;
            OnStopping     = reference.OnStopping;
            OnStop         = reference.OnStop;
            OnUpdate       = reference.OnUpdate;
            OnStateChanged = reference.OnStateChanged;
        }
Example #4
0
        internal static void seekTo(int milliseconds)
        {
            if (milliseconds < 0)
            {
                milliseconds = 0;
            }
            else if (milliseconds > AudioLength)
            {
                milliseconds = AudioLength;
            }

            if (AudioState != AudioStates.Stopped)
            {
                if (Math.Abs(milliseconds - Time) > 200)
                {
                    Bass.BASS_ChannelSetPosition(audioStream, (float)(milliseconds + Offset) / 1000);
                }
                AudioState = AudioStates.Seeking;
            }
            else
            {
                cachedSeek = milliseconds + Offset;
            }

            //Time = milliseconds;
            UpdateAudioTime();
        }
Example #5
0
        internal static void Play()
        {
            checkCachedSeek();

            Bass.BASS_ChannelPlay(audioStream, true);
            AudioState = AudioStates.Seeking;
        }
Example #6
0
 protected AudioItem(string name, int id, float volume, float pitch, AudioStates state, AudioItemManager itemManager, Magicolo.AudioTools.Player player)
 {
     this.Name        = name;
     this.Id          = id;
     this.Volume      = volume;
     this.Pitch       = pitch;
     this.State       = state;
     this.itemManager = itemManager;
     this.player      = player;
 }
Example #7
0
 protected AudioItem(string name, int id, AudioItemManager itemManager, Magicolo.AudioTools.Player player)
 {
     this.Name        = name;
     this.Id          = id;
     this.Volume      = 1;
     this.Pitch       = 1;
     this.State       = AudioStates.Waiting;
     this.itemManager = itemManager;
     this.player      = player;
 }
Example #8
0
 public PDEditorModule(string name, AudioStates state, float volume, GameObject source, PDSpatializer.RolloffMode volumeRolloff, float minDistance, float maxDistance, float panLevel)
 {
     this.name          = name;
     this.state         = state;
     this.volume        = volume;
     this.source        = source;
     this.volumeRolloff = volumeRolloff;
     this.minDistance   = minDistance;
     this.maxDistance   = maxDistance;
     this.panLevel      = panLevel;
 }
Example #9
0
 public override void Pause()
 {
     if (State == AudioStates.Playing || State == AudioStates.FadingIn)
     {
         audioSource.Pause();
         coroutineHolder.PauseCoroutines("FadeIn");
         coroutineHolder.PauseCoroutines("RampVolume");
         coroutineHolder.PauseCoroutines("RampPitch");
         pausedState = State;
         base.Pause();
     }
 }
Example #10
0
 internal static bool Pause()
 {
     if (BASSActive.BASS_ACTIVE_PLAYING == Bass.BASS_ChannelIsActive(audioStream))
     {
         Bass.BASS_ChannelPause(audioStream);
         AudioState = AudioStates.Stopped;
         return(true);
     }
     else
     {
         checkCachedSeek();
         Bass.BASS_ChannelPlay(audioStream, false);
         AudioState = AudioStates.Seeking;
         return(false);
     }
 }
Example #11
0
    GUIStyle GetStateColorStyle()
    {
        if (Application.isPlaying)
        {
            GUIStyle style = new GUIStyle("foldout");
            style.fontStyle = FontStyle.Bold;
            Color       textColor = style.normal.textColor;
            AudioStates state     = currentModule.State;

            switch (state)
            {
            case AudioStates.FadingIn:
                textColor = new Color(1, 1, 0, 1);
                break;

            case AudioStates.FadingOut:
                textColor = new Color(1, 1, 0.5F, 1);
                break;

            case AudioStates.Paused:
                textColor = new Color(0, 0, 1, 1);
                break;

            case AudioStates.Playing:
                textColor = new Color(0, 1, 0, 1);
                break;

            case AudioStates.Waiting:
                textColor = new Color(1, 0, 0, 1);
                break;

            case AudioStates.Stopped:
                textColor = new Color(1, 0, 0, 1);
                break;
            }

            style.normal.textColor    = textColor * 0.8F;
            style.onNormal.textColor  = textColor * 0.8F;
            style.focused.textColor   = textColor;
            style.onFocused.textColor = textColor;
            style.active.textColor    = textColor;
            style.onActive.textColor  = textColor;
            return(style);
        }

        return(new GUIStyle("foldout"));
    }
Example #12
0
        internal static void UpdateAudioTime()
        {
            audioTimeRaw = Bass.BASS_ChannelGetPosition(audioStream);


            //force a stopped state when reaching end of song
            if (AudioState != AudioStates.Stopped && audioTimeRaw == audioLengthRaw)
            {
                AudioState = AudioStates.Stopped;
            }

            if (cachedSeek >= 0)
            {
                audioTime = (float)(cachedSeek) / 1000;
            }
            else if (audioStream != 0)
            {
                audioTime = Bass.BASS_ChannelBytes2Seconds(audioStream, audioTimeRaw);
            }
            else
            {
                audioTime = 0;
            }


            TimeRaw = (int)Math.Round(audioTime * 1000);

            Offset = BeatmapManager.Current != null && BeatmapManager.Current.BeatmapVersion < 5 &&
                     GameBase.Mode != Modes.Edit
                         ? 24
                         : 0;
            Offset += GameBase.Mode != Modes.Edit && BeatmapManager.Current != null
                          ? BeatmapManager.Current.PlayerOffset
                          : 0;
            if (audioRate < 100)
            {
                Offset -= (int)(((100 - audioRate) / 75f) * 30);
            }

            Offset -= (int)((audioRate / 100f) * ConfigManager.sOffset);

            if (UpdateTime)
            {
                Time = TimeRaw - Offset;
            }
        }
Example #13
0
    void MoveToNextState()
    {
        AudioStates curState = audioStates;

        stateElapsed = 0;

        switch (curState)
        {
        case AudioStates.Initial:
            if (audioCfg.FadeIn > 0)
            {
                audioStates        = AudioStates.FadeIn;
                audioSource.volume = 0;
            }
            else
            {
                audioStates        = AudioStates.Playing;
                audioSource.volume = audioCfg.Volume;
            }
            break;

        case AudioStates.FadeIn:
            audioStates        = AudioStates.Playing;
            audioSource.volume = audioCfg.Volume;

            break;

        case AudioStates.Playing:
            if (audioCfg.FadeOut > 0)
            {
                audioStates = AudioStates.FadeOut;
            }
            else
            {
                audioStates = AudioStates.Expired;
                Disable();
            }

            break;

        case AudioStates.FadeOut:
            audioStates = AudioStates.Expired;
            Disable();
            break;
        }
    }
Example #14
0
    private void MoveToNextState()
    {
        AudioStates curState = this.state;

        stateElapsed = 0;

        switch (curState)
        {
        case AudioStates.Initial:
            if (config.FadeIn > 0)
            {
                state = AudioStates.FadeIn;
                audioSource.volume = 0;
            }
            else
            {
                state = AudioStates.Playing;
                audioSource.volume = 1;
            }
            break;

        case AudioStates.FadeIn:
            state = AudioStates.Playing;
            audioSource.volume = 1;

            break;

        case AudioStates.Playing:
            if (config.FadeOut > 0)
            {
                state = AudioStates.FadeOut;
            }
            else
            {
                state = AudioStates.Expired;
                Disable();
            }

            break;

        case AudioStates.FadeOut:
            state = AudioStates.Expired;
            Disable();
            break;
        }
    }
Example #15
0
        public void UpdateState(AudioStates newState)
        {
            MediaPlayer.Stop();

            switch (newState)
            {
            case AudioStates.InWave:
                MediaPlayer.Play(wave);
                break;

            case AudioStates.BetweenWave:
                MediaPlayer.Play(between);
                break;
            }

            MediaPlayer.Volume      = 0.3f;
            MediaPlayer.IsRepeating = true;
            audioState = newState;
        }
Example #16
0
        internal bool TogglePause()
        {
            if (IsDisposed)
            {
                return(false);
            }

            if (BASSActive.BASS_ACTIVE_PLAYING == Bass.BASS_ChannelIsActive(audioStream))
            {
                Bass.BASS_ChannelPause(audioStream);
                State = AudioStates.Stopped;
                return(true);
            }
            else
            {
                Bass.BASS_ChannelPlay(audioStream, false);
                State = AudioStates.Playing;
                return(false);
            }
        }
Example #17
0
        protected override void Dispose(bool disposing)
        {
            if (audioStream != 0)
            {
                Bass.BASS_ChannelStop(audioStream);
            }

            if (audioStreamForwards != 0)
            {
                Bass.BASS_StreamFree(audioStreamForwards);
            }
            if (audioStreamBackwards != 0)
            {
                Bass.BASS_StreamFree(audioStreamBackwards);
            }
            if (audioStreamPrefilter != 0)
            {
                Bass.BASS_StreamFree(audioStreamPrefilter);
            }

            audioStream          = 0;
            audioStreamForwards  = 0;
            audioStreamBackwards = 0;
            audioStreamPrefilter = 0;

            State = AudioStates.Stopped;

            if (DataStream != null)
            {
                DataStream.Dispose();
            }
            DataStream = null;

            AudioEngine.UnregisterTrack(this);

            base.Dispose(disposing);
        }
Example #18
0
 /// <summary>
 /// Resumes the AudioItem if it has been paused.
 /// </summary>
 public virtual void Play()
 {
     State = AudioStates.Playing;
 }
Example #19
0
        internal static void Update()
        {
            /*Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD,0);
             * Bass.BASS_Update(1);*/

            if ((GameBase.FadeState == FadeStates.FadeIn || GameBase.FadeState == FadeStates.Idle) &&
                volumeMusicFade < 100 && Time != TimeLastFrame)
            {
                if (GameBase.Mode != Modes.Rank || volumeMusicFade < 50)
                {
                    SetVolumeMusicFade(volumeMusicFade + 1);
                }
            }

            long diff = Time - TimeLastFrame;

            //Console.WriteLine("diff:{0}", diff);

            TimeLastFrame = Time;

            UpdateAudioTime();

            UpdateActiveTimingPoint(false);

            FrameAverage = (float)(FrameAverage * 0.9 + (Time - TimeLastFrame) * 0.1);

            if (AudioState != AudioStates.Stopped)
            {
                AudioState = AudioStates.Playing;
            }

            if (BeatmapManager.Current != null && BeatmapManager.Current.BeatmapVersion > 3 &&
                activeTimingPointIndex >= 0)
            {
                LoadSampleSet(TimingPoints[activeTimingPointIndex].sampleSet);
            }

            if (0 == Bass.BASS_ChannelIsActive(audioStream))
            {
                AudioState = AudioStates.Stopped;
            }

            if (AudioState == AudioStates.Playing || !UpdateTime)
            {
                for (int i = 0; i < SampleEvents.Count; i++)
                {
                    if (SampleEvents[i].Time <= Time && SampleEvents[i].Time > Time - 400)
                    {
                        if (!SampleEvents[i].Played)
                        {
                            PlaySample(SampleEvents[i].Sample, VolumeEffectAdjusted);
                            Console.WriteLine("playing sample at" + SampleEvents[i].Time);
                            SampleEvents[i].Played = true;
                        }
                    }
                    else
                    {
                        SampleEvents[i].Played = false;
                    }
                }
            }
        }
Example #20
0
 /// <summary>
 /// Stops the AudioItem immediatly without fade out. After being stopped, an AudioItem is obsolete.
 /// </summary>
 public virtual void StopImmediate()
 {
     State = AudioStates.Stopped;
 }
Example #21
0
 /// <summary>
 /// Stops the AudioItem with fade out. After being stopped, an AudioItem is obsolete.
 /// </summary>
 public virtual void Stop()
 {
     State = AudioStates.Stopped;
 }
Example #22
0
 void ResetState()
 {
     audioStates        = AudioStates.Initial;
     stateElapsed       = 0;
     audioSource.volume = audioCfg.Volume;
 }
Example #23
0
 void ResetState()
 {
     state              = AudioStates.Initial;
     stateElapsed       = 0;
     audioSource.volume = config.Volume;
 }
Example #24
0
 internal override void Play(bool restart = true)
 {
     State = AudioStates.Playing;
     Bass.BASS_ChannelPlay(audioStream, restart);
 }
Example #25
0
 /// <summary>
 /// Pauses the AudioItem.
 /// </summary>
 public virtual void Pause()
 {
     State = AudioStates.Paused;
 }
    // Update is called once per frame
    void Update()
    {
        if (Alerted)
        {
            if (EnviromentalSource.volume > 0.0f)
            {
                EnviromentalSource.volume -= startVol * Time.deltaTime / FadeOutTime;
            }
            else
            {
                Alerted     = false;
                TimeElapsed = 0.0f;
            }
        }
        else //Fade the crickets
        {
            TimeElapsed += Time.deltaTime;
            // Debug.Log(TimeElapsed);
            if (EnviromentalSource.volume < startVol && TimeElapsed >= QuietTime)
            {
                EnviromentalSource.volume += startVol * Time.deltaTime / FadeInTime;
            }
        }

        if (debugMode)
        {
            AudioTester();
        }
        else
        {
            switch (thisAI.currentState) //Check AI state and make sure sound has not played yet
            {
            case Deer_AI.AIStates.Roaming:
                if (currentAudio != AudioStates.Walking)
                {
                    thisSource.loop = true;
                    thisSource.clip = WalkClip;
                    thisSource.Play();
                    currentAudio = AudioStates.Walking;
                }
                break;
            //case Deer_AI.AIStates.Standing:
            //    if (currentAudio != AudioStates.Idle)
            //    {

            //    }
            //    break;
            case Deer_AI.AIStates.Running:
                if (currentAudio != AudioStates.Running)
                {
                    thisSource.loop = true;
                    thisSource.clip = RunClip;
                    thisSource.Play();
                    currentAudio = AudioStates.Running;
                }
                break;

            case Deer_AI.AIStates.Alert:
                if (currentAudio != AudioStates.Alert)
                {
                    thisSource.loop = false;
                    thisSource.clip = AlertClip;
                    thisSource.Play();

                    Alerted = true;
                    //EnviromentalSource.Stop();

                    currentAudio = AudioStates.Alert;
                }
                break;

            default:
                thisSource.Stop();
                thisSource.clip = null;
                break;
            }
        }
    }
Example #27
0
 public AudioManager(ContentManager c)
 {
     audioState = AudioStates.BetweenWave;
     wave       = c.Load <Song>("Audio/ingame");
     between    = c.Load <Song>("Audio/ambiance");
 }
Example #28
0
 public void StopImmediate()
 {
     state = AudioStates.Expired;
     Disable();
 }
Example #29
0
        protected void SetState(AudioStates state)
        {
            hasBreak |= state == AudioStates.Stopping || state == AudioStates.Stopped;

            RaiseStateChangeEvent(this.state, (this.state = state));
        }
Example #30
0
        internal static bool LoadAndPreviewMp3(string filename, bool previewPosition)
        {
            if (!File.Exists(filename))
            {
                return(false);
            }

            UpdateTime = true;

            activeTimingPointIndex = -1;

            bool same = true;

            if (continuePlayback && audioTime / AudioLength < 0.8F && audioRate == 100 && filename == audioFilename)
            {
                SetVolumeMusicFade(volumeMusicFade / 3);
            }
            else
            {
                audioFilename = filename;
                FreeMusic();

                //if (!Md5Dictionary.ContainsKey(filename))
                //    Md5Dictionary[filename] = GameBase.GetMd5(filename);

                audioStreamPrefilter =
                    Bass.BASS_StreamCreateFile(filename, 0, 0,
                                               BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                audioStream = BassFx.BASS_FX_TempoCreate(audioStreamPrefilter, BASSFlag.BASS_DEFAULT);

                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_USE_QUICKALGO,
                                              Bass.TRUE);
                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 4);
                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 15);

                /*
                 *              Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 5);
                 *              Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 6);
                 *              SYNCPROC proc = new SYNCPROC(syncCallback);
                 *              Bass.BASS_ChannelSetSync(audioStream, BASSSync.BASS_SYNC_POS, 10000, proc, new IntPtr(10000));
                 */
                try
                {
                    TAG_INFO tagInfo = new TAG_INFO(filename);
                    if (BassTags.BASS_TAG_GetFromFile(audioStream, tagInfo))
                    {
                        audioArtist = tagInfo.artist;
                        audioTitle  = tagInfo.title;
                    }
                    else
                    {
                        audioArtist = "unknown";
                        audioTitle  = "unknown";
                    }
                }
                catch
                {
                    audioArtist = "unknown";
                    audioTitle  = "unknown";
                }

                ResetMp3();

                same = false;

                audioLengthRaw = Bass.BASS_ChannelGetLength(audioStream);
                AudioLength    = (int)(Bass.BASS_ChannelBytes2Seconds(audioStream, audioLengthRaw) * 1000);


                Bass.BASS_ChannelGetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_FREQ, ref audioFrequency);

                if (previewPosition)
                {
                    Bass.BASS_ChannelSetPosition(audioStream,
                                                 (PreviewTime == -1
                                                      ? ((float)AudioLength / 1000 * 0.4)
                                                      : (float)PreviewTime / 1000));
                }
                SetVolumeMusicFade(0);
            }

            AudioLength =
                (int)(Bass.BASS_ChannelBytes2Seconds(audioStream, Bass.BASS_ChannelGetLength(audioStream)) * 1000);

            continuePlayback = false;
            //volumeMusicCurrent = 0;
            //Bass.BASS_ChannelSetAttributes(audioStream, -1, volumeMusicCurrent, -101);

            Bass.BASS_ChannelPlay(audioStream, false);
            AudioState = AudioStates.Playing;

            return(same);
        }