Example #1
0
        public void CanCalculateAlbum(int number, int position, int count)
        {
            var info        = new ReplayGainBatchInfo();
            var expectation = Expectations[number];
            var handles     = new List <int>();

            try
            {
                for (var a = position; a < count; a++)
                {
                    var handle = Bass.CreateStream(Expectations[a].FileName, Flags: BassFlags.Decode | BassFlags.Float);
                    handles.Add(handle);
                }
                Assert.IsTrue(BassReplayGain.ProcessBatch(handles.ToArray(), out info));
                for (var a = position; a < count; a++)
                {
                    Assert.AreEqual(Math.Round(Expectations[a].Peak, 2), Math.Round(info.items[a].peak, 2));
                    Assert.AreEqual(Math.Round(Expectations[a].Gain, 2), Math.Round(info.items[a].gain, 2));
                }
            }
            finally
            {
                foreach (var handle in handles)
                {
                    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));
        }
 public void Scan()
 {
     Logger.Write(this, LogLevel.Debug, "Initializing BASS (NoSound).");
     Bass.Init(Bass.NoSoundDevice);
     BassReplayGain.Init();
     try
     {
         if (this.Threads > 1)
         {
             Logger.Write(this, LogLevel.Debug, "Beginning parallel scanning with {0} threads.", this.Threads);
         }
         else
         {
             Logger.Write(this, LogLevel.Debug, "Beginning single threaded scanning.");
         }
         var scannerItems  = default(IEnumerable <ScannerItem>);
         var scannerGroups = default(IEnumerable <IEnumerable <ScannerItem> >);
         this.GetGroups(out scannerItems, out scannerGroups);
         this.ScanTracks(scannerItems);
         this.ScanGroups(scannerGroups);
         Logger.Write(this, LogLevel.Debug, "Scanning completed successfully.");
     }
     finally
     {
         Logger.Write(this, LogLevel.Debug, "Releasing BASS (NoSound).");
         BassReplayGain.Free();
         Bass.Free();
     }
 }
        protected virtual bool ScanGroup(IDictionary <ScannerItem, IBassStream> group)
        {
            if (group.Count == 0)
            {
                //Nothing to do.
                return(true);
            }
            var channelHandles = group.Values
                                 .Select(stream => stream.ChannelHandle)
                                 .ToArray();
            var info = default(ReplayGainBatchInfo);

            if (!BassReplayGain.ProcessBatch(channelHandles, out info))
            {
                return(false);
            }
            foreach (var scannerItem in group.Keys)
            {
                var stream = group[scannerItem];
                foreach (var item in info.items)
                {
                    if (item.handle == stream.ChannelHandle)
                    {
                        scannerItem.ItemPeak  = item.peak;
                        scannerItem.ItemGain  = item.gain;
                        scannerItem.GroupPeak = info.peak;
                        scannerItem.GroupGain = info.gain;
                        break;
                    }
                }
            }
            return(true);
        }
Example #4
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);
 }
        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);
        }
Example #6
0
 protected virtual void OnDisposing()
 {
     if (this.Output != null)
     {
         this.Output.Loaded   -= this.OnLoaded;
         this.Output.Unloaded -= this.OnUnloaded;
     }
     if (this.BassStreamPipelineFactory != null)
     {
         this.BassStreamPipelineFactory.CreatingPipeline -= this.OnCreatingPipeline;
     }
     BassReplayGain.Free();
 }
Example #7
0
        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));
        }
Example #8
0
 public void TearDown()
 {
     BassReplayGain.Free();
     Bass.Free();
 }
Example #9
0
 public void SetUp()
 {
     Bass.Init(Bass.NoSoundDevice);
     BassReplayGain.Init();
 }
Example #10
0
 public BassReplayGainBehaviour()
 {
     BassReplayGain.Init();
     this.Effects = new ConditionalWeakTable <BassOutputStream, ReplayGainEffect>();
 }