protected virtual bool StartASIO()
 {
     if (BassAsio.IsStarted)
     {
         Logger.Write(this, LogLevel.Debug, "ASIO has already been started.");
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Starting ASIO.");
     BassUtils.OK(BassAsio.Start(BassAsio.Info.PreferredBufferLength));
     return(true);
 }
示例#2
0
 protected virtual bool StopWASAPI(bool reset)
 {
     if (!BassWasapi.IsStarted)
     {
         Logger.Write(this, LogLevel.Debug, "WASAPI has not been started.");
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Stopping WASAPI.");
     BassUtils.OK(BassWasapi.Stop(reset));
     return(true);
 }
 protected override void OnDisposing()
 {
     if (this.ChannelHandle != 0)
     {
         Logger.Write(this, LogLevel.Debug, "Freeing BASS stream: {0}", this.ChannelHandle);
         BassUtils.OK(Bass.StreamFree(this.ChannelHandle)); //Not checking result code as it contains an error if the application is shutting down.
     }
     this.Stop();
     BassAsioDevice.Free();
     base.OnDisposing();
 }
 public override bool Add(BassOutputStream stream)
 {
     if (this.Queue.Contains(stream.ChannelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is already enqueued: {0}", stream.ChannelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Adding stream to the queue: {0}", stream.ChannelHandle);
     BassUtils.OK(BassGapless.ChannelEnqueue(stream.ChannelHandle));
     return(true);
 }
示例#5
0
 public override bool Remove(int channelHandle)
 {
     if (!this.Queue.Contains(channelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is not enqueued: {0}", channelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Removing stream from the queue: {0}", channelHandle);
     BassUtils.OK(BassGapless.ChannelRemove(channelHandle));
     return(true);
 }
示例#6
0
 protected virtual bool StartWASAPI()
 {
     if (BassWasapi.IsStarted)
     {
         Logger.Write(this, LogLevel.Debug, "WASAPI has already been started.");
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Starting WASAPI.");
     BassUtils.OK(BassWasapi.Start());
     return(true);
 }
 public override bool Remove(BassOutputStream stream, Action <BassOutputStream> callBack)
 {
     if (!this.Queue.Contains(stream.ChannelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is not enqueued: {0}", stream.ChannelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Removing stream from the queue: {0}", stream.ChannelHandle);
     BassUtils.OK(BassGapless.ChannelRemove(stream.ChannelHandle));
     callBack(stream);
     return(true);
 }
示例#8
0
        protected virtual void OnCreatingPipeline(object sender, CreatingPipelineEventArgs e)
        {
            if (BassUtils.GetChannelDsdRaw(e.Stream.ChannelHandle))
            {
                //Cannot apply effects to DSD.
                return;
            }
            var component = new BassReplayGainStreamComponent(this, e.Stream);

            component.InitializeComponent(this.Core);
            e.Components.Add(component);
        }
示例#9
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.UpdateThreads, 0));
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.PlaybackBufferLength, this.Output.BufferLength));
     BassUtils.OK(Bass.Init(Bass.NoSoundDevice));
     this.IsInitialized = true;
     Logger.Write(this, LogLevel.Debug, "BASS (No Sound) Initialized.");
 }
示例#10
0
 public override void Connect(IBassStreamComponent previous)
 {
     Logger.Write(this, LogLevel.Debug, "Creating BASS MIX stream with rate {0} and {1} channels.", this.Rate, this.Channels);
     this.ChannelHandle = BassMix.CreateMixerStream(this.Rate, this.Channels, this.Flags);
     if (this.ChannelHandle == 0)
     {
         BassUtils.Throw();
     }
     Logger.Write(this, LogLevel.Debug, "Adding stream to the mixer: {0}", previous.ChannelHandle);
     BassUtils.OK(BassMix.MixerAddChannel(this.ChannelHandle, previous.ChannelHandle, BassFlags.Default | BassFlags.MixerBuffer));
     this.MixerChannelHandles.Add(previous.ChannelHandle);
 }
示例#11
0
 public static int GetDrive(string name)
 {
     for (int a = 0, b = BassCd.DriveCount; a < b; a++)
     {
         var cdInfo = default(CDInfo);
         BassUtils.OK(BassCd.GetInfo(a, out cdInfo));
         if (string.Equals(GetDriveName(cdInfo), name, StringComparison.OrdinalIgnoreCase))
         {
             return(a);
         }
     }
     return(NO_DRIVE);
 }
 public static int GetDrive(SelectionConfigurationOption option)
 {
     for (int a = 0, b = BassCd.DriveCount; a < b; a++)
     {
         var cdInfo = default(CDInfo);
         BassUtils.OK(BassCd.GetInfo(a, out cdInfo));
         if (string.Equals(cdInfo.Name, option.Id, StringComparison.OrdinalIgnoreCase))
         {
             return(a);
         }
     }
     return(CD_NO_DRIVE);
 }
示例#13
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     this.IsInitialized = true;
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.UpdateThreads, 1));
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.PlaybackBufferLength, this.GetBufferLength()));
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.SRCQuality, this.Output.ResamplingQuality));
     BassUtils.OK(Bass.Init(this.DirectSoundDevice, this.Output.Rate));
     Logger.Write(this, LogLevel.Debug, "BASS Initialized.");
 }
