コード例 #1
0
        private decimal getData()
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(this.fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return(0m);
            }

            Int32 level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == this.lastLevel && level != 0)
            {
                this.hanctr++;
            }

            float left = Utils.LowWord32(level);

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (this.hanctr > 3)
            {
                this.hanctr = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                this.initialized = false;
                this.Init();
            }

            // convert to usable percentages
            decimal data = ((decimal)left / 10000 * 100);

            return(data);
        }
コード例 #2
0
        public int _getLevel()
        {
            int value = (Utils.LowWord32(BassWasapi.BASS_WASAPI_GetLevel()));

            //to get a value between 0 and 100
            value = (value * 100) / 32768;
            return(value);
        }
コード例 #3
0
        //timer
        public void _t_Tick(object sender, EventArgs e)
        {
            // get fft data. Return value is -1 on error
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048);

            if (ret < 0)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            MainWindow.ActiveWindow.modeMusic.SetIntensity(_spectrumdata);
            _spectrumdata.Clear();

            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;
        }
コード例 #4
0
        public bool GetChannelLevel(out double dbLevelL, out double dbLevelR)
        {
            dbLevelL = 0f;
            dbLevelR = 0f;
            if (!BassWasapi.BASS_WASAPI_IsStarted())
            {
                return(false);
            }
            int level = BassWasapi.BASS_WASAPI_GetLevel();

            dbLevelL = Un4seen.Bass.Utils.LevelToDB(Un4seen.Bass.Utils.LowWord32(level), 65535);  // the left level
            dbLevelR = Un4seen.Bass.Utils.LevelToDB(Un4seen.Bass.Utils.HighWord32(level), 65535); // the right level
            return(true);
        }
コード例 #5
0
        // Performs FFT analysis in order to detect beat
        private void PerformAnalysis()
        {
            // Specifes on which result end which band (dividing it into 10 bands)
            // 19 - bass, 187 - mids, rest is highs
            int[]    BandRange = { 4, 8, 18, 38, 48, 94, 140, 186, 466, 1022, 22000 };
            double[] BandsTemp = new double[BANDS];
            int      n         = 0;
            int      level     = BassWasapi.BASS_WASAPI_GetLevel();

            // Get FFT
            int ret = BassWasapi.BASS_WASAPI_GetData(_FFTData, (int)BASSData.BASS_DATA_FFT1024 | (int)BASSData.BASS_DATA_FFT_COMPLEX); //get channel fft data

            if (ret < -1)
            {
                return;
            }

            // Calculate the energy of every result and divide it into subbands
            float sum = 0;

            for (int i = 2; i < 2048; i = i + 2)
            {
                float real    = _FFTData[i];
                float complex = _FFTData[i + 1];
                sum += (float)Math.Sqrt((double)(real * real + complex * complex));

                if (i == BandRange[n])
                {
                    BandsTemp[n++] = (BANDS * sum) / 1024;
                    sum            = 0;
                }
            }

            // Detect beat basing on FFT results
            DetectBeat(BandsTemp, level);

            // Shift the history register and save new values
            ShiftHistory(1);

            for (int i = 0; i < BANDS; i++)
            {
                _History[i, 0] = BandsTemp[i];
            }
        }
