Ejemplo n.º 1
0
        protected virtual bool ConfigureASIO_PCM(IBassStreamComponent previous)
        {
            Logger.Write(this, LogLevel.Debug, "Configuring PCM.");
            BassAsioUtils.OK(BassAsio.SetDSD(false));
            if (!this.CheckFormat(this.Rate, this.Channels))
            {
                Logger.Write(this, LogLevel.Warn, "PCM format {0}:{1} is unsupported.", this.Rate, this.Channels);
                return(false);
            }
            else
            {
                BassAsio.Rate = this.Rate;
            }
            var format = default(AsioSampleFormat);

            if (previous.Flags.HasFlag(BassFlags.Float))
            {
                format = AsioSampleFormat.Float;
            }
            else
            {
                format = AsioSampleFormat.Bit16;
            }
            Logger.Write(this, LogLevel.Debug, "PCM: Rate = {0}, Format = {1}", BassAsio.Rate, Enum.GetName(typeof(AsioSampleFormat), format));
            BassAsioUtils.OK(BassAsio.ChannelSetRate(false, BassAsioDevice.PRIMARY_CHANNEL, previous.Rate));
            BassAsioUtils.OK(BassAsio.ChannelSetFormat(false, BassAsioDevice.PRIMARY_CHANNEL, format));
            return(true);
        }
Ejemplo n.º 2
0
 protected virtual bool ConfigureASIO_DSD(IBassStreamComponent previous)
 {
     try
     {
         Logger.Write(this, LogLevel.Debug, "Configuring DSD RAW.");
         try
         {
             BassAsioUtils.OK(BassAsio.SetDSD(true));
         }
         catch
         {
             //If we get here some drivers (at least Creative) will crash when BassAsio.Start is called.
             //I can't find a way to prevent it but it seems to be related to the allocated buffer size
             //not being what the driver *thinks* it is and over-flowing.
             //
             //It should be unlikely in real life as the device would have to report capability of some
             //very high PCM frequencies.
             Logger.Write(this, LogLevel.Error, "Failed to enable DSD RAW on the device. Creative ASIO driver becomes unstable and usually crashes soon...");
             return(false);
         }
         if (!this.CheckFormat(this.Rate, previous.Channels))
         {
             Logger.Write(this, LogLevel.Warn, "DSD format {0}:{1} is unsupported.", previous.Rate, previous.Channels);
             return(false);
         }
         else
         {
             BassAsio.Rate = this.Rate;
         }
         //It looks like BASS DSD always outputs 8 bit/MSB data so we don't need to determine the format.
         //var format = default(AsioSampleFormat);
         //switch (this.Depth)
         //{
         //    case BassAttribute.DSDFormat_LSB:
         //        format = AsioSampleFormat.DSD_LSB;
         //        break;
         //    case BassAttribute.DSDFormat_None:
         //    case BassAttribute.DSDFormat_MSB:
         //        format = AsioSampleFormat.DSD_MSB;
         //        break;
         //    default:
         //        throw new NotImplementedException();
         //}
         Logger.Write(this, LogLevel.Debug, "DSD: Rate = {0}, Format = {1}", BassAsio.Rate, Enum.GetName(typeof(AsioSampleFormat), AsioSampleFormat.DSD_MSB));
         BassAsioUtils.OK(BassAsio.ChannelSetFormat(false, BassAsioDevice.PRIMARY_CHANNEL, AsioSampleFormat.DSD_MSB));
         return(true);
     }
     catch (Exception e)
     {
         Logger.Write(this, LogLevel.Warn, "Failed to configure DSD RAW: {0}", e.Message);
         return(false);
     }
 }
Ejemplo n.º 3
0
        private static void InitPCM(int device, int rate, int channels, BassFlags flags)
        {
            BassAsioUtils.OK(BassAsio.SetDSD(false));
            BassAsioUtils.OK(BassAsio.ChannelSetRate(false, BassAsioDevice.PRIMARY_CHANNEL, rate));
            var format = default(AsioSampleFormat);

            if (flags.HasFlag(BassFlags.Float))
            {
                format = AsioSampleFormat.Float;
            }
            else
            {
                format = AsioSampleFormat.Bit16;
            }
            BassAsioUtils.OK(BassAsio.ChannelSetFormat(false, BassAsioDevice.PRIMARY_CHANNEL, format));
        }
