Exemplo n.º 1
0
        /// <summary>
        /// Fade Out  Procedure
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="stream"></param>
        /// <param name="data"></param>
        /// <param name="userData"></param>
        private void PlaybackCrossFadeProc(int handle, int stream, int data, IntPtr userData)
        {
            new Thread(() =>
            {
                try
                {
                    Log.Debug("BASS: X-Fading out stream {0}", _filePath);

                    if (Config.CrossFadeIntervalMs > 0)
                    {
                        // Only sent GUI_MSG_PLAYBACK_CROSSFADING when gapless/crossfading mode is used
                        GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_CROSSFADING, 0, 0,
                                                        0, 0, 0, null);
                        GUIWindowManager.SendThreadMessage(msg);
                    }

                    // We want to get informed, when Crossfading has ended
                    _playBackSlideEndDelegate = new SYNCPROC(SlideEndedProc);
                    Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_SLIDE, 0, _playBackSlideEndDelegate,
                                             IntPtr.Zero);

                    _crossFading = true;
                    Bass.BASS_ChannelSlideAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 0,
                                                    Config.CrossFadeIntervalMs);
                }
                catch (AccessViolationException)
                {
                    Log.Error("BASS: Caught AccessViolationException in Crossfade Proc");
                }
            }
                       )
            {
                Name = "BASS X-Fade"
            }.Start();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Slides the volume to the given value over the period of time given by <see cref="Duration"/>.
 /// </summary>
 /// <param name="volume">0.0f-1.0f -> 0-100%</param>
 protected void SlideVolume(float volume)
 {
     if (!Bass.BASS_ChannelSlideAttribute(_stream.Handle, BASSAttribute.BASS_ATTRIB_VOL, volume, _durationMS))
     {
         throw new BassLibraryException("BASS_ChannelSlideAttribute");
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Fade Out  Procedure
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="stream"></param>
        /// <param name="data"></param>
        /// <param name="userData"></param>
        private void PlaybackCrossFadeProc(int handle, int stream, int data, IntPtr userData)
        {
            new Thread(() =>
            {
                try
                {
                    Log.Debug("BASS: X-Fading out stream {0}", _filePath);

                    // We want to get informed, when Crossfading has ended
                    _playBackSlideEndDelegate = new SYNCPROC(SlideEndedProc);
                    Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_SLIDE, 0, _playBackSlideEndDelegate,
                                             IntPtr.Zero);

                    _crossFading = true;
                    Bass.BASS_ChannelSlideAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 0,
                                                    Config.CrossFadeIntervalMs);
                }
                catch (AccessViolationException)
                {
                    Log.Error("BASS: Caught AccessViolationException in Crossfade Proc");
                }
            }
                       )
            {
                Name = "BASS X-Fade"
            }.Start();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fade out and Stop the Song
        /// </summary>
        /// <param name="stream"></param>
        public void FadeOutStop()
        {
            new Thread(() =>
            {
                Log.Debug("BASS: FadeOutStop of stream {0}", _filePath);

                if (!IsPlaying)
                {
                    return;
                }

                double crossFadeSeconds = 0.0;

                if (Config.CrossFadeIntervalMs > 0)
                {
                    crossFadeSeconds = crossFadeSeconds / 1000.0;
                }

                if ((TotalStreamSeconds - (StreamElapsedTime + crossFadeSeconds) > -1))
                {
                    Bass.BASS_ChannelSlideAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, -1,
                                                    Config.CrossFadeIntervalMs);
                    while (Bass.BASS_ChannelIsSliding(_stream, BASSAttribute.BASS_ATTRIB_VOL))
                    {
                        Thread.Sleep(20);
                    }
                }
                else
                {
                    Bass.BASS_ChannelStop(_stream);
                }
                Dispose();
            }
                       ).Start();
        }
