Example #1
0
        /// <summary>
        /// Gets a waveform of the specified channel
        /// </summary>
        /// <param name="channelOffset"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public float[] GetWaveform(int channelOffset = -1, int size = 256)
        {
            if (0 > size)
            {
                throw new ArgumentOutOfRangeException("size");
            }
            var result = new float[size];

            BassMix.BASS_Mixer_ChannelGetData(channelHandle, result, size * sizeof(float)); // Length is actually number of bytes...
            return(result);
        }
Example #2
0
        /// <summary>
        /// FFTs the specified channel offset.
        /// </summary>
        /// <param name="channelOffset">The channel offset.</param>
        /// <param name="fftSize">Size of the FFT.</param>
        /// <returns></returns>
        public float[] FFT(int channelOffset = -1,
                           int fftSize       = 256)
        {
            if (!fftSize.IsPowerOfTwo())
            {
                throw new ArgumentOutOfRangeException("fftSize");
            }
            var result = new float[fftSize];

            //Bassh.BASS_ChannelGetData(mixerHandle, result, GetFFTSize(fftSize * 2) | (int) BASSData.BASS_DATA_FFT_REMOVEDC);
            BassMix.BASS_Mixer_ChannelGetData(channelHandle, result, GetFFTSize(fftSize * 2) | (int)BASSData.BASS_DATA_FFT_REMOVEDC);
            return(result);
        }
Example #3
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FPinInHandle.PinIsChanged || this.FChannel == null)
            {
                //Just Update the Handle
                double dhandle;
                this.FPinInHandle.GetValue(0, out dhandle);
                int ihandle = Convert.ToInt32(Math.Round(dhandle));

                if (this.FManager.Exists(ihandle))
                {
                    this.FChannel = this.FManager.GetChannel(ihandle);
                    if (this.FChannel.BassHandle.HasValue)
                    {
                        if (this.FChannel.IsDecoding)
                        {
                            int mixhandle = BassMix.BASS_Mixer_ChannelGetMixer(this.FChannel.BassHandle.Value);

                            if (mixhandle == 0)
                            {
                                // create a buffer of the source stream
                                //We can't get it from the main stream otherwise it would interfere with the asio buffering
                                bufferStream = new DSP_BufferStream();
                                bufferStream.ChannelHandle = this.FChannel.BassHandle.Value; // the stream to copy
                                bufferStream.DSPPriority   = -4000;
                                bufferStream.Start();
                                this.FMyBassHandle = bufferStream.BufferStream;
                                this.FMixer        = false;
                            }
                            else
                            {
                                //We have a mixer, much better :)
                                this.FMyBassHandle = this.FChannel.BassHandle.Value;
                                this.FMixer        = true;
                            }
                        }
                        else
                        {
                            //If it's not decoding, no problem :)
                            this.FMyBassHandle = this.FChannel.BassHandle.Value;
                            this.FMixer        = false;
                        }
                    }
                    else
                    {
                        this.FMyBassHandle = 0;
                        this.FChannel      = null;
                    }
                }
                else
                {
                    this.FMyBassHandle = 0;
                    this.FChannel      = null;
                }
            }

            int len = this.DataLength;

            this.FPinOutSize.SetValue(0, len);

            if (len != -1)
            {
                BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(this.FChannel.BassHandle.Value);

                //We get float, so length is divided by 4
                float[] samples = new float[len];
                int     val;

                if (this.FMixer)
                {
                    val = BassMix.BASS_Mixer_ChannelGetData(this.FMyBassHandle, samples, this.DataType);
                }
                else
                {
                    val = Bass.BASS_ChannelGetData(this.FMyBassHandle, samples, this.DataType);
                }
                this.SetData(samples);
                this.FPinOutMsg.SetString(0, "OK");
            }
            else
            {
                this.FPinOutMsg.SetString(0, this.ErrorMsg);
            }
        }
