public void StartAllSoundsOnLayer(SoundLayer layer)
 {
     foreach (SoundManagerClip clip in _layers[layer])
     {
         clip._audiSource.Play();
     }
 }
 public void PauseSoundsOnLayer(SoundLayer layer)
 {
     foreach (SoundManagerClip clip in _layers[layer].Where(c => c._audiSource.isPlaying))
     {
         clip.PauseClip();
     }
 }
        SoundManagerClip FindFreeAudioSource(SoundLayer layer, string clipName)
        {
            AudioSource tempAudio = null;

            foreach (SoundManagerClip clip in _layers[layer])
            {
                if (clip._audioClipPath == clipName)
                {
                    tempAudio = clip._audiSource;
                }
                if (!clip._audiSource.isPlaying && !clip._isPaused)
                {
                    return(clip);
                }
            }

            SoundManagerClip smc = new SoundManagerClip();

            if (tempAudio == null)
            {
                smc._audiSource = gameObject.AddComponent <AudioSource> ();
            }
            else
            {
                smc._audiSource = tempAudio;
            }

            smc._audiSource.outputAudioMixerGroup = SetAudioGroup(layer);
            smc._audiSource.playOnAwake           = false;
            smc._audioClipPath = "";
            _layers[layer].Add(smc);
            return(smc);
        }
 public void UnmuteLayer(SoundLayer layer)
 {
     foreach (SoundManagerClip clip in _layers[layer])
     {
         clip.UnmuteClip();
     }
 }
Example #5
0
        /// <summary>
        /// Cleans up the sound testing environment.
        /// </summary>
        /// <param name="layer">The sound layer to cleanup.</param>
        /// <param name="playingFiles">The sound files to cleanup.</param>
        private void SoundTestCleanup(SoundLayer layer, SoundFile[] playingFiles)
        {
            // Stop playing.
            Engine.SoundManager.StopLayer(layer.Name, true);

            // Cleanup sound.
            foreach (SoundFile file in playingFiles)
            {
                Engine.AssetLoader.Destroy(file.Name);
            }

            // Wait for cleanup. Only one file will be cleaned up per loop.
            WaitForSoundLoops(playingFiles.Length);

            // Should be cleaned up.
            foreach (SoundFile file in playingFiles)
            {
                Assert.Equal((uint)0, ((ALSoundFile)file).ALBuffer);
            }

            // Remove the layer.
            Engine.SoundManager.RemoveLayer("testLayer");
            Assert.Empty(Engine.SoundManager.Layers);

            // Cleanup.
            Helpers.UnloadScene();

            // Restore sound thread frequency.
            Engine.Flags.SoundThreadFrequency = 200;
        }
Example #6
0
        public override void Update(float frameTime)
        {
            _uiController.Update();

            SoundLayer mainLayer = Context.SoundManager.GetLayer("main");

            if (mainLayer == null)
            {
                return;
            }

            _controlButton.Texture = Context.AssetLoader.Get <Texture>(Context.SoundManager.GetLayer("main")?.Status == SoundStatus.Playing ? _pauseButton : _playButton);

            if (mainLayer.CurrentlyPlayingFile == null)
            {
                _soundBar.Value    = 0;
                _soundBarInfo.Text = "N/A";
            }
            else
            {
                int playbackPercentage = (int)(100 * mainLayer.PlaybackLocation / mainLayer.TotalDuration);
                _soundBar.Value    = playbackPercentage;
                _soundBarInfo.Text = $"{mainLayer.PlaybackLocation}:{mainLayer.TotalDuration}";
            }
        }
    public void RegisterSound(SoundLayer layer, int priority, AudioSource source)
    {
        // XXX: Layers and priorities not implemented

        switch (layer)
        {
        case SoundLayer.backgroundMusic:
        case SoundLayer.foregroundMusic:
            if (!settings.musicOn)
            {
                return;
            }
            break;

        default:
            if (!settings.soundOn)
            {
                return;
            }
            break;
        }

        sources.Add(source);
        source.Play();
    }
 public void UnPauseSoundsOnLayer(SoundLayer layer)
 {
     foreach (SoundManagerClip clip in _layers[layer].Where(c => c._isPaused))
     {
         clip.UnPauseClip();
     }
 }
 public void MuteSoundLayer(SoundLayer layer)
 {
     //StopSoundLayer(layer);
     _player.MuteLayer(layer);
     channelMute[layer] = true;
     PlayerPrefs.SetInt("soundMute/" + layer, 1);
     PlayerPrefs.Save();
 }
Example #10
0
 public bool GetLayerEnable(SoundLayer layer)
 {
     if (!m_LayerSwitchDict.ContainsKey(layer))
     {
         return(true);
     }
     return(m_LayerSwitchDict[layer]);
 }