Exemplo n.º 5
0
        public void Play(List <string> albumTracksUrls)
        {
            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                int stream1 = Bass.BASS_StreamCreateURL(albumTracksUrls[0], 0, BASSFlag.BASS_SAMPLE_MONO, null, IntPtr.Zero);
                int stream2 = Bass.BASS_StreamCreateURL(albumTracksUrls[1], 0, BASSFlag.BASS_SAMPLE_MONO, null, IntPtr.Zero);
                int stream3 = Bass.BASS_StreamCreateURL(albumTracksUrls[2], 0, BASSFlag.BASS_SAMPLE_MONO, null, IntPtr.Zero);

                Bass.BASS_ChannelSetPosition(stream1, Bass.BASS_ChannelSeconds2Bytes(stream1, 0.01), BASSMode.BASS_POS_BYTES);
                Bass.BASS_ChannelSlideAttribute(stream1, BASSAttribute.BASS_ATTRIB_VOL, 0, 0);
                Bass.BASS_ChannelPlay(stream1, false);
                VolumeUpSlow(stream1);
                Bass.BASS_ChannelSlideAttribute(stream1, BASSAttribute.BASS_ATTRIB_VOL, 0, 3000);//volume down
                Thread.Sleep(2500);
                Bass.BASS_ChannelSetPosition(stream2, Bass.BASS_ChannelSeconds2Bytes(stream2, 0.5), BASSMode.BASS_POS_BYTES);
                Bass.BASS_ChannelSlideAttribute(stream2, BASSAttribute.BASS_ATTRIB_VOL, 0, 0);
                Bass.BASS_ChannelPlay(stream2, false);
                Bass.BASS_StreamFree(stream1);
                VolumeUpSlow(stream2);
                Thread.Sleep(3000);
                Bass.BASS_ChannelSlideAttribute(stream2, BASSAttribute.BASS_ATTRIB_VOL, 0, 3000);//volume down
                Bass.BASS_ChannelSlideAttribute(stream3, BASSAttribute.BASS_ATTRIB_VOL, 0, 0);
                Bass.BASS_ChannelPlay(stream3, false);
                VolumeUpSlow(stream3);
                Bass.BASS_StreamFree(stream2);
                Thread.Sleep(5000);
                Bass.BASS_ChannelSlideAttribute(stream3, BASSAttribute.BASS_ATTRIB_VOL, 0, 3000);//volume down
                Thread.Sleep(3000);
                Bass.BASS_StreamFree(stream3);
                // free BASS
                Bass.BASS_Free();
            }
        }
Exemplo n.º 6
0
 public void PlayStreamWithFade(int _stream, bool _restart)
 {
     if (_stream != 0)
     {
         Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 0.0f);
         Bass.BASS_ChannelSlideAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 1.0f, 1500);
         Bass.BASS_ChannelPlay(_stream, _restart);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 声音淡入淡出
        /// </summary>
        /// <param name="volValue">音量目标值</param>
        /// <param name="duration">持续时间,单位/毫秒</param>
        public void VoiceSlide(float volValue, int duration)
        {
            if (this._handle == -1)
            {
                return;
            }

            //float value = 0.2f;
            //int duration=2*1000;
            Bass.BASS_ChannelSlideAttribute(this._handle, BASSAttribute.BASS_ATTRIB_VOL, volValue, duration);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Slide in the Channel over the Defined Crossfade intervall
        /// </summary>
        public void SlideIn()
        {
            if (Config.CrossFadeIntervalMs > 0)
            {
                // Reduce the stream volume to zero so we can fade it in...
                Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 0);

                // Fade in from 0 to 1 over the Config.CrossFadeIntervalMs duration
                Bass.BASS_ChannelSlideAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 1, Config.CrossFadeIntervalMs);
            }
        }
Exemplo n.º 9
0
        private static void VolumeUpSlow(int stream)
        {
            var stream2VolumeValue = 0F;

            for (int i = 0; 100 > i; i++)
            {
                stream2VolumeValue = stream2VolumeValue + 0.01F;
                Thread.Sleep(30);
                Bass.BASS_ChannelSlideAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, stream2VolumeValue, 0);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Resume Playback of a Paused stream
 /// </summary>
 public void ResumePlayback()
 {
     Log.Debug("BASS: Resuming playback of paused stream for {0}", _filePath);
     if (Config.SoftStop)
     {
         Bass.BASS_ChannelSlideAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 1, 500);
     }
     else
     {
         Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 1);
     }
 }
        /// <summary>
        ///     Does an audio stream power down effect asynchronously
        /// </summary>
        /// <param name="audioStream">The audio stream.</param>
        private static void PowerDownAsync(AudioStream audioStream)
        {
            if (audioStream == null || !audioStream.IsAudioLoaded())
            {
                return;
            }

            var freq     = audioStream.DefaultSampleRate;
            var interval = (int)(BpmHelper.GetDefaultLoopLength(audioStream.Bpm) * 1000) / 128;

            // set the volume slide

            //lock (Lock)
            {
                Bass.BASS_ChannelSlideAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_VOL, 0F, interval * 8);
                Thread.Sleep(1);
            }

            var percentValue = 0.70;

            while (freq > 100)
            {
                percentValue = percentValue / 1.2;
                interval     = (int)(interval * 0.9D);
                freq         = (int)(audioStream.DefaultSampleRate * percentValue);
                if (freq <= 100 || audioStream.ChannelId == int.MinValue)
                {
                    continue;
                }
                //lock (Lock)
                {
                    Bass.BASS_ChannelSlideAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_FREQ, freq, interval);
                    Thread.Sleep(1);
                }
                Thread.Sleep(interval);
            }
            Pause(audioStream);
            if (!audioStream.IsAudioLoaded())
            {
                return;
            }
            //lock (Lock)
            {
                Bass.BASS_ChannelSetAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_FREQ,
                                              audioStream.DefaultSampleRate);
                Thread.Sleep(1);
            }
            SetVolume(audioStream, 100M);
        }