Example #4
0
        public override void OnStarted()
        {
            int num = Bass.BASS_GetDevice();

            if (num != this._streamCopyDevice)
            {
                Bass.BASS_SetDevice(this._streamCopyDevice);
            }
            if (base.ChannelBitwidth == 32)
            {
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_8BITS;
                this._streamCopyFlags |= BASSFlag.BASS_SAMPLE_FLOAT;
            }
            else if (base.ChannelBitwidth == 8)
            {
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_FLOAT;
                this._streamCopyFlags |= BASSFlag.BASS_SAMPLE_8BITS;
            }
            else
            {
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_FLOAT;
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_8BITS;
            }
            int num2 = Bass.BASS_StreamCreatePush(base.ChannelSampleRate, base.ChannelNumChans, this._streamCopyFlags, IntPtr.Zero);

            this._streamCopyDelay = 0;
            if (this.SourceMixerStream == 0)
            {
                Bass.BASS_ChannelLock(base.ChannelHandle, true);
            }
            else
            {
                Bass.BASS_ChannelLock(this.SourceMixerStream, true);
            }
            if (this._isOutputBuffered)
            {
                if (this.SourceMixerStream != 0)
                {
                    if (this.TargetMixerStream != 0)
                    {
                        if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                        {
                            int num3 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                            int num4 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                            num4 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num4));
                            if (num4 > 0)
                            {
                                num3 -= num4;
                            }
                            if (num3 > 0)
                            {
                                int num5 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                                if (num4 > 0)
                                {
                                    num5 = 0;
                                }
                                byte[] array = new byte[num3];
                                num3 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array, num3);
                                if (num3 > num5)
                                {
                                    if (num5 > 0)
                                    {
                                        Array.Copy(array, num5, array, 0, num3 - num5);
                                    }
                                    Bass.BASS_StreamPutData(num2, array, num3 - num5);
                                }
                            }
                        }
                        else
                        {
                            int num6 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                            num6 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num6));
                            int num7 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                            num7  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num7));
                            num6 -= num7;
                            if (num6 > 0)
                            {
                                int num8 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                                if (num7 > 0)
                                {
                                    num8 = 0;
                                }
                                byte[] array2 = new byte[num6];
                                if (!base.ChannelInfo.IsDecodingChannel)
                                {
                                    num6 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array2, num6);
                                    num6 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num6));
                                }
                                if (num6 > num8)
                                {
                                    if (num8 > 0)
                                    {
                                        Array.Copy(array2, num8, array2, 0, num6 - num8);
                                    }
                                    Bass.BASS_StreamPutData(num2, array2, num6 - num8);
                                }
                            }
                        }
                    }
                    else if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                    {
                        int num9 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                        if (num9 > 0)
                        {
                            int    num10  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                            byte[] array3 = new byte[num9];
                            num9 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array3, num9);
                            if (num9 > num10)
                            {
                                if (num10 > 0)
                                {
                                    Array.Copy(array3, num10, array3, 0, num9 - num10);
                                }
                                Bass.BASS_StreamPutData(num2, array3, num9 - num10);
                            }
                        }
                    }
                    else
                    {
                        int num11 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                        num11 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num11));
                        if (num11 > 0)
                        {
                            int    num12  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                            byte[] array4 = new byte[num11];
                            if (!base.ChannelInfo.IsDecodingChannel)
                            {
                                num11 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array4, num11);
                                num11 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num11));
                            }
                            if (num11 > num12)
                            {
                                if (num12 > 0)
                                {
                                    Array.Copy(array4, num12, array4, 0, num11 - num12);
                                }
                                Bass.BASS_StreamPutData(num2, array4, num11 - num12);
                            }
                        }
                    }
                }
                else if (!base.ChannelInfo.IsDecodingChannel)
                {
                    int    num13  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                    int    num14  = Bass.BASS_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                    byte[] array5 = new byte[num14];
                    num14 = Bass.BASS_ChannelGetData(base.ChannelHandle, array5, num14);
                    if (num14 > num13)
                    {
                        if (num13 > 0)
                        {
                            Array.Copy(array5, num13, array5, 0, num14 - num13);
                        }
                        Bass.BASS_StreamPutData(num2, array5, num14 - num13);
                    }
                }
            }
            this._streamCopy = num2;
            if (this.TargetMixerStream != 0 && (this._streamCopyFlags & BASSFlag.BASS_STREAM_DECODE) != BASSFlag.BASS_DEFAULT)
            {
                BassMix.BASS_Mixer_StreamAddChannel(this.TargetMixerStream, this._streamCopy, ((BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT) ? BASSFlag.BASS_RECORD_ECHOCANCEL : BASSFlag.BASS_DEFAULT);
                if (!this._isTargetMixerImmediate && !this._isTargetMixerNonstop)
                {
                    Bass.BASS_ChannelUpdate(this.TargetMixerStream, 0);
                }
            }
            if ((!base.ChannelInfo.IsDecodingChannel || this.SourceMixerStream != 0) && Bass.BASS_ChannelIsActive(base.ChannelHandle) == BASSActive.BASS_ACTIVE_PLAYING)
            {
                Bass.BASS_ChannelPlay(this._streamCopy, false);
            }
            if (this.SourceMixerStream == 0)
            {
                Bass.BASS_ChannelLock(base.ChannelHandle, false);
            }
            else
            {
                Bass.BASS_ChannelLock(this.SourceMixerStream, false);
            }
            if (!base.ChannelInfo.IsDecodingChannel)
            {
                Bass.BASS_ChannelSetLink(base.ChannelHandle, this._streamCopy);
            }
            Bass.BASS_SetDevice(num);
        }