Example #11
0
        public void UnMuteSoundLayer(SoundLayer layer)
        {
//			if (alsoPlayTheSoundsOnLayer)
//				StartSoundLayer(layer);
            _player.UnmuteLayer(layer);
            channelMute[layer] = false;
            PlayerPrefs.SetInt("soundMute/" + layer, 0);
            PlayerPrefs.Save();
        }
Example #12
0
        public override void Load()
        {
            SoundFile[]     files  = { Context.AssetLoader.Get <SoundFile>("1.wav"), Context.AssetLoader.Get <SoundFile>("2.wav") };
            SoundLayer      layer  = Context.SoundManager.CreateLayer("example");
            StreamingSource source = Context.SoundManager.StreamOnLayer("example", files);

            source.Looping     = true;
            source.OnFinished += (e, a) => { Debugger.Log(MessageType.Info, MessageSource.Game, "Sound is over."); };
        }
 public void StopSound(string clipName, SoundLayer layer)
 {
     foreach (SoundManagerClip clip in _layers[layer])
     {
         if (clip._audiSource != null && clip._audioClipPath == clipName)
         {
             clip._audiSource.Stop();
         }
     }
 }
        public SoundManagerClip PlaySound(string clipName, SoundLayer layer, bool isLooping = false)
        {
            SoundManagerClip smc = FindFreeAudioSource(layer, clipName);

            smc._audioClipPath = clipName;
            smc.LoadSoundClip();
            smc._audiSource.loop = isLooping;
            smc._audiSource.Play();
            return(smc);
        }
 public void StopAllSoundsOnLayer(SoundLayer layer)
 {
     foreach (SoundManagerClip clip in _layers[layer])
     {
         if (clip._audiSource != null)
         {
             clip._audiSource.Stop();
         }
     }
 }
Example #16
0
        public void StopSound(List <string> soundList, SoundLayer layer)
        {
//			if (channelMute[layer] || channelPaused[layer])
//				return;

            // try to stop all sounds in list because can't know which one be played
            for (int i = 0; i < soundList.Count; i++)
            {
                string clipPath = SoundMapping.GetSoundClipPathForEventType(soundList [i]);
                _player.StopSound(clipPath, layer);
            }
        }
Example #17
0
        public override void Load()
        {
            _song = Context.AssetLoader.Get <SoundFile>("ElectricSleepMainMenu.wav");
            SoundLayer layer  = Context.SoundManager.CreateLayer("example");
            Source     source = Context.SoundManager.PlayOnLayer("example", _song);

            source.Looping     = true;
            source.OnFinished += (e, a) => { Debugger.Log(MessageType.Info, MessageSource.Game, "Sound is over."); };

            SoundFadeIn effectTest = new SoundFadeIn(5000, Context.SoundManager.GetLayer("example"));

            layer.ApplySoundEffect(effectTest);
        }
//		public SoundManagerClip PlaySound(AudioClip clip, SoundLayer layer, bool isLooping = false)
//		{
//			SoundManagerClip smc = FindFreeAudioSource(layer, clipName);
//			smc._audioClipPath = clipName;
//			smc.LoadSoundClip();
//			smc._audiSource.clip = clip;
//			smc._audiSource.loop = isLooping;
//			smc._audiSource.Play();
//			return smc;
//		}

        public bool IsPlaying(string clipName, SoundLayer layer)
        {
            bool isPlaying = false;

            foreach (SoundManagerClip clip in _layers[layer])
            {
                if (clip._audiSource != null && clip._audiSource.clip != null)
                {
                    if (clip._audioClipPath == clipName && clip._audiSource.isPlaying)
                    {
                        isPlaying = true;
                    }
                }
            }

            return(isPlaying);
        }
Example #19
0
        public void SetLayerEnable(SoundLayer layer, bool isOn)
        {
            if (!m_LayerSwitchDict.ContainsKey(layer))
            {
                return;
            }
            m_LayerSwitchDict[layer] = isOn;

            if (isOn && m_IsOn)
            {
                Manager.UnMuteSoundLayer(layer);
            }
            else
            {
                Manager.MuteSoundLayer(layer);
            }
        }
        public AudioMixerGroup SetAudioGroup(SoundLayer layer)
        {
            AudioMixerGroup temp = null;

            if (layer == SoundLayer.Main)
            {
                temp = masterMixer.FindMatchingGroups("Main")[0];
                Debug.Log("SetAudioGroup to: " + temp.name);
            }
            else
            {
                temp = masterMixer.FindMatchingGroups("Music")[0];
                Debug.Log("SetAudioGroup to: " + temp.name);
            }

            return(temp);
        }
