Exemple #1
0
 protected virtual void OnFreeDevice()
 {
     if (!BassAsioDevice.IsInitialized)
     {
         return;
     }
     BassAsioDevice.Free();
 }
        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();
        }
 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();
 }
Exemple #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));
     }
 }