コード例 #6
0
        private void KSIntegration_DoWork(object sender, DoWorkEventArgs e)
        {
            using (RegistryKey Mixer = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\OmniMIDI\", true))
            {
                if (Mixer != null && !IsWinXPOrOlder())
                {
                    RegistryKey SynthSettings = Registry.CurrentUser.OpenSubKey("SOFTWARE\\OmniMIDI\\Configuration", true);
                    RegistryKey Channels      = Registry.CurrentUser.OpenSubKey("SOFTWARE\\OmniMIDI\\Channels", true);
                    RegistryKey Watchdog      = Registry.CurrentUser.OpenSubKey("SOFTWARE\\KOmniMIDI\\Watchdog", true);
                    RegistryKey SynthPaths    = Registry.CurrentUser.OpenSubKey("SOFTWARE\\OmniMIDI\\Paths", true);
                    while (isitrunning)
                    {
                        try
                        {
                            if (chan != 0)
                            {
                                int levels = BassWasapi.BASS_WASAPI_GetLevel();

                                Mixer.SetValue("leftvol", Utils.LowWord32(levels), RegistryValueKind.DWord);
                                Mixer.SetValue("rightvol", Utils.HighWord32(levels), RegistryValueKind.DWord);
                                Mixer.SetValue("currentcpuusage0", cpu, RegistryValueKind.DWord);
                                for (int i = 1; i <= 16; i++)
                                {
                                    Mixer.SetValue(String.Format("chv{0}", i), BassMidi.BASS_MIDI_StreamGetEvent(chan, i - 1, (BASSMIDIEvent)0x20001), RegistryValueKind.DWord);
                                    BassMidi.BASS_MIDI_StreamEvent(chan, i - 1, BASSMIDIEvent.MIDI_EVENT_MIXLEVEL, Convert.ToInt32(Channels.GetValue(String.Format("ch{0}", i))));
                                }
                            }

                            System.Threading.Thread.Sleep(1);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
        }
コード例 #7
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            // get fft data. Return value is -1 on error
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048);

            if (ret < 0)
            {
                return;
            }

            OnAudioAvailable(_fft);
            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            _l = Utils.LowWord32(level);
            _r = Utils.HighWord32(level);
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output
            //so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr = 0;
                _l      = 0;
                _r      = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #8
0
        //timer
        private void OnTimerTick(object sender, EventArgs e)
        {
            // get fft data. Return value is -1 on error
            var ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048);

            if (ret < 0)
            {
                return;
            }

            OnAudioAvailable(_fft);
            _spectrumdata.Clear();


            var level = BassWasapi.BASS_WASAPI_GetLevel();

            leftChannelIntensity  = Utils.LowWord32(level);
            rightChannelIntensity = Utils.HighWord32(level);
            if (level == lastOutLevel && level != 0)
            {
                lastOutputLevelCounter++;
            }

            lastOutLevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output
            //so it doesn't make a gliched sound for long.

            if (lastOutputLevelCounter > 3)
            {
                lastOutputLevelCounter = 0;
                leftChannelIntensity   = 0;
                rightChannelIntensity  = 0;
            }
        }
コード例 #9
0
        public void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            /*  if(musicvisualize.IsChecked==true)
             * {
             * MMDevice defaultDevice = new MMDeviceEnumerator().GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
             * if(defaultDevice!=null)
             * {
             * //var device = (MMDevice)audio.SelectedItem;
             * zoebar.Value = (int)(Math.Round(defaultDevice.AudioMeterInformation.MasterPeakValue * 255));
             *    musicvalue = (int)(Math.Round(defaultDevice.AudioMeterInformation.MasterPeakValue * 255));
             *
             * }
             * }
             */

            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;


            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < 16; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (16 - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 250 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 10)
                {
                    y = 0;
                }
                spectrumdata[x] = (spectrumdata[x] * 6 + y * 2) / 8; //Smoothing out the value (take 5/8 of old value and 3/8 of new value to make finnal value)
                if (spectrumdata[x] > 255)
                {
                    spectrumdata[x] = 255;
                }

                //  Console.Write("{0, 3} ", y);
            }
            int i;

            //output_spectrumdata = spectrumdata;
            for (i = 0; i < 16; i++)
            {
                if (order_data[i] >= 0)
                {
                    output_spectrumdata[i] = Convert.ToByte(spectrumdata[order_data[i]]); // Re-Arrange the value to match the order of LEDs
                }
                zoebar1.Value  = spectrumdata[order_data[0]];
                zoebar2.Value  = spectrumdata[order_data[1]];
                zoebar3.Value  = spectrumdata[order_data[2]];
                zoebar4.Value  = spectrumdata[order_data[3]];
                zoebar5.Value  = spectrumdata[order_data[4]];
                zoebar6.Value  = spectrumdata[order_data[5]];
                zoebar7.Value  = spectrumdata[order_data[6]];
                zoebar8.Value  = spectrumdata[order_data[7]];
                zoebar9.Value  = spectrumdata[order_data[8]];
                zoebar10.Value = spectrumdata[order_data[9]];
                zoebar11.Value = spectrumdata[order_data[10]];
                zoebar12.Value = spectrumdata[order_data[11]];
                zoebar13.Value = spectrumdata[order_data[12]];
                zoebar14.Value = spectrumdata[order_data[13]];
                zoebar15.Value = spectrumdata[order_data[14]];
                zoebar16.Value = spectrumdata[order_data[15]];
            }



            //  Array.Clear(spectrumdata, 0, 16);

            int level = BassWasapi.BASS_WASAPI_GetLevel(); // Get level (VU metter) for Old AMBINO Device (remove in the future)

            volume = (byte)level;


            // _l.Value = Utils.LowWord32(level);
            //  _r.Value = Utils.HighWord32(level);
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.

            /* if (_hanctr > 300)
             * {
             *   _hanctr = 0;
             * //  _l.Value = 0;
             *  // _r.Value = 0;
             *   Free();
             *   Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
             * //  _initialized = false;
             * //  Enable = true;
             * }
             */
        }
        private void timerTick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048);

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //8 = Launchpad line count
            for (x = 0; x < 8; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (8 - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            //Software Visualization
            if (useSoftwareVis)
            {
                _vis.SetData(_spectrumdata);
            }

            //Launchpad Serialization here
            if (_lInt != null)
            {
                for (int i = 0; i < 8; i++)
                {
                    _val  = ((float)_spectrumdata[i] / 255) * 8;
                    _ledY = _val >= 8 ? 7 : _val;
                    int v = GetVelocityForVolume(_spectrumdata[i]);

                    for (int tX = 1; tX <= 8; tX++)
                    {
                        for (int tY = 1; tY <= 8; tY++)
                        {
                            int veloAtThisPoint = leds[tX - 1, tY - 1];
                            if (tX == i + 1 && tY == 8 - (int)_ledY)
                            {
                                _lInt.fillLEDs(tX, 8 - (int)_ledY, tX, 8, v);     //Write Color Track
                                if (8 - (int)_ledY != 8 && 8 - (int)_ledY != 1)   //Write it only if it is not 8th or 1st LED (which causes flickering)
                                {
                                    _lInt.fillLEDs(tX, 1, tX, 8 - (int)_ledY, 0); //Write zero track (inverse of color track)
                                }
                                leds[tX - 1, tY - 1] = v;
                            }
                        }
                    }
                }
            }

            _spectrumdata.Clear();

            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            if (_hanctr > 3)
            {
                _hanctr = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #11
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT8192);      //get ch.annel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < 64; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
                //Console.WriteLine("{0, 3} ", y);
            }



            if (DisplayEnable)
            {
                _spectrum.Set(_spectrumdata);
            }
            for (int i = 0; i < _spectrumdata.ToArray().Length; i++)
            {
                try
                {
                    _chart.Series["wave"].Points.Add(_spectrumdata[i]);
                }
                catch (Exception)
                {
                }
                try
                {
                    _chart.Series["wave"].Points.RemoveAt(0);
                }
                catch (Exception)
                {
                }
            }

            if (!port.IsOpen)
            {
                try
                {
                    int dataforduino = 0;
                    if (high_low == 1)
                    {
                        dataforduino = (_spectrumdata[0] + _spectrumdata[1] + _spectrumdata[2] + _spectrumdata[1]) * 2;
                    }
                    else if (high_low == 2)
                    {
                        dataforduino = (_spectrumdata[11] + _spectrumdata[11] + _spectrumdata[12] + _spectrumdata[12]) * 2;
                    }
                    else if (high_low == 3)
                    {
                        dataforduino = (_spectrumdata[30] + _spectrumdata[30] + _spectrumdata[32] + _spectrumdata[32]) * 2;
                    }
                    dataforduino = dataforduino / 4;

                    port.Open();

                    if (_red_btn.Checked == true)
                    {
                        port.Write(dataforduino + ",0,20,0\n");
                    }
                    else if (_green_btn.Checked == true)
                    {
                        port.Write("0," + dataforduino + ",20,0\n");
                    }
                    else if (_blue_btn.Checked == true)
                    {
                        port.Write("0,20," + dataforduino + ",0\n");
                    }
                    else if (_yellow_btn.Checked == true)
                    {
                        port.Write(dataforduino + "," + dataforduino + ",0,0\n");
                    }
                    else if (_cyan_btn.Checked == true)
                    {
                        port.Write("0," + dataforduino + "," + dataforduino + ",0\n");
                    }
                    else if (_magenta_btn.Checked == true)
                    {
                        port.Write(dataforduino + ",0," + dataforduino + ",0\n");
                    }
                    else if (_white_btn.Checked == true)
                    {
                        port.Write(dataforduino + "," + dataforduino + "," + dataforduino + ",0\n");
                    }
                    else if (_fade_btn.Checked == true)
                    {
                        decimal color_fade = dataforduino;
                        if (fade_durchlauf_ganz == 0)
                        {
                            fade_durchlauf++;
                            if (fade_durchlauf == 256)
                            {
                                fade_durchlauf      = 0;
                                fade_durchlauf_ganz = 1;
                            }
                            else
                            {
                                port.Write(Math.Round((color_fade / 255) * (255 - fade_durchlauf), 0) + "," + Math.Round((color_fade / 255) * fade_durchlauf, 0) + "," + "0" + ",0\n");
                            }
                        }
                        else if (fade_durchlauf_ganz == 1)
                        {
                            fade_durchlauf++;
                            if (fade_durchlauf == 256)
                            {
                                fade_durchlauf      = 0;
                                fade_durchlauf_ganz = 2;
                            }
                            else
                            {
                                port.Write("0" + "," + Math.Round((color_fade / 255) * (255 - fade_durchlauf), 0) + "," + Math.Round((color_fade / 255) * fade_durchlauf, 0) + ",0\n");
                            }
                        }
                        else if (fade_durchlauf_ganz == 2)
                        {
                            fade_durchlauf++;
                            if (fade_durchlauf == 256)
                            {
                                fade_durchlauf      = 0;
                                fade_durchlauf_ganz = 0;
                            }
                            else
                            {
                                port.Write(Math.Round((color_fade / 255) * fade_durchlauf, 0) + "," + "0" + "," + Math.Round((color_fade / 255) * (255 - fade_durchlauf), 0) + ",0\n");
                            }
                        }
                    }

                    port.Close();
                }
                catch
                {
                }
            }

            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            _l.Value = (Utils.LowWord32(level));
            _r.Value = (Utils.HighWord32(level));
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr  = 0;
                _l.Value = (0);
                _r.Value = (0);
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #12
0
ファイル: Analyser.cs プロジェクト: pmate955/SpectrumViewer
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            if (DisplayEnable)
            {
                _chart.Series[0].Points.Clear();
            }

            _sb.Clear();

            for (int i = 0; i < _spectrumdata.Count; i++)
            {
                if (!_realMode)
                {
                    if (_spectrumdata[i] > max[i])
                    {
                        max[i] = _spectrumdata[i];                                          //if the new level is greater than original, then set to max
                    }
                    else if (max[i] >= 12 && _spectrumdata[i] < max[i] - 5)
                    {
                        max[i] -= 12;                                                         //if greater than 12 and difference is bigger than 5, decrease by 12
                    }
                    else if (max[i] > 0)
                    {
                        max[i]--;                                                           //else decrease by one
                    }
                }
                else
                {
                    max[i] = _spectrumdata[i];
                }
                if (DisplayEnable)
                {
                    _chart.Series[0].Points.AddXY(i + 1, max[i]);
                    if (_variableColor == 5)                                    //Dynamic pink
                    {
                        _chart.Series[0].Points[i].Color = System.Drawing.Color.FromArgb(max[i], 0, 150);
                    }
                    else if (_variableColor == 6)                               //Default dynamic
                    {
                        if (max[i] < 65)
                        {
                            _chart.Series[0].Points[i].Color = System.Drawing.Color.Lime;
                        }
                        else if (max[i] < 130)
                        {
                            _chart.Series[0].Points[i].Color = System.Drawing.Color.Yellow;
                        }
                        else if (max[i] < 189)
                        {
                            _chart.Series[0].Points[i].Color = System.Drawing.Color.Orange;
                        }
                        else
                        {
                            _chart.Series[0].Points[i].Color = System.Drawing.Color.Red;
                        }
                    }
                    else if (_variableColor == 7)                               //Dynamic cyan
                    {
                        _chart.Series[0].Points[i].Color = System.Drawing.Color.FromArgb(0, max[i], 150);
                    }
                    else if (_variableColor == 8)                               //Dynamic Fire
                    {
                        //_chart.Series[0].Color = System.Drawing.Color.Red;
                        //_chart.Series[0].BackSecondaryColor = System.Drawing.Color.Yellow;
                        _chart.Series[0].Points[i].Color = System.Drawing.Color.FromArgb(max[i], 0, 0);
                        _chart.Series[0].Points[i].BackSecondaryColor = System.Drawing.Color.FromArgb(250, max[i], 31);;
                    }
                    else if (_variableColor == 9)                               //Dynamic sth
                    {
                        _chart.Series[0].Points[i].Color = System.Drawing.Color.FromArgb(max[i], 0, 140);
                        _chart.Series[0].Points[i].BackSecondaryColor = System.Drawing.Color.FromArgb(0, max[i], 255);
                    }
                }
                char c = 'a';
                byte b = max[i];
                if (b < 5)
                {
                    c = 'a';
                }
                else if (b < 17)
                {
                    c = 'b';
                }
                else if (b < 39)
                {
                    c = 'c';
                }
                else if (b < 51)
                {
                    c = 'd';
                }
                else if (b < 63)
                {
                    c = 'e';
                }
                else if (b < 75)
                {
                    c = 'f';
                }
                else if (b < 87)
                {
                    c = 'g';
                }
                else if (b < 99)
                {
                    c = 'h';
                }
                else if (b < 111)
                {
                    c = 'i';
                }
                else if (b < 123)
                {
                    c = 'j';
                }
                else if (b < 135)
                {
                    c = 'k';
                }
                else if (b < 147)
                {
                    c = 'l';
                }
                else if (b < 159)
                {
                    c = 'm';
                }
                else if (b < 171)
                {
                    c = 'n';
                }
                else if (b < 183)
                {
                    c = 'o';
                }
                else if (b < 195)
                {
                    c = 'q';
                }
                else if (b < 207)
                {
                    c = 'r';
                }
                else if (b < 219)
                {
                    c = 's';
                }
                else if (b < 231)
                {
                    c = 't';
                }
                else if (b < 243)
                {
                    c = 'u';
                }
                else
                {
                    c = 'v';
                }
                int num = c - 'a';
                _sb.Append(c);
            }

            //Console.WriteLine(output);
            if (Serial != null)
            {
                Serial.Write(_sb.ToString());                 //Serial.Write(output);
            }
            //Console.WriteLine();

            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.

            /*
             * if (_hanctr > 3)
             * {
             *  Console.WriteLine("error");
             *
             *  _hanctr = 0;
             *  _l.Value = 0;
             *  _r.Value = 0;
             *  Free();
             *  Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
             *  _initialized = false;
             *  Enable = true;
             * }
             */
        }