Example #21
0
        /// <summary>
        /// Setup a sound testing environment. Creates a scene, sound layer, loads tracks.
        /// </summary>
        /// <param name="playingFiles">The playing tracks.</param>
        /// <param name="layer">The created layer.</param>
        /// <param name="filesToPlay">Files to play on layer.</param>
        private void SoundTestStartNoChecks(out SoundFile[] playingFiles, out SoundLayer layer, params string[] filesToPlay)
        {
            // Create a holder for the sound file.
            List <SoundFile> files = new List <SoundFile>();

            // Create scene for this test.
            TestScene extScene = new TestScene
            {
                // This will test loading testing in another thread.
                ExtLoad = () =>
                {
                    foreach (string trackName in filesToPlay)
                    {
                        SoundFile track = Engine.AssetLoader.Get <SoundFile>(trackName);
                        if (filesToPlay.Length == 1)
                        {
                            Engine.SoundManager.Play(track, "testLayer");
                        }
                        else
                        {
                            Engine.SoundManager.QueuePlay(track, "testLayer");
                        }
                        files.Add(track);
                    }
                }
            };

            // Load scene.
            Helpers.LoadScene(extScene);

            // Set instant sound thread.
            Engine.Flags.SoundThreadFrequency = 1;

            // Ensure layer is proper and get it.
            Assert.Single(Engine.SoundManager.Layers);
            layer = Engine.SoundManager.GetLayer("testLayer");
            Assert.Equal("testlayer", layer.Name);

            // Wait for two loops.
            WaitForSoundLoops(2);

            // Assign loaded files.
            playingFiles = files.ToArray();
        }
Example #22
0
        public void PlaySound(List <string> soundList, SoundLayer layer, bool isLooping = false)
        {
//            if (channelMute[layer] || channelPaused[layer])
//                return;

            string clipPath = SoundMapping.GetSoundClipPathForEventType(soundList);

            SoundManagerPlayer.SoundManagerClip smc = _player.PlaySound(clipPath, layer, isLooping);

            if (channelMute[layer])
            {
                smc.MuteClip();
            }

            if (channelPaused[layer])
            {
                smc.PauseClip();
            }
        }
Example #23
0
        public void PlayTimedSound(List <string> type, SoundLayer layer, float timeToPlay)
        {
//            if (channelMute[layer] || channelPaused[layer])
//                return;

            string clipPath = SoundMapping.GetSoundClipPathForEventType(type);

            SoundManagerPlayer.SoundManagerClip smc = _player.PlayTimedSound(clipPath, layer, timeToPlay);

            if (channelMute[layer])
            {
                smc.MuteClip();
            }

            if (channelPaused[layer])
            {
                smc.PauseClip();
            }
        }
Example #24
0
        /// <summary>
        /// Setup a sound testing environment. Creates a scene, sound layer, loads tracks, and performs checks.
        /// </summary>
        /// <param name="playingFiles">The playing tracks.</param>
        /// <param name="layer">The created layer.</param>
        /// <param name="filesToPlay">Files to play on layer.</param>
        private void SoundTestStart(out SoundFile[] playingFiles, out SoundLayer layer, params string[] filesToPlay)
        {
            SoundTestStartNoChecks(out SoundFile[] files, out SoundLayer testLayer, filesToPlay);
            playingFiles = files;
            layer        = testLayer;

            WaitForSoundLoops(1);

            // Ensure everything loaded correctly.
            Assert.Equal(playingFiles.Sum(x => x.Duration), layer.TotalDuration);
            Assert.Equal(playingFiles.Length, layer.PlayList.Count);
            for (int i = 0; i < playingFiles.Length; i++)
            {
                Assert.Equal(playingFiles[i], layer.PlayList[i]);
            }

            Assert.Equal(SoundStatus.Playing, layer.Status);
            Assert.Equal(playingFiles[0], layer.CurrentlyPlayingFile);
            Assert.Equal(0, layer.CurrentlyPlayingFileIndex);
        }
        public SoundManagerClip PlayTimedSound(string clipName, SoundLayer layer, float timeToPlay)
        {
            SoundManagerClip cc = null;

            if (_continuosLooping.ContainsKey(clipName))
            {
                cc            = _continuosLooping[clipName];
                cc._playUntil = Time.time + timeToPlay;
            }
            else
            {
                cc = FindFreeAudioSource(layer, clipName);
                cc._audioClipPath   = clipName;
                cc._playUntil       = Time.time + timeToPlay;
                cc._audiSource.loop = true;
                cc.LoadSoundClip();
                cc._audiSource.Play();

                _continuosLooping.Add(cc._audioClipPath, cc);
            }

            return(cc);
        }
Example #26
0
 public bool IsLayerMuted(SoundLayer layer)
 {
     return(channelMute[layer]);
 }
Example #27
0
 public void StartSoundLayer(SoundLayer layer)
 {
     _player.StartAllSoundsOnLayer(layer);
 }
Example #28
0
 public void StopSoundLayer(SoundLayer layer)
 {
     _player.StopAllSoundsOnLayer(layer);
 }
Example #29
0
 public bool IsClipPlaying(string clipName, SoundLayer layer)
 {
     return(_player.IsPlaying(clipName, layer));
 }
Example #30
0
 public void UnPauseSoundLayer(SoundLayer layer)
 {
     channelPaused[layer] = false;
     _player.UnPauseSoundsOnLayer(layer);
 }