Ejemplo n.º 4
0
        private void Start()
        {
            //Debug.WriteLine("{0} {1} {2} {3}", "Start ASIO handler: ", AsioDevNum, AsioChannel, MixerStream);
            //Bass.Configure(Configuration.UpdatePeriod, 0);
            BassAsio.CurrentDevice = AsioDevNum;
            AsioInfo asioinfo;

            BassAsio.GetInfo(out asioinfo);
            BassAsio.Rate = 44100;
            dAsioProc     = new AsioProcedure(AsioProc);
            Cfg.AsioProcs.Add(dAsioProc); //prevent Garbage Collection
            CheckOKHard(BassAsio.ChannelEnable(false, 0, dAsioProc));
            CheckOKHard(BassAsio.ChannelJoin(false, 1, 0));
            BassAsio.ChannelSetFormat(false, 0, AsioSampleFormat.Bit16);
            BassAsio.ChannelSetFormat(false, 1, AsioSampleFormat.Bit16);
            SetdB();
            CheckOKHard(BassAsio.Start(asioinfo.PreferredBufferLength));
            //CheckOK(Bass.ChannelPlay(MixerStream, false));  //can't play decode chan
        }
Ejemplo n.º 5
0
 private static void InitDSD(int device, int rate, int channels, BassFlags flags)
 {
     BassAsioUtils.OK(BassAsio.SetDSD(true));
     //It looks like BASS DSD always outputs 8 bit/MSB data so we don't need to determine the format.
     //var format = default(AsioSampleFormat);
     //switch (this.Depth)
     //{
     //    case BassAttribute.DSDFormat_LSB:
     //        format = AsioSampleFormat.DSD_LSB;
     //        break;
     //    case BassAttribute.DSDFormat_None:
     //    case BassAttribute.DSDFormat_MSB:
     //        format = AsioSampleFormat.DSD_MSB;
     //        break;
     //    default:
     //        throw new NotImplementedException();
     //}
     BassAsioUtils.OK(BassAsio.ChannelSetFormat(false, BassAsioDevice.PRIMARY_CHANNEL, AsioSampleFormat.DSD_MSB));
 }