コード例 #13
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            var ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int line;
            var b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (line = 0; line < _lines; line++)
            {
                float peak = 0;
                var   b1   = (int)Math.Pow(2, line * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                var y = (int)(Math.Sqrt(peak) * 496);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }

                _spectrumdata.Add((byte)y);
            }

            // Pre-Process the spectrum data
            ProcessSpectrum(_spectrumdata, _oldSpectrumdata);

            if (NormalizeEnabled)
            {
                for (line = 0; line < _spectrumdata.Count; line++)
                {
                    if (_maxSpectrumValue[line] > _minSpectrumValue[line] + 20)
                    {
                        // ReSharper disable once UnusedVariable
                        var precentApart = Math.Abs(_maxSpectrumValue[line] - _minSpectrumValue[line]) / 255;
                        _maxSpectrumValue[line] -= NormalDecayVelocity;
                        //_minSpectrumValue[line] += NormalDecayVelocity;
                    }

                    if (_maxSpectrumValue[line] < _spectrumdata[line])
                    {
                        _maxSpectrumValue[line] = (byte)_spectrumdata[line];
                    }
                    //if (_minSpectrumValue[line] > _spectrumdata[line]) _minSpectrumValue[line] = (byte)_spectrumdata[line];

                    _spectrumdata[line] = (byte)ConvertRange(_minSpectrumValue[line], _maxSpectrumValue[line], 0, 255, _spectrumdata[line]);
                    //Console.WriteLine((byte)_minSpectrumValue[line]);
                }
            }

            //_mode.Display(_spectrumdata);

            _oldSpectrumdata.Clear();
            _oldSpectrumdata.AddRange(_spectrumdata.ToArray());

            // Post

            if (DisplayEnable)
            {
                _spectrum.Set(ByteSpectrumData);
            }
            Serial?.Write(ByteSpectrumData.ToArray(), 0, _spectrumdata.Count);

            _spectrumdata.Clear();


            var level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            if (SetModeFlag && Serial != null)
            {
                SetMode(Modes.ModeList[_mode]);
            }

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr <= 3)
            {
                return;
            }
            _hanctr = 0;
            Free();
            Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            _initialized = false;
            Enable       = true;
        }
