public BassAsioStreamOutput(BassAsioStreamOutputBehaviour behaviour, BassOutputStream stream)
     : this()
 {
     this.Behaviour = behaviour;
     if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
     {
         this.Rate   = BassUtils.GetChannelDsdRate(stream.ChannelHandle);
         this.Flags |= BassFlags.DSDRaw;
     }
     else
     {
         if (behaviour.Output.Rate == stream.Rate)
         {
             this.Rate = stream.Rate;
         }
         else if (!behaviour.Output.EnforceRate && BassAsioDevice.Info.SupportedRates.Contains(stream.Rate))
         {
             this.Rate = stream.Rate;
         }
         else
         {
             Logger.Write(this, LogLevel.Debug, "The requested output rate is either enforced or the device does not support the stream's rate: {0} => {1}", stream.Rate, behaviour.Output.Rate);
             this.Rate = behaviour.Output.Rate;
         }
         if (behaviour.Output.Float)
         {
             this.Flags |= BassFlags.Float;
         }
     }
     this.Channels = stream.Channels;
 }
Esempio n. 2
0
        public override async Task <int> CreateStream(PlaylistItem playlistItem, BassFlags flags)
#endif
        {
            if (!flags.HasFlag(BassFlags.DSDRaw))
            {
#if NET40
                return(base.CreateStream(playlistItem, flags));
#else
                return(await base.CreateStream(playlistItem, flags).ConfigureAwait(false));
#endif
            }
#if NET40
            this.Semaphore.Wait();
#else
            await this.Semaphore.WaitAsync().ConfigureAwait(false);
#endif
            try
            {
                var channelHandle = default(int);
                if (this.Output != null && this.Output.PlayFromMemory)
                {
                    channelHandle = BassDsdInMemoryHandler.CreateStream(playlistItem.FileName, 0, 0, flags);
                    if (channelHandle == 0)
                    {
                        Logger.Write(this, LogLevel.Warn, "Failed to load file into memory: {0}", playlistItem.FileName);
                    }
                }
                else
                {
                    channelHandle = BassDsd.CreateStream(playlistItem.FileName, 0, 0, flags);
                }
                if (channelHandle != 0)
                {
                    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);
                        this.FreeStream(playlistItem, channelHandle);
                        channelHandle = 0;
                    }
                }
#if NET40
                return(TaskEx.FromResult(channelHandle));
#else
                return(channelHandle);
#endif
            }
            finally
            {
                this.Semaphore.Release();
            }
        }
        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);
        }
        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);
        }
 public BassGaplessStreamInput(BassGaplessStreamInputBehaviour behaviour, BassOutputStream stream)
 {
     this.Behaviour = behaviour;
     this.Channels  = stream.Channels;
     this.Flags     = BassFlags.Decode;
     if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
     {
         this.Rate   = BassUtils.GetChannelDsdRate(stream.ChannelHandle);
         this.Flags |= BassFlags.DSDRaw;
     }
     else
     {
         this.Rate = stream.Rate;
         if (behaviour.Output.Float)
         {
             this.Flags |= BassFlags.Float;
         }
     }
 }