示例#14
0
        protected virtual bool IsFormatSupported(PlaylistItem playlistItem, int channelHandle)
        {
            var query    = this.BassStreamPipelineFactory.QueryPipeline();
            var channels = BassUtils.GetChannelCount(channelHandle);
            var rate     = BassUtils.GetChannelDsdRate(channelHandle);

            if (query.OutputChannels < channels || !query.OutputRates.Contains(rate))
            {
                Logger.Write(this, LogLevel.Warn, "DSD format {0}:{1} is unsupported, the stream will be unloaded. This warning is expensive, please don't attempt to play unsupported DSD.", rate, channels);
                return(false);
            }
            return(true);
        }
示例#15
0
 public override void Connect(IBassStreamComponent previous)
 {
     this.Rate          = previous.Rate;
     this.Channels      = previous.Channels;
     this.ChannelHandle = BassFx.TempoCreate(previous.ChannelHandle, previous.Flags);
     if (this.ChannelHandle == 0)
     {
         BassUtils.Throw();
     }
     if (this.IsActive)
     {
         this.Update();
     }
 }
示例#16
0
        public static void Detect(int device, bool exclusive, bool autoFormat, bool buffer, bool eventDriven, bool dither)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Device is already initialized.");
            }

            IsInitialized = true;

            LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detecting WASAPI device.");

            try
            {
                var flags = GetFlags(exclusive, autoFormat, buffer, eventDriven, dither);
                BassUtils.OK(
                    BassWasapiHandler.Init(
                        device,
                        0,
                        0,
                        flags
                        )
                    );
                var deviceInfo = default(WasapiDeviceInfo);
                BassUtils.OK(BassWasapi.GetDeviceInfo(BassWasapi.CurrentDevice, out deviceInfo));
                Info = new BassWasapiDeviceInfo(
                    BassWasapi.CurrentDevice,
                    deviceInfo.MixFrequency,
                    0,
                    deviceInfo.MixChannels,
                    GetSupportedFormats(
                        BassWasapi.CurrentDevice,
                        flags
                        ),
                    BassWasapi.CheckFormat(
                        BassWasapi.CurrentDevice,
                        deviceInfo.MixFrequency,
                        deviceInfo.MixChannels,
                        flags
                        ),
                    device == BassWasapi.DefaultDevice
                    );

                LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", BassWasapi.CurrentDevice, Info.Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(WasapiFormat), Info.Format));
                LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Rates => {1}", BassWasapi.CurrentDevice, string.Join(", ", Info.SupportedRates));
            }
            finally
            {
                Free();
            }
        }