コード例 #14
0
        //timer
        private void DisplayTimerTick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < SpectrumBarsCount; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (SpectrumBarsCount - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < fft[1 + b0])
                    {
                        peak = fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                spectrumdata.Add((byte)y);
            }

            SendValues(spectrumdata);
            spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == lastlevel && level != 0)
            {
                hanctr++;
            }
            lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (hanctr > 3)
            {
                hanctr = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                initialized = false;
                Enable      = true;
            }
        }
コード例 #15
0
        public List <byte> _getSpectrum()
        {
            _spectrumdata.Clear();

            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048);  //get channel fft data//default BASS_DATA_FFT2048

            if (ret < -1)
            {
                return(_spectrumdata);
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }
            _spectrum.Set(_spectrumdata);

            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr >= 3)
            {
                _hanctr = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }

            return(_spectrumdata);
        }
コード例 #16
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int         x, y;
            int         b0         = 0;
            List <byte> serialdata = new List <byte>();

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
                if (x == _sendline)
                {
                    serialdata.Add((byte)y);
                }
                //Console.Write("{0, 3} ", y);
            }

            if (DisplayEnable)
            {
                _spectrum.Set(_spectrumdata);
            }
            if (Serial != null)
            {
                Serial.Write(serialdata.ToArray(), 0, serialdata.Count);
                Console.WriteLine(ConvertStringArrayToStringJoin(serialdata.ToArray()));
            }
            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            _l.Value = Utils.LowWord32(level);
            _r.Value = Utils.HighWord32(level);
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr  = 0;
                _l.Value = 0;
                _r.Value = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #17
