Esempio n. 1
0
 public void bassPlay(string mp3name)
 {
     if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
     {
         stream = Bass.BASS_StreamCreateFile(mp3name, 0, 0, BASSFlag.BASS_DEFAULT);
         if (stream != 0)
         {
             BASS_BFX_VOLUME volume = new BASS_BFX_VOLUME();
             volume.fVolume = 0.5f;
             int volumeHandle = Bass.BASS_ChannelSetFX(stream, BASSFXType.BASS_FX_BFX_VOLUME, 0);
             //apply effect parameter
             Bass.BASS_FXSetParameters(volumeHandle, volume);
             //play the channel
             Bass.BASS_ChannelPlay(stream, false);
         }
     }
 }
        /// <summary>
        ///     Sets the replay gain for a channel.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="gain">The gain.</param>
        public static void SetReplayGain(int channel, float gain)
        {
            if (gain == 0) return;
            if (channel == int.MinValue) return;

            DebugHelper.WriteLine("SetReplayGain " + gain);

            var fxChannel = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_VOLUME, int.MaxValue);
            var volume = DecibelToPercent(gain);
            var volumeParameters = new BASS_BFX_VOLUME(volume, BASSFXChan.BASS_BFX_CHANALL);
            Bass.BASS_FXSetParameters(fxChannel, volumeParameters);
        }
        /// <summary>
        /// Sets the replay gain for a channel.
        /// </summary>
        /// <param name="audioStream">The audio stream.</param>
        private static void SetReplayGain(AudioStream audioStream)
        {
            if (audioStream == null || !audioStream.IsAudioLoaded())
                throw new Exception("Audio file null or not audio not loaded");

            if (!audioStream.IsGainChannelInitialized() && audioStream.Gain == 0) return;

            var volume = DecibelToPercent(audioStream.Gain);
            DebugHelper.WriteLine("SetReplayGain for " + audioStream + " to " + volume);

            if (!audioStream.IsGainChannelInitialized())
            {
                audioStream.GainChannel = Bass.BASS_ChannelSetFX(audioStream.Channel, BASSFXType.BASS_FX_BFX_VOLUME, int.MaxValue);
            }

            var volumeParameters = new BASS_BFX_VOLUME(volume, BASSFXChan.BASS_BFX_CHANALL);
            Bass.BASS_FXSetParameters(audioStream.GainChannel, volumeParameters);
        }