예제 #1
0
        protected virtual void Add(BassOutputStream stream)
        {
            if (!FileSystemHelper.IsLocalPath(stream.FileName))
            {
                return;
            }
            if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
            {
                return;
            }
            var gain = default(float);
            var peak = default(float);
            var mode = default(ReplayGainMode);

            if (!this.TryGetReplayGain(stream, out gain, out mode))
            {
                if (this.OnDemand)
                {
                    //TODO: Bad .Result
                    using (var duplicated = this.Output.Duplicate(stream).Result as BassOutputStream)
                    {
                        if (duplicated == null)
                        {
                            Logger.Write(this, LogLevel.Warn, "Failed to duplicate stream for file \"{0}\", cannot calculate.", stream.FileName);
                            return;
                        }
                        if (!this.TryCalculateReplayGain(duplicated, out gain, out peak, out mode))
                        {
                            return;
                        }
                    }
                    this.Dispatch(() => this.UpdateMetaData(stream, gain, peak, mode));
                }
                else
                {
                    return;
                }
            }
            var effect = new ReplayGainEffect(stream.ChannelHandle, gain, mode);

            effect.Activate();
            this.Effects.Add(stream, effect);
        }
예제 #2
0
 protected virtual bool TryCalculateReplayGain(BassOutputStream stream, out float gain, out float peak, out ReplayGainMode mode)
 {
     Logger.Write(this, LogLevel.Debug, "Attempting to calculate track replay gain for file \"{0}\".", stream.FileName);
     try
     {
         var info = default(ReplayGainInfo);
         if (BassReplayGain.Process(stream.ChannelHandle, out info))
         {
             Logger.Write(this, LogLevel.Debug, "Calculated track replay gain for file \"{0}\": {1}dB", stream.FileName, ReplayGainEffect.GetVolume(info.gain));
             gain = info.gain;
             peak = info.peak;
             mode = ReplayGainMode.Track;
             return(true);
         }
         else
         {
             Logger.Write(this, LogLevel.Warn, "Failed to calculate track replay gain for file \"{0}\".", stream.FileName);
         }
     }
     catch (Exception e)
     {
         Logger.Write(this, LogLevel.Warn, "Failed to calculate track replay gain for file \"{0}\": {1}", stream.FileName, e.Message);
     }
     gain = 0;
     peak = 0;
     mode = ReplayGainMode.None;
     return(false);
 }