Example #5
0
 public override void OnBypassChanged()
 {
     if (base.IsBypassed)
     {
         if (this._isOutputBuffered && !base.ChannelInfo.IsDecodingChannel)
         {
             Bass.BASS_ChannelPause(this._streamCopy);
             Bass.BASS_ChannelSetPosition(this._streamCopy, 0L);
             return;
         }
     }
     else
     {
         int streamCopy = this._streamCopy;
         this._streamCopy = 0;
         if (this.SourceMixerStream == 0)
         {
             Bass.BASS_ChannelLock(base.ChannelHandle, true);
         }
         else
         {
             Bass.BASS_ChannelLock(this.SourceMixerStream, true);
         }
         if (this._isOutputBuffered)
         {
             if (this.SourceMixerStream != 0)
             {
                 if (this.TargetMixerStream != 0)
                 {
                     if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                     {
                         int num  = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                         int num2 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                         num2 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num2));
                         if (num2 > 0)
                         {
                             num -= num2;
                         }
                         if (num > 0)
                         {
                             int num3 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                             if (num2 > 0)
                             {
                                 num3 = 0;
                             }
                             byte[] array = new byte[num];
                             num = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array, num);
                             if (num > num3)
                             {
                                 if (num3 > 0)
                                 {
                                     Array.Copy(array, num3, array, 0, num - num3);
                                 }
                                 Bass.BASS_StreamPutData(streamCopy, array, num - num3);
                             }
                         }
                     }
                     else
                     {
                         int num4 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                         num4 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num4));
                         int num5 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                         num5  = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num5));
                         num4 -= num5;
                         if (num4 > 0)
                         {
                             int num6 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                             if (num5 > 0)
                             {
                                 num6 = 0;
                             }
                             byte[] array2 = new byte[num4];
                             if (!base.ChannelInfo.IsDecodingChannel)
                             {
                                 num4 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array2, num4);
                                 num4 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num4));
                             }
                             if (num4 > num6)
                             {
                                 if (num6 > 0)
                                 {
                                     Array.Copy(array2, num6, array2, 0, num4 - num6);
                                 }
                                 Bass.BASS_StreamPutData(streamCopy, array2, num4 - num6);
                             }
                         }
                     }
                 }
                 else if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                 {
                     int num7 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                     if (num7 > 0)
                     {
                         int    num8   = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                         byte[] array3 = new byte[num7];
                         num7 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array3, num7);
                         if (num7 > num8)
                         {
                             if (num8 > 0)
                             {
                                 Array.Copy(array3, num8, array3, 0, num7 - num8);
                             }
                             Bass.BASS_StreamPutData(streamCopy, array3, num7 - num8);
                         }
                     }
                 }
                 else
                 {
                     int num9 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                     num9 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num9));
                     if (num9 > 0)
                     {
                         int    num10  = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                         byte[] array4 = new byte[num9];
                         if (!base.ChannelInfo.IsDecodingChannel)
                         {
                             num9 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array4, num9);
                             num9 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num9));
                         }
                         if (num9 > num10)
                         {
                             if (num10 > 0)
                             {
                                 Array.Copy(array4, num10, array4, 0, num9 - num10);
                             }
                             Bass.BASS_StreamPutData(streamCopy, array4, num9 - num10);
                         }
                     }
                 }
             }
             else if (!base.ChannelInfo.IsDecodingChannel)
             {
                 int    num11  = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                 int    num12  = Bass.BASS_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                 byte[] array5 = new byte[num12];
                 num12 = Bass.BASS_ChannelGetData(base.ChannelHandle, array5, num12);
                 if (num12 > num11)
                 {
                     if (num11 > 0)
                     {
                         Array.Copy(array5, num11, array5, 0, num12 - num11);
                     }
                     Bass.BASS_StreamPutData(streamCopy, array5, num12 - num11);
                 }
             }
         }
         this._streamCopy = streamCopy;
         if (this.TargetMixerStream != 0 && !this._isTargetMixerImmediate && !this._isTargetMixerNonstop)
         {
             Bass.BASS_ChannelUpdate(this.TargetMixerStream, 0);
         }
         if ((!base.ChannelInfo.IsDecodingChannel || this.SourceMixerStream != 0) && Bass.BASS_ChannelIsActive(base.ChannelHandle) == BASSActive.BASS_ACTIVE_PLAYING)
         {
             Bass.BASS_ChannelPlay(this._streamCopy, false);
         }
         if (this.SourceMixerStream == 0)
         {
             Bass.BASS_ChannelLock(base.ChannelHandle, false);
             return;
         }
         Bass.BASS_ChannelLock(this.SourceMixerStream, false);
     }
 }