0
        // timer
        private void _t_Tick(object sender, EventArgs e)
        {
            // get fft data. Return value is -1 on error
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT4096);

            if (ret < 0)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            // computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            mainWindow.GetSpectrumData(_spectrumdata);
            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            // Required, because some programs hang the output. If the output hangs for a 75ms
            // this piece of code re initializes the output
            // so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #18
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;
            int hz = 255;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * hz - 4);
                if (y > hz)
                {
                    y = hz;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            _spectrum.Set(_spectrumdata);

            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            _l.Value = Utils.LowWord32(level);
            _r.Value = Utils.HighWord32(level);
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr      = 0;
                _l.Value     = 0;
                _r.Value     = 0;
                _initialized = false;
                Free();
                NewInit();
            }
        }
コード例 #19
0
        private void _t_Tick(object sender, EventArgs e)
        {
            // get fft data. Return value is -1 on error
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048);

            if (ret < 0)
            {
                return;
            }
            int    x;
            double y;
            int    b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (Math.Sqrt(peak));

                Channels[x].Value = y;
            }



            int level = BassWasapi.BASS_WASAPI_GetLevel();

            //_l.Value = Utils.LowWord32(level);
            //_r.Value = Utils.HighWord32(level);
            //if (level == _lastlevel && level != 0) _hanctr++;
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output
            //so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr = 0;
                //_l.Value = 0;
                //_r.Value = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                //Enable = true;
            }
        }