示例#17
0
 public BassResamplerStreamComponent(BassResamplerStreamComponentBehaviour behaviour, BassOutputStream stream)
 {
     if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
     {
         throw new InvalidOperationException("Cannot resample DSD streams.");
     }
     this.Behaviour = behaviour;
     this.Rate      = behaviour.Output.Rate;
     this.Channels  = stream.Channels;
     this.Flags     = BassFlags.Decode;
     if (this.Behaviour.Output.Float)
     {
         this.Flags |= BassFlags.Float;
     }
 }
        protected virtual void OnCreatingPipeline(object sender, CreatingPipelineEventArgs e)
        {
            if (!this.Enabled)
            {
                return;
            }
            if (BassUtils.GetChannelDsdRaw(e.Stream.ChannelHandle))
            {
                return;
            }
            var component = new BassParametricEqualizerStreamComponent(this, e.Stream);

            component.InitializeComponent(this.Core);
            e.Components.Add(component);
        }
示例#19
0
 public BassParametricEqualizerStreamComponent(BassParametricEqualizerStreamComponentBehaviour behaviour, BassOutputStream stream)
 {
     if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
     {
         throw new InvalidOperationException("Cannot apply effects to DSD streams.");
     }
     this.Behaviour = behaviour;
     this.Rate      = behaviour.Output.Rate;
     this.Channels  = stream.Channels;
     this.Flags     = BassFlags.Decode;
     if (this.Behaviour.Output.Float)
     {
         this.Flags |= BassFlags.Float;
     }
     this.Attach();
 }
示例#20
0
        private static IEnumerable <SelectionConfigurationOption> GetWASAPIDevices()
        {
            yield return(new SelectionConfigurationOption(BassWasapi.DefaultDevice.ToString(), "Default Device"));

            for (int a = 0, b = BassWasapi.DeviceCount; a < b; a++)
            {
                var deviceInfo = default(WasapiDeviceInfo);
                BassUtils.OK(BassWasapi.GetDeviceInfo(a, out deviceInfo));
                if (deviceInfo.IsInput || deviceInfo.IsDisabled || deviceInfo.IsLoopback || deviceInfo.IsUnplugged)
                {
                    continue;
                }
                LogManager.Logger.Write(typeof(BassWasapiStreamOutputConfiguration), LogLevel.Debug, "WASAPI Device: {0} => {1} => {2} => {3} => {4}", a, deviceInfo.ID, deviceInfo.Name, Enum.GetName(typeof(WasapiDeviceType), deviceInfo.Type), deviceInfo.MixFrequency);
                yield return(new SelectionConfigurationOption(deviceInfo.ID, deviceInfo.Name, string.Format("{0} ({1})", deviceInfo.Name, Enum.GetName(typeof(WasapiDeviceType), deviceInfo.Type))));
            }
        }
示例#21
0
 public static int GetWasapiDevice(SelectionConfigurationOption option)
 {
     if (!string.Equals(option.Id, BassWasapi.DefaultDevice.ToString()))
     {
         for (int a = 0, b = BassWasapi.DeviceCount; a < b; a++)
         {
             var deviceInfo = default(WasapiDeviceInfo);
             BassUtils.OK(BassWasapi.GetDeviceInfo(a, out deviceInfo));
             if (string.Equals(deviceInfo.ID, option.Id, StringComparison.OrdinalIgnoreCase))
             {
                 return(a);
             }
         }
     }
     return(BassWasapi.DefaultDevice);
 }
示例#22
0
 public override void InitializeComponent(ICore core)
 {
     BassUtils.OK(Bass.ChannelSetSync(
                      this.OutputStream.ChannelHandle,
                      SyncFlags.Position,
                      this.EndingPosition,
                      this.OnEnding
                      ));
     BassUtils.OK(Bass.ChannelSetSync(
                      this.OutputStream.ChannelHandle,
                      SyncFlags.End,
                      0,
                      this.OnEnded
                      ));
     base.InitializeComponent(core);
 }
示例#23
0
        private static IEnumerable <SelectionConfigurationOption> GetDSDevices()
        {
            yield return(new SelectionConfigurationOption(Bass.DefaultDevice.ToString(), "Default Device"));

            for (int a = 0, b = Bass.DeviceCount; a < b; a++)
            {
                var deviceInfo = default(DeviceInfo);
                BassUtils.OK(Bass.GetDeviceInfo(a, out deviceInfo));
                LogManager.Logger.Write(typeof(BassDirectSoundStreamOutputConfiguration), LogLevel.Debug, "DS Device: {0} => {1} => {2}", a, deviceInfo.Name, deviceInfo.Driver);
                if (!deviceInfo.IsEnabled)
                {
                    continue;
                }
                yield return(new SelectionConfigurationOption(deviceInfo.Name, deviceInfo.Name, deviceInfo.Driver));
            }
        }
