예제 #1
0
        public BassAsioHandler(int asioDevice, int asioChannel, int outputChannel)
        {
            this._input         = false;
            this._device        = asioDevice;
            this._channel       = asioChannel;
            this._outputChannel = outputChannel;
            BassAsio.BASS_ASIO_Init(asioDevice, BassAsioHandler.UseDedicatedThreads ? BASSASIOInit.BASS_ASIO_THREAD : BASSASIOInit.BASS_ASIO_DEFAULT);
            BassAsio.BASS_ASIO_SetDevice(asioDevice);
            this.GetChannelInfo(outputChannel);
            this._numchans = this._outputChannelInfo.chans;
            this._format   = BASSASIOFormat.BASS_ASIO_FORMAT_16BIT;
            if ((this._outputChannelInfo.flags & BASSFlag.BASS_SAMPLE_FLOAT) != BASSFlag.BASS_DEFAULT)
            {
                this._format = BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT;
            }
            this._samplerate = (double)this._outputChannelInfo.freq;
            BassAsio.BASS_ASIO_SetRate(this._samplerate);
            this._internalAsioProc = new ASIOPROC(this.AsioOutputCallback);
            bool           flag           = BassAsio.BASS_ASIO_IsStarted();
            BASSASIOActive bassasioactive = BassAsio.BASS_ASIO_ChannelIsActive(this._input, this._channel);

            if (flag && bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_DISABLED)
            {
                BassAsio.BASS_ASIO_Stop();
            }
            this.EnableAndJoin(this._input, this._channel, this._numchans, this._internalAsioProc, this._format);
            if (flag)
            {
                BassAsio.BASS_ASIO_Start(0, 0);
            }
        }
예제 #2
0
        public bool AssignOutputChannel(int outputChannel)
        {
            if (this._input)
            {
                return(false);
            }
            bool flag = true;
            int  num  = BassAsio.BASS_ASIO_GetDevice();

            if (num != this._device)
            {
                flag &= BassAsio.BASS_ASIO_SetDevice(this._device);
            }
            if (flag)
            {
                BASSASIOActive bassasioactive = BassAsio.BASS_ASIO_ChannelIsActive(this._input, this._channel);
                if (bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_ENABLED)
                {
                    BassAsio.BASS_ASIO_ChannelPause(this._input, this._channel);
                }
                this._outputChannel = outputChannel;
                if (this._outputChannel == 0)
                {
                    this._samplerate       = BassAsio.BASS_ASIO_GetRate();
                    this._numchans         = 1;
                    this._format           = BASSASIOFormat.BASS_ASIO_FORMAT_16BIT;
                    this._internalAsioProc = new ASIOPROC(this.AsioOutputCallback);
                }
                else
                {
                    this.GetChannelInfo(this._outputChannel);
                    this._numchans = this._outputChannelInfo.chans;
                    this._format   = BASSASIOFormat.BASS_ASIO_FORMAT_16BIT;
                    if ((this._outputChannelInfo.flags & BASSFlag.BASS_SAMPLE_FLOAT) != BASSFlag.BASS_DEFAULT)
                    {
                        this._format = BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT;
                    }
                    this._samplerate = (double)this._outputChannelInfo.freq;
                }
                BassAsio.BASS_ASIO_SetRate(this._samplerate);
                if (bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_DISABLED)
                {
                    this._internalAsioProc = new ASIOPROC(this.AsioOutputCallback);
                }
                flag &= this.EnableAndJoin(this._input, this._channel, this._numchans, this._internalAsioProc, this._format);
                if (bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_ENABLED)
                {
                    BassAsio.BASS_ASIO_ChannelReset(this._input, this._channel, BASSASIOReset.BASS_ASIO_RESET_PAUSE);
                }
            }
            BassAsio.BASS_ASIO_SetDevice(num);
            return(flag);
        }