コード例 #20
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            var ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x;
            var b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < Lines; x++)
            {
                float peak = 0;
                var   b1   = (int)Math.Pow(2, x * 10.0 / (Lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                var y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            AnalyerDataReady?.Invoke(_spectrumdata);
            _spectrumdata.Clear();


            var level = BassWasapi.BASS_WASAPI_GetLevel();

            if ((level == _lastlevel) && (level != 0))
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr <= 3)
            {
                return;
            }

            _hanctr = 0;
            Free();
            Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            _initialized = false;
            Enable(_enabledButton, _enabledComboBox);
        }
コード例 #21
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT8192);  //get ch.annel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
                //Console.Write("{0, 3} ", y);
            }

            if (DisplayEnable)
            {
                _spectrum.Set(_spectrumdata);
            }
            for (int i = 0; i < _spectrumdata.ToArray().Length; i++)
            {
                try
                {
                    _chart.Series["wave"].Points.Add(_spectrumdata[i]);
                }
                catch (Exception)
                {
                }
                try
                {
                    _chart.Series["wave"].Points.RemoveAt(0);
                }
                catch (Exception)
                {
                }
            }
            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            _l.Value = (Utils.LowWord32(level));
            _r.Value = (Utils.HighWord32(level));
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr  = 0;
                _l.Value = (0);
                _r.Value = (0);
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #22
0
        private void tick(Object myObject, EventArgs myEventArgs)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < fft[1 + b0])
                    {
                        peak = fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }

                Color lastColor = lastColors[x];
                Color nowColor  = grd.GetColorAt(y / 255f);

                float a_smoothing = 1f - smoothing;

                byte  r         = (byte)(lastColor.R * smoothing + nowColor.R * a_smoothing);
                byte  g         = (byte)(lastColor.G * smoothing + nowColor.G * a_smoothing);
                byte  b         = (byte)(lastColor.B * smoothing + nowColor.B * a_smoothing);
                Color calcColor = Color.FromArgb(r, g, b);

                spectrumdata.Add(new Tuple <byte, Color>((byte)y, nowColor));
                lastColors[x] = calcColor;

                LedManager.setLed(x + 21, calcColor);
            }

            setValues(spectrumdata);
            spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == lastlevel && level != 0)
            {
                hanctr++;
            }
            lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (hanctr > 3)
            {
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, process, IntPtr.Zero);
                BassWasapi.BASS_WASAPI_Start();
            }
        }
コード例 #23
0
        private void _t_Tick(object sender, EventArgs e)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < _lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
            }

            if (DisplayEnable)
            {
                _spectrum.Set(_spectrumdata);
            }

            if (skip >= skipper)
            {
                if (activeAlgo != null && _rgbOutput != null && _rgbOutput.IsEnabled())
                {
                    activeAlgo.showRGB(_spectrumdata.ToArray(), (int)_mrs.RangeMin, (int)_mrs.RangeMax, minSliderValue, absNotRel, _rgbOutput);  // Now show Audio_RGB-Algorithm
                }
                skip = 0;
            }
            skip++;
            _spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            _l.Value = Utils.LowWord32(level);
            _r.Value = Utils.HighWord32(level);
            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr  = 0;
                _l.Value = 0;
                _r.Value = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #24
0
        /// <summary>
        /// Метод получения данных с устройсва.
        /// </summary>
        /// <param name="_object"></param>
        /// <param name="_elapsedEventArgs"></param>
        private void Getter(Object _object, EventArgs _elapsedEventArgs)
        {
            Int32 Ret = BassWasapi.BASS_WASAPI_GetData(_ftt, (int)BASSData.BASS_DATA_FFT8192); // Получение данных ch.annel fft

            if (Ret < -1)
            {
                return;
            }
            Int32 X, Y;
            Int32 B0 = 0;

            // Вычисление данных спектра (код берется из образца bass_wasapi).
            for (X = 0; X < Count; X++)
            {
                float Peak = 0;
                Int32 B1   = (int)Math.Pow(2, X * 10.0 / (Count - 1));
                if (B1 > 1023)
                {
                    B1 = 1023;
                }
                if (B1 <= B0)
                {
                    B1 = B0 + 1;
                }
                for (; B0 < B1; B0++)
                {
                    if (Peak < _ftt[1 + B0])
                    {
                        Peak = _ftt[1 + B0];
                    }
                }
                Y = (int)(Math.Sqrt(Peak) * 3 * 255 - 4);
                if (Y > 255)
                {
                    Y = 255;
                }
                if (Y < 0)
                {
                    Y = 0;
                }
                _spectrumData.Add((byte)Y);
            }

            Leveling?.Invoke(this, new SpectrumAnalyzerEventArgs(_spectrumData));
            _spectrumData.Clear();

            Int32 level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == _lastLevel && level != 0)
            {
                _hanctr++;
            }
            _lastLevel = level;

            if (_hanctr > 3)
            {
                _hanctr = 0;
                this.Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
            }
        }
