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);
        }
Beispiel #2
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));
        }
Beispiel #3
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();
        }
Beispiel #4
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();
        }