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); }
protected virtual bool ScanTrack(ScannerItem scannerItem, IBassStream stream) { var info = default(ReplayGainInfo); if (!BassReplayGain.Process(stream.ChannelHandle, out info)) { return(false); } scannerItem.ItemPeak = info.peak; scannerItem.ItemGain = info.gain; return(true); }
public void CanCalculateTrack(int number) { var info = new ReplayGainInfo(); var expectation = Expectations[number]; var handle = Bass.CreateStream(expectation.FileName, Flags: BassFlags.Decode | BassFlags.Float); try { Assert.IsTrue(BassReplayGain.Process(handle, out info)); } finally { Bass.StreamFree(handle); } Assert.AreEqual(Math.Round(expectation.Peak, 2), Math.Round(info.peak, 2)); Assert.AreEqual(Math.Round(expectation.Gain, 2), Math.Round(info.gain, 2)); }