コード例 #25
0
        //timer
        private void _t_Tick(object sender, EventArgs e)
        {
            if (!Enable)
            {
                return;
            }
            int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }



            int level = BassWasapi.BASS_WASAPI_GetLevel();


            _l.Value = Utils.LowWord32(level);
            _r.Value = Utils.HighWord32(level);



            var left  = (float)Utils.LowWord32(level) / 32768;;
            var right = (float)Utils.HighWord32(level) / 32768;

            powerHistory.AddFirst(new Tuple <float, DateTime>(left, DateTime.Now));
            if ((powerHistory.First().Item2 - powerHistory.Last().Item2).TotalMilliseconds > 8 && powerHistory.Count > 200)
            {
                powerHistory.RemoveLast();
            }


            if (this.Visuualizer == "ChaseOut")
            {
                Chase(true);
            }
            else if (this.Visuualizer == "ChaseIn")
            {
                Chase(false);
            }
            else if (this.Visuualizer == "ColorSlider")
            {
                ColorSlider();
            }
            else if (this.Visuualizer == "SmallGains")
            {
                SmallGains();
            }
            else if (this.Visuualizer == "RainbowGains")
            {
                RainbowGains();
            }
            else if (this.Visuualizer == "StopLight")
            {
                StopLight();
            }
            else
            {
                AnimateCenterRightLeft();
            }


            if (level == _lastlevel && level != 0)
            {
                _hanctr++;
            }
            _lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (_hanctr > 3)
            {
                _hanctr  = 0;
                _l.Value = 0;
                _r.Value = 0;
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                _initialized = false;
                Enable       = true;
            }
        }
コード例 #26
0
        void ChasOld()
        {
            int x, y;
            int b0          = 0;
            int chanelCount = 3;

            int level = BassWasapi.BASS_WASAPI_GetLevel();



            var left = (float)Utils.LowWord32(level) / 32768;;



            //  BassWasapi.BASS_WASAPI_GetLevel()
            _spectrumdata.Clear();
            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < chanelCount; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (chanelCount - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
                //Console.Write("{0, 3} ", y);
            }

            if (DisplayEnable)
            {
                _spectrum.Set(_spectrumdata);
            }



            if (client != null)
            {
                //   var precentile = GetPrecentile(powerHistory, left);
                //   System.Diagnostics.Debug.WriteLine(precentile);
                //      var poweer256 =  Convert.ToInt32( GetPrecentile(powerHistory, left)  * 255);

                //var red = _spectrumdata[1] - _spectrumdata[1] % 3;
                //var green = _spectrumdata[0] - _spectrumdata[0] % 3;
                //var blue =  _spectrumdata[2] - _spectrumdata[2] % 3;
                // var red = (byte)((int)Convert.ToInt32(Math.Pow(GetPrecentile(powerHistory, left), 2) * 255));
                //   var newColor = rgb2Int(red, green, blue);
                var newColor = rgb2Intx(_spectrumdata[1], _spectrumdata[0], _spectrumdata[2]);
                int middele  = _ledArray.Length / 2;

                var nextcolor = newColor;
                for (var i = middele - 1; i >= 0; i--)
                {
                    var lastColor = _ledArray[i];
                    _ledArray[i] = nextcolor;
                    nextcolor    = lastColor;
                }
                nextcolor = newColor;
                for (var i = middele; i < _ledArray.Length; i++)
                {
                    var lastColor = _ledArray[i];
                    _ledArray[i] = nextcolor;
                    nextcolor    = lastColor;
                }
                Render();
            }
        }
