コード例 #1
0
 protected virtual void OnFreeDevice()
 {
     if (!BassAsioDevice.IsInitialized)
     {
         return;
     }
     BassAsioDevice.Free();
 }
コード例 #2
0
        public override void Connect(IBassStreamComponent previous)
        {
            if (previous.Channels > BassAsioDevice.Info.Outputs)
            {
                //TODO: We should down mix.
                Logger.Write(this, LogLevel.Error, "Cannot play stream with more channels than device outputs.");
                throw new NotImplementedException(string.Format("The stream contains {0} channels which is greater than {1} output channels provided by the device.", previous.Channels, BassAsioDevice.Info.Outputs));
            }
            if (!this.CheckFormat(this.Rate, previous.Channels))
            {
                Logger.Write(this, LogLevel.Error, "Cannot play stream with unsupported rate.");
                throw new NotImplementedException(string.Format("The stream has a rate of {0} which is not supported by the device.", this.Rate));
            }
            var exception = default(Exception);

            for (var a = 1; a <= CONNECT_ATTEMPTS; a++)
            {
                Logger.Write(this, LogLevel.Debug, "Configuring ASIO, attempt: {0}", a);
                try
                {
                    if (BassAsioUtils.OK(this.ConfigureASIO(previous)))
                    {
                        var success = default(bool);
                        if (previous.Flags.HasFlag(BassFlags.DSDRaw) || BassUtils.GetChannelDsdRaw(previous.ChannelHandle))
                        {
                            success = BassAsioUtils.OK(this.ConfigureASIO_DSD(previous));
                        }
                        else
                        {
                            success = BassAsioUtils.OK(this.ConfigureASIO_PCM(previous));
                        }
                        if (success)
                        {
                            Logger.Write(this, LogLevel.Debug, "Configured ASIO.");
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    exception = e;
                    Logger.Write(this, LogLevel.Warn, "Failed to configure ASIO: {0}", e.Message);
                    if (BassAsioDevice.IsInitialized)
                    {
                        Logger.Write(this, LogLevel.Warn, "Re-initializing ASIO, have you just switched from DSD to PCM?");
                        BassAsioDevice.Free();
                        BassAsioDevice.Init();
                    }
                }
                Thread.Sleep(CONNECT_ATTEMPT_INTERVAL);
            }
            if (exception != null)
            {
                throw exception;
            }
            throw new NotImplementedException();
        }
コード例 #3
0
 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();
 }
コード例 #4
0
 protected virtual void OnInitDevice()
 {
     if (BassAsioDevice.IsInitialized)
     {
         return;
     }
     BassAsioDevice.Init(this.AsioDevice);
     if (this.Output.EnforceRate && !BassAsioDevice.Info.SupportedRates.Contains(this.Output.Rate))
     {
         var supportedRates = string.Join(
             ", ",
             BassAsioDevice.Info.SupportedRates
             );
         Logger.Write(this, LogLevel.Error, "The output rate {0} is not supported by the device, supported rates are: {1}", this.Output.Rate, supportedRates);
         BassAsioDevice.Free();
         throw new NotImplementedException(string.Format("The output rate {0} is not supported by the device, supported rates are: {1}", this.Output.Rate, supportedRates));
     }
 }
コード例 #5
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     this.IsInitialized = true;
     BassAsioUtils.OK(Bass.Configure(global::ManagedBass.Configuration.UpdateThreads, 0));
     BassAsioUtils.OK(Bass.Configure(global::ManagedBass.Configuration.PlaybackBufferLength, this.Output.BufferLength));
     BassAsioUtils.OK(Bass.Configure(global::ManagedBass.Configuration.SRCQuality, this.Output.ResamplingQuality));
     BassAsioUtils.OK(Bass.Init(Bass.NoSoundDevice));
     //Always detect device for now.
     //if (BassAsioDevice.Info != null && BassAsioDevice.Info.Device != this.AsioDevice)
     {
         BassAsioDevice.Detect(this.AsioDevice);
     }
     Logger.Write(this, LogLevel.Debug, "BASS (No Sound) Initialized.");
 }
コード例 #6
0
 protected virtual void ConfigureASIO(IBassStreamComponent previous)
 {
     if (previous.Flags.HasFlag(BassFlags.DSDRaw))
     {
         this.Rate   = previous.Rate;
         this.Flags |= BassFlags.DSDRaw;
     }
     else
     {
         if (this.Behaviour.Output.EnforceRate)
         {
             if (!BassAsioDevice.Info.SupportedRates.Contains(this.Rate))
             {
                 var nearestRate = BassAsioDevice.Info.GetNearestRate(this.Rate);
                 Logger.Write(this, LogLevel.Warn, "Enforced rate {0} isn't supposed by the device, falling back to {1}.", this.Rate, nearestRate);
                 this.Rate = nearestRate;
             }
             else
             {
                 //Enfoced rate is supported by the device, nothing to do.
             }
         }
         else
         {
             if (!BassAsioDevice.Info.SupportedRates.Contains(previous.Rate))
             {
                 var nearestRate = BassAsioDevice.Info.GetNearestRate(previous.Rate);
                 Logger.Write(this, LogLevel.Debug, "Stream rate {0} isn't supposed by the device, falling back to {1}.", this.Rate, nearestRate);
                 this.Rate = nearestRate;
             }
             else
             {
                 //Stream rate is supported by the device, nothing to do.
                 this.Rate = previous.Rate;
             }
         }
     }
     BassAsioDevice.Init(
         this.Behaviour.AsioDevice,
         this.Rate,
         this.Channels,
         this.Flags
         );
 }