示例#24
0
 public void Activate()
 {
     if (!this.IsActive)
     {
         this.EffectHandle = Bass.ChannelSetFX(this.ChannelHandle, this.Parameters.FXType, 0);
         if (this.EffectHandle == 0)
         {
             BassUtils.Throw();
         }
         this.IsActive = true;
     }
     if (!Bass.FXSetParameters(this.EffectHandle, this.Parameters))
     {
         BassUtils.Throw();
     }
 }
示例#25
0
 public override void Stop()
 {
     if (this.IsStopped)
     {
         return;
     }
     Logger.Write(this, LogLevel.Debug, "Stopping channel: {0}", this.ChannelHandle);
     try
     {
         BassUtils.OK(Bass.ChannelStop(this.ChannelHandle));
     }
     catch (Exception e)
     {
         this.OnError(e);
         throw;
     }
 }
示例#26
0
 public override void Resume()
 {
     if (this.IsPlaying)
     {
         return;
     }
     Logger.Write(this, LogLevel.Debug, "Resuming channel: {0}", this.ChannelHandle);
     try
     {
         BassUtils.OK(Bass.ChannelPlay(this.ChannelHandle, false));
     }
     catch (Exception e)
     {
         this.OnError(e);
         throw;
     }
 }
示例#27
0
        protected virtual void OnInit(object sender, EventArgs e)
        {
            if (!this.Enabled || this.Drive == CdUtils.NO_DRIVE)
            {
                return;
            }
            var flags = BassFlags.Decode;

            if (this.Output.Float)
            {
                flags |= BassFlags.Float;
            }
            BassUtils.OK(BassGaplessCd.Init());
            BassUtils.OK(BassGaplessCd.Enable(this.Drive, flags));
            this.IsInitialized = true;
            Logger.Write(this, LogLevel.Debug, "BASS CD Initialized.");
        }
        public static void Init(int device)
        {
            IsInitialized = true;
            Device        = device;
            var info = default(DeviceInfo);

            BassUtils.OK(Bass.GetDeviceInfo(BassUtils.GetDeviceNumber(Device), out info));
            Devices[Device] = new BassDirectSoundDeviceInfo(
                info.Name,
                Bass.Info.SampleRate,
                0,
                Bass.Info.SpeakerCount,
                OutputRate.GetRates(Bass.Info.MinSampleRate, Bass.Info.MaxSampleRate)
                );
            LogManager.Logger.Write(typeof(BassDirectSoundDevice), LogLevel.Debug, "Detected DS device: {0} => Name => {1}, Inputs => {2}, Outputs = {3}, Rate = {4}", Device, Info.Name, Info.Inputs, Info.Outputs, Info.Rate);
            LogManager.Logger.Write(typeof(BassDirectSoundDevice), LogLevel.Debug, "Detected DS device: {0} => Rates => {1}", Device, string.Join(", ", Info.SupportedRates));
        }
示例#29
0
 public override void Stop()
 {
     if (this.IsStopped)
     {
         return;
     }
     try
     {
         BassUtils.OK(this.StopWASAPI(true));
         this.IsPaused = false;
     }
     catch (Exception e)
     {
         this.OnError(e);
         throw;
     }
 }
        public override bool CheckFormat(BassOutputStream stream)
        {
            var rate     = default(int);
            var channels = default(int);

            if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
            {
                rate     = BassUtils.GetChannelDsdRate(stream.ChannelHandle);
                channels = BassUtils.GetChannelCount(stream.ChannelHandle);
            }
            else
            {
                rate     = BassUtils.GetChannelPcmRate(stream.ChannelHandle);
                channels = BassUtils.GetChannelCount(stream.ChannelHandle);
            }
            return(this.Rate == rate && this.Channels == channels);
        }