コード例 #27
0
        void AnimateCenterRightLeft()
        {
            int x, y;
            int b0          = 0;
            int chanelCount = 1;

            _spectrumdata.Clear();
            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < chanelCount; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (chanelCount - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < _fft[1 + b0])
                    {
                        peak = _fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }
                _spectrumdata.Add((byte)y);
                //Console.Write("{0, 3} ", y);
            }

            if (DisplayEnable)
            {
                _spectrum.Set(_spectrumdata);
            }
            //if (Serial != null)
            //{
            //    Serial.Write(_spectrumdata.ToArray(), 0, _spectrumdata.Count);
            //}


            int level = BassWasapi.BASS_WASAPI_GetLevel();


            var left  = (float)Utils.LowWord32(level) / 32768;;
            var right = (float)Utils.HighWord32(level) / 32768;

            if ((DateTime.Now - lastBeat).TotalSeconds > 1)
            {
                if (left > Percentile(powerHistory.Select(_ => _.Item1), .8f))
                {
                    lastBeat   = DateTime.Now;
                    lastindex += 125;
                    System.Diagnostics.Debug.WriteLine("beat " + DateTime.Now.Second + " " + DateTime.Now.Millisecond);
                }
            }

            if (client != null)
            {
                Array.Clear(_ledArray, 0, _ledArray.Length);

                lastindex += colorStep;
                if (lastindex > 256)
                {
                    lastindex = lastindex % 256;
                }



                for (int i = 0; i < _ledArray.Length; i++)
                {
                    _ledArray[i] = colorwheel((lastindex + i * colorStep) % 256);
                }
                var specLength = (_leftIdx - _rightIdx) / chanelCount;


                var rem = (_leftIdx - _rightIdx) % 3 + specLength % 2;
                specLength = specLength / 2;

                //Newtonsoft.Json.Linq.JArray arr = new Newtonsoft.Json.Linq.JArray();
                for (int i = 0; i < chanelCount; i++)
                {
                    var colorStart = (int)(i * ((float)256 / (float)chanelCount));
                    for (int j = 0; j < specLength; j++)
                    {
                        var powerLevel   = (float)_spectrumdata[i] / (float)255;
                        var percentLevel = (float)(j + 1) / (float)specLength;
                        // var color = 0;
                        var on = powerLevel > percentLevel;


                        var idxa = _rightIdx + i * (specLength * 2) + specLength - (j + 1);
                        var idxb = _rightIdx + i * (specLength * 2) + specLength + j;
                        _ledArray[idxa] = on ? _ledArray[idxa] : 0;
                        _ledArray[idxb] = on ? _ledArray[idxb] : 0;
                    }
                }
                //  var percentLoud = 1.1*  (float)Utils.LowWord32(level)/ (float)65553;
                for (int i = 0; i < _rightIdx; i++)
                {
                    var percentIdx = (float)(i + 1) / (float)_rightIdx;
                    var lon        = (1.1 * Math.Pow(left, .4)) > percentIdx;
                    var ron        = (1.1 * Math.Pow(right, .4)) > percentIdx;
                    _ledArray[i] = ron ? _ledArray[0] : 0;
                    _ledArray[_ledArray.Length - i - 1] = lon ? _ledArray[0] : 0;
                }


                Render();
            }
        }
コード例 #28
0
        public float[] GetSpectrum(int lines, ref int R, ref int L)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(fftBuffer, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            //if the Data was successfully retrieved
            if (ret != -1)
            {
                int x, y;
                int b0 = 0;

                //computes the spectrum data, the code is taken from a bass_wasapi sample.
                for (x = 0; x < lines; x++)
                {
                    float peak = 0;
                    int   b1   = (int)Math.Pow(2, x * 10.0 / (lines - 1));
                    if (b1 > 1023)
                    {
                        b1 = 1023;
                    }
                    if (b1 <= b0)
                    {
                        b1 = b0 + 1;
                    }
                    for (; b0 < b1; b0++)
                    {
                        if (peak < fftBuffer[1 + b0])
                        {
                            peak = fftBuffer[1 + b0];
                        }
                    }
                    y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                    if (y > 255)
                    {
                        y = 255;
                    }
                    if (y < 0)
                    {
                        y = 0;
                    }
                    SpectrumData[x] = y;
                    currentIndex    = x;
                    currentValue    = y;
                    OnUpdated(EventArgs.Empty);
                }

                //right left volume
                int level = BassWasapi.BASS_WASAPI_GetLevel();
                left  = Utils.LowWord32(level);
                right = Utils.HighWord32(level);
                R     = (int)right;
                L     = (int)left;

                //Required, because some programs hang the output. If the output hangs for a 75ms
                //this piece of code re initializes the output so it doesn't make a gliched sound for long.
                if (level == lastLevel && level != 0)
                {
                    hanCtr++;
                }

                lastLevel = level;


                if (hanCtr > 3)
                {
                    hanCtr = 0;
                    left   = 0;
                    right  = 0;
                    Free();
                    Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                    initialized = false;
                    Enable      = true;
                }
            }
            else
            {
                //other wise the fail is market in the SpectrumData, at the first position
                SpectrumData[0] = -1;
                currentIndex    = 0;
                currentValue    = -1;
                OnUpdated(EventArgs.Empty);
            }

            return(SpectrumData);
        }