Ejemplo n.º 6
0
        public void Test001()
        {
            if (!Bass.Init(Bass.NoSoundDevice, OUTPUT_RATE))
            {
                Assert.Fail(string.Format("Failed to initialize BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            var sourceChannel = Bass.CreateStream(@"D:\Source\Prototypes\Resources\1 - 6 - DYE (game version).mp3", 0, 0, BassFlags.Decode | BassFlags.Float);

            if (sourceChannel == 0)
            {
                Assert.Fail(string.Format("Failed to create source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            if (!BassSox.Init())
            {
                Assert.Fail("Failed to initialize SOX.");
            }

            var playbackChannel = BassSox.StreamCreate(OUTPUT_RATE, BassFlags.Decode | BassFlags.Float, sourceChannel);

            if (playbackChannel == 0)
            {
                Assert.Fail(string.Format("Failed to create playback stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            BassSox.ChannelSetAttribute(playbackChannel, SoxChannelAttribute.BufferLength, 5);
            BassSox.ChannelSetAttribute(playbackChannel, SoxChannelAttribute.Background, true);

            if (!BassAsio.Init(2, AsioInitFlags.Thread))
            {
                Assert.Fail(string.Format("Failed to initialize ASIO: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            if (!BassSoxAsio.StreamSet(playbackChannel))
            {
                Assert.Fail("Failed to set ASIO stream.");
            }

            if (!BassSoxAsio.ChannelEnable(false, 0))
            {
                Assert.Fail(string.Format("Failed to enable ASIO: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            if (!BassAsio.ChannelJoin(false, 1, 0))
            {
                Assert.Fail(string.Format("Failed to enable ASIO: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            if (!BassAsio.ChannelSetRate(false, 0, OUTPUT_RATE))
            {
                Assert.Fail(string.Format("Failed to set ASIO rate: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            if (!BassAsio.ChannelSetFormat(false, 0, AsioSampleFormat.Float))
            {
                Assert.Fail(string.Format("Failed to set ASIO format: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            BassAsio.Rate = OUTPUT_RATE;

            if (!BassAsio.Start())
            {
                Assert.Fail(string.Format("Failed to start ASIO: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            var channelLength        = Bass.ChannelGetLength(sourceChannel);
            var channelLengthSeconds = Bass.ChannelBytes2Seconds(sourceChannel, channelLength);

            Bass.ChannelSetPosition(sourceChannel, Bass.ChannelSeconds2Bytes(sourceChannel, channelLengthSeconds - 10));

            do
            {
                if (Bass.ChannelIsActive(sourceChannel) == PlaybackState.Stopped)
                {
                    break;
                }

                var channelPosition        = Bass.ChannelGetPosition(sourceChannel);
                var channelPositionSeconds = Bass.ChannelBytes2Seconds(sourceChannel, channelPosition);

                Console.WriteLine(
                    "{0}/{1}",
                    TimeSpan.FromSeconds(channelPositionSeconds).ToString("g"),
                    TimeSpan.FromSeconds(channelLengthSeconds).ToString("g")
                    );

                Thread.Sleep(1000);
            } while (true);

            BassAsio.Stop();

            BassSox.StreamFree(playbackChannel);
            Bass.StreamFree(sourceChannel);
            BassSox.Free();
            BassSoxAsio.Free();
            BassAsio.Free();
            Bass.Free();
        }
Ejemplo n.º 7
0
        public void Test001()
        {
            if (!Bass.Init(Bass.NoSoundDevice))
            {
                Assert.Fail(string.Format("Failed to initialize BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            if (!BassAsio.Init(2, AsioInitFlags.Thread))
            {
                Assert.Fail(string.Format("Failed to initialize ASIO: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            if (!BassGapless.Init() || !BassGaplessAsio.Init())
            {
                Assert.Fail("Failed to initialize GAPLESS.");
            }

            var sourceChannel1 = Bass.CreateStream(@"D:\Source\Prototypes\Resources\01 Botanical Dimensions.flac", 0, 0, BassFlags.Decode | BassFlags.Float);

            if (sourceChannel1 == 0)
            {
                Assert.Fail(string.Format("Failed to create source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            var sourceChannel2 = Bass.CreateStream(@"D:\Source\Prototypes\Resources\02 Outer Shpongolia.flac", 0, 0, BassFlags.Decode | BassFlags.Float);

            if (sourceChannel2 == 0)
            {
                Assert.Fail(string.Format("Failed to create source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            var channelInfo = default(ChannelInfo);

            if (!Bass.ChannelGetInfo(sourceChannel1, out channelInfo))
            {
                Assert.Fail(string.Format("Failed to get channel info: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            if (!BassGapless.ChannelEnqueue(sourceChannel1))
            {
                Assert.Fail("Failed to add stream to gapless queue.");
            }

            if (!BassGapless.ChannelEnqueue(sourceChannel2))
            {
                Assert.Fail("Failed to add stream to gapless queue.");
            }

            var sourceChannelCount = default(int);
            var sourceChannels     = BassGapless.GetChannels(out sourceChannelCount);

            if (sourceChannelCount != 2)
            {
                Assert.Fail("Gapless reports unexpected queued channel count.");
            }

            if (sourceChannels[0] != sourceChannel1 || sourceChannels[1] != sourceChannel2)
            {
                Assert.Fail("Gapless reports unexpected queued channel handles.");
            }

            {
                var ok = true;
                ok &= BassGaplessAsio.ChannelEnable(false, 0);
                ok &= BassAsio.ChannelJoin(false, 1, 0);
                ok &= BassAsio.ChannelSetFormat(false, 0, AsioSampleFormat.Float);
                ok &= BassAsio.ChannelSetRate(false, 0, channelInfo.Frequency);
                if (!ok)
                {
                    Assert.Fail("Failed to configure ASIO.");
                }
            }

            if (!BassAsio.Start())
            {
                Assert.Fail(string.Format("Failed to start ASIO: {0}", Enum.GetName(typeof(Errors), BassAsio.LastError)));
            }

            var channelLength        = Bass.ChannelGetLength(sourceChannel1);
            var channelLengthSeconds = Bass.ChannelBytes2Seconds(sourceChannel1, channelLength);

            Bass.ChannelSetPosition(sourceChannel1, Bass.ChannelSeconds2Bytes(sourceChannel1, channelLengthSeconds - 10));

            do
            {
                var channelActive1 = Bass.ChannelIsActive(sourceChannel1);
                var channelActive2 = Bass.ChannelIsActive(sourceChannel2);
                if (channelActive1 == PlaybackState.Stopped && channelActive2 == PlaybackState.Stopped)
                {
                    break;
                }

                var channelPosition        = Bass.ChannelGetPosition(sourceChannel2);
                var channelPositionSeconds = Bass.ChannelBytes2Seconds(sourceChannel2, channelPosition);

                if (channelPositionSeconds >= 10)
                {
                    break;
                }

                Thread.Sleep(1000);
            } while (true);

            if (BassGapless.ChannelRemove(sourceChannel1))
            {
                Assert.Fail("Queued gapless channel should have been removed.");
            }

            if (!BassGapless.ChannelRemove(sourceChannel2))
            {
                Assert.Fail("Failed to remove queued gapless channel.");
            }

            BassAsio.Stop();

            Bass.StreamFree(sourceChannel1);
            Bass.StreamFree(sourceChannel2);
            BassGapless.Free();
            BassGaplessAsio.Free();
            BassAsio.Free();
            Bass.Free();
        }