Exemplo n.º 12
0
 // Token: 0x060000D6 RID: 214 RVA: 0x0001B138 File Offset: 0x00019338
 public void Song_FadeOut()
 {
     if (!this.isSongLoaded || !this.isSongPlaying || this.isSongFading)
     {
         return;
     }
     for (int i = 0; i < this.stemChannels.Length; i++)
     {
         if (this.stemChannels[i] != 0)
         {
             Bass.BASS_ChannelSlideAttribute(this.stemChannels[i], BASSAttribute.BASS_ATTRIB_SRC, 0f, 2000);
         }
     }
     this.isSongFading = false;
 }
Exemplo n.º 13
0
        public void EngageJumpChannel(bool engage)
        {
            var targetVolume = engage ? MaximumVolume * 0.5f : 0f;

            if (StartJumpChannelHandle != null && Bass.BASS_ChannelIsActive(StartJumpChannelHandle.Handle) == BASSActive.BASS_ACTIVE_PLAYING)
            {
                Bass.BASS_ChannelSlideAttribute(StartJumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, targetVolume, 850);
            }
            else
            {
                if (JumpChannelHandle != null)
                {
                    Bass.BASS_ChannelSlideAttribute(JumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, targetVolume, 850);
                }
            }
        }
Exemplo n.º 14
0
 public void Update()
 {
     if (_fadeJumpNextFrame)
     {
         _fadeJumpNextFrame = false;
         G.Sys.AudioManager_.DoNextFrame(() =>
         {
             if (StartJumpChannelHandle != null && Bass.BASS_ChannelIsActive(StartJumpChannelHandle.Handle) == BASSActive.BASS_ACTIVE_PLAYING)
             {
                 Bass.BASS_ChannelSlideAttribute(StartJumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, 0.0f, 850);
             }
             else
             {
                 Bass.BASS_ChannelSlideAttribute(JumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, 0.0f, 850);
             }
         });
     }
 }
Exemplo n.º 15
0
 private bool SetBalanceEffect(int channel, int id, Data.IBalanceEffect effect)
 {
     if (!effect.IsPanning)
     {
         float balanceValue = DetermineIntEffectValue(effect);
         // balance is stored as [-10..10], but must be set as [-1..1]
         if (!Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_PAN, balanceValue / 10.0f))
         {
             ErrorHandling.BassErrorOccurred(id, StringResources.SetEffectError);
             return(false);
         }
         return(true);
     }
     else
     {
         long totalLength = Bass.BASS_ChannelGetLength(channel);
         if (totalLength == -1)
         {
             ErrorHandling.BassErrorOccurred(id, StringResources.SetEffectError);
             return(false);
         }
         double totalLengthSeconds = Bass.BASS_ChannelBytes2Seconds(channel, totalLength);
         if (totalLengthSeconds < 0)
         {
             ErrorHandling.BassErrorOccurred(id, StringResources.SetEffectError);
             return(false);
         }
         // first set to start value
         // balance is stored as [-10..10], but must be set as [-1..1]
         if (!Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_PAN, effect.PanningStart / 10.0f))
         {
             ErrorHandling.BassErrorOccurred(id, StringResources.SetEffectError);
             return(false);
         }
         // now slide over all time to end value
         if (!Bass.BASS_ChannelSlideAttribute(channel, BASSAttribute.BASS_ATTRIB_PAN, effect.PanningEnd / 10.0f, (int)(totalLengthSeconds * 1000)))
         {
             ErrorHandling.BassErrorOccurred(id, StringResources.SetEffectError);
             return(false);
         }
         return(true);
     }
 }
Exemplo n.º 16
0
 public void Play()
 {
     this.IsPlaying = true;
     if (this.IsFading == true)
     {
         this.IsFading = false;
         Bass.BASS_ChannelSlideAttribute(SceneMixerChannel, BASSAttribute.BASS_ATTRIB_VOL, this.SceneVolume, 1);
     }
     if (StopsOthers)
     {
         OnStoppingOthers(EventArgs.Empty);
     }
     foreach (SoundEffect soundEffect in SoundEffects)
     {
         soundEffect.Play();
     }
     this.IsPlaying = true;
     OnPlaying(EventArgs.Empty);
 }
        /// <summary>
        ///     Sets the duration and start/end volumes for an audio stream volume slide.
        /// </summary>
        /// <param name="audioStream">The audio stream.</param>
        /// <param name="startVolume">The start volume as a percentage (0 - 1).</param>
        /// <param name="endVolume">The end volume as a percentage (0 - 1).</param>
        /// <param name="seconds">The seconds.</param>
        public static void SetVolumeSlide(AudioStream audioStream, float startVolume, float endVolume, double seconds)
        {
            if (audioStream == null || !audioStream.IsAudioLoaded())
            {
                return;
            }

            // set start volume
            SetVolume(audioStream, startVolume);

            var miliseconds = (int)(seconds * 1000);

            // set the volume slide
            //lock (Lock)
            {
                Bass.BASS_ChannelSlideAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_VOL, endVolume,
                                                miliseconds);
                Thread.Sleep(1);
            }
        }