예제 #3
0
        private int AsioCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
        {
            //We deal only with outputs here
            //And if the channel has it's own handler, we ignore it
            if (!this.FOutputHandled.Contains(channel) && !input)
            {
                if (this.manager.Exists(user.ToInt32()))
                {
                    ChannelInfo channelinfo = this.manager.GetChannel(user.ToInt32());
                    if (channelinfo.Play && channelinfo.IsDecoding)
                    {
                        int _decLength;

                        BASSASIOActive _status = BassAsio.BASS_ASIO_ChannelIsActive(false, channel);
                        //BASSActive _status = Bass.BASS_ChannelIsActive(user.ToInt32());
                        // now we evaluate the status...
                        if (_status != BASSASIOActive.BASS_ASIO_ACTIVE_ENABLED)
                        {
                            //BassAsio.BASS_ASIO_ChannelPause(false, channel);
                            return(0);
                        }
                        else
                        {
                            //BassAsio.BASS_ASIO_ChannelReset(false, channel, BASSASIOReset.BASS_ASIO_RESET_PAUSE);
                            _decLength = Bass.BASS_ChannelGetData(channelinfo.BassHandle.Value, buffer, length);

                            if (_decLength < 0)
                            {
                                _decLength = 0;
                            }
                            return(_decLength);
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
예제 #4
0
        public bool SetMirror(int asioChannel)
        {
            if (!this._input && this._channel == asioChannel)
            {
                return(false);
            }
            bool flag = true;
            int  num  = BassAsio.BASS_ASIO_GetDevice();

            if (num != this._device)
            {
                flag &= BassAsio.BASS_ASIO_SetDevice(this._device);
            }
            if (flag)
            {
                bool           flag2          = BassAsio.BASS_ASIO_IsStarted();
                BASSASIOActive bassasioactive = BassAsio.BASS_ASIO_ChannelIsActive(false, asioChannel);
                if (flag2)
                {
                    BassAsio.BASS_ASIO_Stop();
                }
                for (int i = 0; i < this._numchans; i++)
                {
                    flag &= BassAsio.BASS_ASIO_ChannelEnableMirror(asioChannel + i, this._input, this._channel + i);
                }
                if (flag)
                {
                    this._mirrorChannel = asioChannel;
                }
                else if (bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_DISABLED)
                {
                    for (int j = 0; j < this._numchans; j++)
                    {
                        BassAsio.BASS_ASIO_ChannelEnable(false, asioChannel + j, null, IntPtr.Zero);
                        BassAsio.BASS_ASIO_ChannelReset(false, asioChannel + j, BASSASIOReset.BASS_ASIO_RESET_ENABLE | BASSASIOReset.BASS_ASIO_RESET_FORMAT | BASSASIOReset.BASS_ASIO_RESET_RATE | BASSASIOReset.BASS_ASIO_RESET_VOLUME);
                    }
                }
                if (flag2)
                {
                    BassAsio.BASS_ASIO_Start(0, 0);
                }
            }
            BassAsio.BASS_ASIO_SetDevice(num);
            return(flag);
        }
예제 #5
0
        public BassAsioHandler(bool input, int asioDevice, int asioChannel, int asioNumChans, BASSASIOFormat asioFormat, double asioSamplerate)
        {
            this._input    = input;
            this._device   = asioDevice;
            this._channel  = asioChannel;
            this._numchans = asioNumChans;
            this._format   = asioFormat;
            BassAsio.BASS_ASIO_Init(asioDevice, BassAsioHandler.UseDedicatedThreads ? BASSASIOInit.BASS_ASIO_THREAD : BASSASIOInit.BASS_ASIO_DEFAULT);
            BassAsio.BASS_ASIO_SetDevice(asioDevice);
            if (asioSamplerate <= 0.0)
            {
                this._samplerate = BassAsio.BASS_ASIO_GetRate();
            }
            else
            {
                BassAsio.BASS_ASIO_SetRate(asioSamplerate);
                this._samplerate = BassAsio.BASS_ASIO_GetRate();
            }
            if (this._input)
            {
                this._internalAsioProc = new ASIOPROC(this.AsioInputCallback);
                this.UseInput          = true;
            }
            else
            {
                this._internalAsioProc = new ASIOPROC(this.AsioOutputCallback);
            }
            bool           flag           = BassAsio.BASS_ASIO_IsStarted();
            BASSASIOActive bassasioactive = BassAsio.BASS_ASIO_ChannelIsActive(this._input, this._channel);

            if (flag && bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_DISABLED)
            {
                BassAsio.BASS_ASIO_Stop();
            }
            this.EnableAndJoin(this._input, this._channel, this._numchans, this._internalAsioProc, this._format);
            if (flag)
            {
                BassAsio.BASS_ASIO_Start(0, 0);
            }
        }
예제 #6
0
        public bool RemoveFullDuplex(bool disableOutput)
        {
            if (!this.IsInputFullDuplex)
            {
                return(false);
            }
            bool flag = true;
            int  num  = BassAsio.BASS_ASIO_GetDevice();

            if (this._fullDuplexChannel != -1 && num != this._fullDuplexDevice)
            {
                flag &= BassAsio.BASS_ASIO_SetDevice(this._fullDuplexDevice);
            }
            if (flag)
            {
                bool flag2 = false;
                if (this._fullDuplexChannel != -1)
                {
                    flag2 = BassAsio.BASS_ASIO_IsStarted();
                    BASSASIOActive bassasioactive = BassAsio.BASS_ASIO_ChannelIsActive(false, this._fullDuplexChannel);
                    if (flag2 && disableOutput && bassasioactive != BASSASIOActive.BASS_ASIO_ACTIVE_DISABLED)
                    {
                        BassAsio.BASS_ASIO_Stop();
                        flag &= BassAsio.BASS_ASIO_ChannelEnable(false, this._fullDuplexChannel, null, IntPtr.Zero);
                        if (flag)
                        {
                            BassAsio.BASS_ASIO_ChannelReset(false, this._fullDuplexChannel, BASSASIOReset.BASS_ASIO_RESET_ENABLE | BASSASIOReset.BASS_ASIO_RESET_FORMAT | BASSASIOReset.BASS_ASIO_RESET_RATE | BASSASIOReset.BASS_ASIO_RESET_VOLUME);
                            for (int i = 1; i < this._numchans; i++)
                            {
                                BassAsio.BASS_ASIO_ChannelReset(false, this._fullDuplexChannel + i, BASSASIOReset.BASS_ASIO_RESET_JOIN);
                            }
                        }
                    }
                }
                if (flag)
                {
                    this._fullDuplexChannel = -1;
                    this._fullDuplexDevice  = -1;
                    this._fullDuplex        = false;
                }
                if (flag2)
                {
                    BassAsio.BASS_ASIO_Start(0, 0);
                }
                if (flag)
                {
                    if (this._fullDuplexDevice != this._device)
                    {
                        flag &= BassAsio.BASS_ASIO_SetDevice(this._device);
                    }
                    if (flag)
                    {
                        this._internalAsioProc = new ASIOPROC(this.AsioInputCallback);
                        flag &= this.EnableAndJoin(this._input, this._channel, this._numchans, this._internalAsioProc, this._format);
                    }
                    Bass.Bass.BASS_StreamFree(this._outputChannel);
                    this._outputChannel    = 0;
                    this._fullDuplexBuffer = null;
                    this.BypassFullDuplex  = false;
                }
            }
            BassAsio.BASS_ASIO_SetDevice(num);
            return(flag);
        }
예제 #7
0
        public bool SetFullDuplex(int asioDevice, int asioChannel)
        {
            if (!this._input)
            {
                return(false);
            }
            bool flag = true;
            int  num  = BassAsio.BASS_ASIO_GetDevice();

            if (num != this._device)
            {
                flag &= BassAsio.BASS_ASIO_SetDevice(this._device);
            }
            if (flag)
            {
                if (this._outputChannel != 0)
                {
                    Bass.Bass.BASS_StreamFree(this._outputChannel);
                }
                BASSFlag bassflag = BASSFlag.BASS_STREAM_DECODE;
                if (this._format == BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT)
                {
                    bassflag |= BASSFlag.BASS_SAMPLE_FLOAT;
                }
                this._outputChannel = Bass.Bass.BASS_StreamCreateDummy((int)BassAsio.BASS_ASIO_GetRate(), this._numchans, bassflag, IntPtr.Zero);
                BASS_ASIO_INFO bass_ASIO_INFO = BassAsio.BASS_ASIO_GetInfo();
                this._fullDuplexBuffer = new byte[bass_ASIO_INFO.bufmax * this._numchans * 4];
                this._internalAsioProc = new ASIOPROC(this.AsioToAsioFullDuplexCallback);
                flag &= this.EnableAndJoin(this._input, this._channel, this._numchans, this._internalAsioProc, this._format);
                if (flag)
                {
                    if (this._device != asioDevice)
                    {
                        flag &= BassAsio.BASS_ASIO_SetDevice(asioDevice);
                    }
                    if (flag)
                    {
                        BassAsio.BASS_ASIO_SetRate(this._samplerate);
                        bool           flag2          = BassAsio.BASS_ASIO_IsStarted();
                        BASSASIOActive bassasioactive = BassAsio.BASS_ASIO_ChannelIsActive(false, asioChannel);
                        if (flag2 && bassasioactive == BASSASIOActive.BASS_ASIO_ACTIVE_DISABLED)
                        {
                            BassAsio.BASS_ASIO_Stop();
                        }
                        flag &= this.EnableAndJoin(false, asioChannel, this._numchans, this._internalAsioProc, this._format);
                        if (flag)
                        {
                            this._fullDuplexDevice  = asioDevice;
                            this._fullDuplexChannel = asioChannel;
                            this._fullDuplex        = true;
                        }
                        if (flag2)
                        {
                            BassAsio.BASS_ASIO_Start(0, 0);
                        }
                    }
                }
            }
            BassAsio.BASS_ASIO_SetDevice(num);
            return(flag);
        }