예제 #1
0
        public static void Detect(int device)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Device is already initialized.");
            }

            IsInitialized = true;

            Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Detecting ASIO device.");

            try
            {
                BassAsioUtils.OK(BassAsio.Init(device, AsioInitFlags.Thread));
                BassAsioUtils.OK(BassAsioHandler.Init());
                var info = default(AsioChannelInfo);
                BassAsioUtils.OK(BassAsio.ChannelGetInfo(false, PRIMARY_CHANNEL, out info));
                Info = new BassAsioDeviceInfo(
                    BassAsio.CurrentDevice,
                    Convert.ToInt32(BassAsio.Rate),
                    BassAsio.Info.Inputs,
                    BassAsio.Info.Outputs,
                    GetSupportedRates(),
                    info.Format
                    );
                Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Detected ASIO device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", BassAsio.CurrentDevice, Info.Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(AsioSampleFormat), Info.Format));
                Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Detected ASIO device: {0} => Rates => {1}", BassAsio.CurrentDevice, string.Join(", ", Info.SupportedRates));
            }
            finally
            {
                Free();
            }
        }
예제 #2
0
        public static void Init(int device)
        {
            if (device == BassAsioStreamOutputConfiguration.ASIO_NO_DEVICE)
            {
                throw new InvalidOperationException("A valid device must be provided.");
            }
            LogManager.Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Initializing BASS ASIO.");
            BassAsioUtils.OK(BassAsio.Init(device, AsioInitFlags.Thread));
            BassAsioUtils.OK(BassAsioHandler.Init());
            IsInitialized = true;
            var info = default(AsioChannelInfo);

            BassAsioUtils.OK(BassAsio.ChannelGetInfo(false, PRIMARY_CHANNEL, out info));
            Device          = device;
            Devices[device] = new BassAsioDeviceInfo(
                info.Name,
                Convert.ToInt32(BassAsio.Rate),
                BassAsio.Info.Inputs,
                BassAsio.Info.Outputs,
                GetSupportedRates(),
                info.Format
                );
            LogManager.Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Detected ASIO device: {0} => Name => {1}, Inputs => {2}, Outputs = {3}, Rate = {4}, Format = {5}", Device, Info.Name, Info.Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(AsioSampleFormat), Info.Format));
            LogManager.Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Detected ASIO device: {0} => Rates => {1}", Device, string.Join(", ", Info.SupportedRates));
        }
예제 #3
0
        internal clsBASSOutDevAsio()
        {
            //* create mixer stream
            //* get asio infos
            AsioDeviceInfo asiodevinfo = new AsioDeviceInfo();

            BassAsio.GetDeviceInfo(AsioDevNum, out asiodevinfo);
            Debug.WriteLine("AsioDevInfo " + AsioDevNum + ": " + asiodevinfo.ToString());

            AsioInfo asioinfo;
            bool     ok = BassAsio.GetInfo(out asioinfo);

            if (!ok || asioinfo.Name == "")
            {
                Debug.WriteLine("No Asio Info");
            }
            else
            {
                Debug.WriteLine("AsioInfo " + ": " + asioinfo.ToString());
            }

            //AsioChannelInfo chaninfo = BassAsio.ChannelGetInfo(false, AsioDevNum);
            //if (chaninfo.Name == null || chaninfo.Name == "") Debug.WriteLine("No Asio Channel Info");
            //else Debug.WriteLine("AsioChannelInfo " + ": " + chaninfo.ToString());

            //* init
            //* no update - not played via BASS
            //* init nosound device
            Bass.Configure(Configuration.UpdatePeriod, 0);
            CheckOKHard(Bass.Init(0, 48000, 0, P.frmSC.Handle)); //44100 ignored (dev0=nosound/decode)
            //CheckOKHard(Bass.SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0));
            //Bass.UpdatePeriod = 0;
            //* int mixer stream (no sound 2 channels=stereo)
            //MixerStream = TestBass.BASS_Mixer_StreamCreate(44100, 2,
            //  BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE);
            MixerStream = CheckHandleHard(BassMix.CreateMixerStream(44100, 2,
                                                                    BassFlags.Decode));
            //* init asio stream on asiodevnum (optional)
            //TestBass.BASS_ASIO_Init(AsioDevNum, BASSASIOInit.BASS_ASIO_DEFAULT);  //(asiodev, flags)
            CheckOKHard(BassAsio.Init(AsioDevNum, AsioInitFlags.None)); //(asiodev, flags)
            Start();                                                    //should be OK to start and add channels later
        }
예제 #4
0
            internal override void ShowAsioPanel()
            {
                int tmp = -1; //device to init temporarily
                int sel = Frm.cmbAudioOutput.SelectedIndex;
                int dev = BassAsio.CurrentDevice;

                if (sel >= 0)
                {
                    if (sel != dev)
                    {
                        tmp = sel;
                        BassAsio.Init(tmp, AsioInitFlags.None); //(asiodev, flags)
                    }
                    clsBassOutMidi.CheckOK(BassAsio.ControlPanel());
                }
                if (tmp >= 0)
                {
                    BassAsio.Free();
                }
            }
예제 #5
0
        public static void Init(int device, int rate, int channels, BassFlags flags)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Device is already initialized.");
            }

            IsInitialized = true;

            Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Initializing BASS ASIO.");

            try
            {
                BassAsioUtils.OK(BassAsio.Init(device, AsioInitFlags.Thread));
                BassAsioUtils.OK(BassAsioHandler.Init());
                BassAsioUtils.OK(BassAsioHandler.ChannelEnable(false, PRIMARY_CHANNEL));
                for (var channel = 1; channel < channels; channel++)
                {
                    Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Joining channel: {0} => {1}", channel, PRIMARY_CHANNEL);
                    BassAsioUtils.OK(BassAsio.ChannelJoin(false, channel, PRIMARY_CHANNEL));
                }

                if (flags.HasFlag(BassFlags.DSDRaw))
                {
                    InitDSD(device, rate, channels, flags);
                }
                else
                {
                    InitPCM(device, rate, channels, flags);
                }

                BassAsio.Rate = rate;

                Logger.Write(typeof(BassAsioDevice), LogLevel.Debug, "Initialized BASS ASIO.");
            }
            catch
            {
                Free();
                throw;
            }
        }
예제 #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();
        }
예제 #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();
        }