Exemplo n.º 18
0
        private void FadeOut(int channel, int time)
        {
            Bass.BASS_ChannelSlideAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, 0.0f, time);
            RunningFileInfo info = null;

            lock (m_Mutex)
            {
                info = m_RunningFiles.ContainsKey(channel) ? m_RunningFiles[channel] : null;
            }
            if (info != null)
            {
                if (info.LinkedChannels != null)
                {
                    foreach (int secondChannel in info.LinkedChannels)
                    {
                        Bass.BASS_ChannelSlideAttribute(secondChannel, BASSAttribute.BASS_ATTRIB_VOL, 0.0f, time);
                    }
                }
            }
        }
Exemplo n.º 19
0
 private void OnTrackSync(int handle, int channel, int data, IntPtr user)
 {
     if (user.ToInt32() == 0)
     {
         // END SYNC
         BeginInvoke(new MethodInvoker(PlayNextTrack));
     }
     else
     {
         // POS SYNC
         BeginInvoke((MethodInvoker) delegate()
         {
             // this code runs on the UI thread!
             PlayNextTrack();
             // and fade out and stop the 'previous' track (for 4 seconds)
             if (_previousTrack != null)
             {
                 Bass.BASS_ChannelSlideAttribute(_previousTrack.Channel, BASSAttribute.BASS_ATTRIB_VOL, -1f, 4000);
             }
         });
     }
 }
Exemplo n.º 20
0
 private void FadeOut()
 {
     this.IsFading = true;
     Bass.BASS_ChannelSlideAttribute(SceneMixerChannel, BASSAttribute.BASS_ATTRIB_VOL, 0, FadeOutLength);
 }
Exemplo n.º 21
0
        private System.Collections.Generic.Dictionary <int, bool> m_CueOutRepeats = new Dictionary <int, bool>(); // channel to repeat

        private bool SetStartVolume(ISoundFile file, int fadeInTime, int channel, RunningFileInfo info)
        {
            float volume         = file.Volume / 100.0f;
            float specificVolume = 1.0f;

            if (file.Effects != null)
            {
                volume = DetermineVolume(file.Effects, volume, out specificVolume);
            }
            info.Volume = specificVolume;
            if ((file.Effects != null && file.Effects.FadeInTime != 0) || fadeInTime > 0)
            {
                if (!Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, 0.0f))
                {
                    ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                    return(false);
                }
                if (info.LinkedChannels != null)
                {
                    foreach (int secondChannel in info.LinkedChannels)
                    {
                        if (secondChannel != 0 && !Bass.BASS_ChannelSetAttribute(secondChannel, BASSAttribute.BASS_ATTRIB_VOL, 0.0f))
                        {
                            ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                            return(false);
                        }
                    }
                }
                int maxFadeInTime = file.Effects != null?Math.Max(file.Effects.FadeInTime, fadeInTime) : fadeInTime;

                if (!Bass.BASS_ChannelSlideAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, volume, maxFadeInTime))
                {
                    ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                    return(false);
                }
                if (info.LinkedChannels != null)
                {
                    foreach (int secondChannel in info.LinkedChannels)
                    {
                        if (secondChannel != 0 && !Bass.BASS_ChannelSlideAttribute(secondChannel, BASSAttribute.BASS_ATTRIB_VOL, volume, maxFadeInTime))
                        {
                            ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                            return(false);
                        }
                    }
                }
            }
            else
            {
                if (!Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, volume))
                {
                    ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                    return(false);
                }
                if (info.LinkedChannels != null)
                {
                    foreach (int secondChannel in info.LinkedChannels)
                    {
                        if (secondChannel != 0 && !Bass.BASS_ChannelSetAttribute(secondChannel, BASSAttribute.BASS_ATTRIB_VOL, volume))
                        {
                            ErrorHandling.BassErrorOccurred(file.Id, StringResources.SetVolumeError);
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 22
0
 public void FadeStop(int miliseconds)
 {
     fading = true;
     Bass.BASS_ChannelSlideAttribute(handle, BASSAttribute.BASS_ATTRIB_VOL, 0, miliseconds);
     Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_SLIDE, 0, Engine.g_FadeFreeProc, new IntPtr(0));
 }
 public static void Init(int stream)
 {
     _stream = stream;
     BassNet.Registration("*****@*****.**", "2X8141823152222");
     Bass.BASS_ChannelSlideAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 0.5f, 0);
 }