public float[] GetRawSpectrData(string filename, FFTSize size, float fps, int maxwidth, int startscan = 0) { float[] Spectr; GetFFTData(filename, size, fps, maxwidth, startscan); Spectr = DoScanSpectr(ref Data); return(Spectr); }
//most of this code is stolen from the example in the CSCore github so idk what it does 40% of the time public void Initialize(FFTSize _size = FFTSize._4096) { size = _size; _soundIn = new WasapiLoopbackCapture(); _soundIn.Initialize(); var soundInSource = new SoundInSource(_soundIn); var source = soundInSource.ToSampleSource(); _fft = new FftProvider(source.WaveFormat.Channels, (FftSize)size); var n = new SingleBlockNotificationStream(source); n.SingleBlockRead += (s, a) => _fft.Add(a.Left, a.Right); _source = n.ToWaveSource(16); byte[] buffer = new byte[_source.WaveFormat.BytesPerSecond]; soundInSource.DataAvailable += (s, aEvent) => { int read; while ((read = _source.Read(buffer, 0, buffer.Length)) > 0) { ; } }; _soundIn.Start(); }
public SpectrumVisualizer() { InitializeComponent(); FFTSize = 2048; string[] windowingTypes = Enum.GetNames(typeof(FFTTransformer.eWindowingFunction)); cmbWindowFunc.Items.AddRange(windowingTypes); cmbWindowFunc.Text = FFTDisplay.WindowingFunction.ToString(); cmbAverage.Text = FFTDisplay.VerticalSmooth.ToString(); cmbFFTSize.Text = FFTSize.ToString(); }
public Bitmap GetBitmapSpectrum(string filename, FFTSize size, float fps, int maxwidth, int startscan = 0) { Bitmap Image; //glfrm = new GLForm(); //glfrm.Width = 1024; //glfrm.Height = 518; //glfrm.Show(); GetFFTData(filename, size, fps, maxwidth); int heigth = (int)size; int width = (int)Data.Count; if (width == 0) { Image = new Bitmap(1, 1); return(Image); } Image = new Bitmap(width, heigth); float min = 9999; float max = -9999; for (int x = 0; x < width; x++) { for (int y = 0; y < heigth; y++) { if (Data[x][y] > max) { max = Data[x][y]; } else { if (Data[x][y] < min) { min = Data[x][y]; } } } } float amin = Math.Abs(min); float kor = 1 / (max + amin); for (int x = 0; x < width; x++) { for (int y = 0; y < heigth; y++) { Data[x][y] = Data[x][y] + amin; Data[x][y] = Data[x][y] * kor * 16 * 50; Data[x][y] = Data[x][y] * Data[x][y]; } } double dd, dd2, d, dd3, d2; byte d1, d3, d4, d5; Color c; for (int x = 0; x < width; x++) { dd = 0; dd2 = 0; for (int y = 0; y < heigth; y++) { d = Math.Ceiling(Data[x][y]); dd3 = 0; if (d > 255) { d = 255; } if (d < 0) { d = 0; } dd = dd * 100 + d; dd = dd / 101; dd2 = dd2 * 10 + d; dd2 = dd2 / 11; d1 = (byte)d; d2 = Math.Ceiling(dd2); d3 = (byte)d2; d4 = (byte)Math.Ceiling(dd); dd3 = d4 + d3 + d1; dd3 = dd3 / 3; d5 = (byte)Math.Ceiling(dd3); c = Color.FromArgb(255, d3, d4, d5); Image.SetPixel(x, y, c); } } //glfrm.BackgroundImage = Image; //glfrm.BackgroundImageLayout = ImageLayout.Zoom; //glfrm.Invalidate(); //Application.DoEvents(); //glfrm.Show (); //Thread.Sleep(3000); //glfrm.Close(); return(Image); }
public List <float[]> GetFFTData(string filename, FFTSize size, float fps, int maxwidth, int startscan = 0) { Un4seen.Bass.BASSData FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT256; int arlen = 0; if (size == FFTSize.FFT128) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT256; } if (size == FFTSize.FFT256) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT512; } if (size == FFTSize.FFT512) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT1024; } if (size == FFTSize.FFT1024) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT2048; } if (size == FFTSize.FFT2048) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT4096; } if (size == FFTSize.FFT4096) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT8192; } if (size == FFTSize.FFT8192) { FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT16384; } arlen = (int)size; int len = (int)FFTType; GC.Collect(); time = 0; Data.Clear(); Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero); // create the stream int chan = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0); var pos = Bass.BASS_ChannelGetLength(chan); var p = Bass.BASS_ChannelBytes2Seconds(chan, pos); //Console.Write("ScanFile"); //Console.Clear(); long byte_pos = 0; int n = 0; while (byte_pos < pos) { n++; if (Data.Count > maxwidth) { break; } else if (n > startscan) { byte_pos = Bass.BASS_ChannelSeconds2Bytes(chan, time); //double d = (double)n / (double)maxwidth; //d = d * 100; //d = Math.Ceiling(d); //if (d % 10 == 0) //{ // Console.SetCursorPosition(0, 0); // Console.Write(filename); // Console.SetCursorPosition(0, 1); // Console.Write(d.ToString() + "%"); //} Bass.BASS_ChannelSetPosition(chan, byte_pos, BASSMode.BASS_POS_BYTES); float[] fft = new float[arlen]; Bass.BASS_ChannelGetData(chan, fft, len); Data.Add(fft); } time += 1F / fps; } Bass.BASS_ChannelPause(chan); Bass.BASS_Stop(); Bass.BASS_StreamFree(chan); GC.Collect(); return(Data); }
public float[] GetRawSpectrData(string filename,FFTSize size,float fps,int maxwidth,int startscan=0) { float[] Spectr; GetFFTData(filename, size, fps, maxwidth, startscan); Spectr = DoScanSpectr(ref Data); return Spectr; }
public List<float[]> GetFFTData(string filename, FFTSize size, float fps, int maxwidth, int startscan=0) { Un4seen.Bass.BASSData FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT256; int arlen = 0; if (size == FFTSize.FFT128) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT256; if (size == FFTSize.FFT256) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT512; if (size == FFTSize.FFT512) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT1024; if (size == FFTSize.FFT1024) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT2048; if (size == FFTSize.FFT2048) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT4096; if (size == FFTSize.FFT4096) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT8192; if (size == FFTSize.FFT8192) FFTType = Un4seen.Bass.BASSData.BASS_DATA_FFT16384; arlen=(int)size; int len = (int)FFTType; GC.Collect(); time = 0; Data.Clear(); Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero); // create the stream int chan = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0); var pos = Bass.BASS_ChannelGetLength(chan); var p = Bass.BASS_ChannelBytes2Seconds (chan, pos); //Console.Write("ScanFile"); //Console.Clear(); long byte_pos=0; int n = 0; while (byte_pos<pos) { n++; if (Data.Count > maxwidth) { break; } else if(n>startscan) { byte_pos = Bass.BASS_ChannelSeconds2Bytes(chan, time); //double d = (double)n / (double)maxwidth; //d = d * 100; //d = Math.Ceiling(d); //if (d % 10 == 0) //{ // Console.SetCursorPosition(0, 0); // Console.Write(filename); // Console.SetCursorPosition(0, 1); // Console.Write(d.ToString() + "%"); //} Bass.BASS_ChannelSetPosition(chan, byte_pos, BASSMode.BASS_POS_BYTES); float[] fft = new float[arlen]; Bass.BASS_ChannelGetData(chan, fft, len); Data.Add(fft); } time += 1F / fps; } Bass.BASS_ChannelPause(chan); Bass.BASS_Stop(); Bass.BASS_StreamFree(chan); GC.Collect(); return Data; }
public Bitmap GetBitmapSpectrum(string filename, FFTSize size, float fps,int maxwidth, int startscan=0) { Bitmap Image; //glfrm = new GLForm(); //glfrm.Width = 1024; //glfrm.Height = 518; //glfrm.Show(); GetFFTData(filename, size, fps, maxwidth); int heigth = (int)size; int width = (int)Data.Count ; if (width==0) { Image = new Bitmap(1, 1); return Image; } Image = new Bitmap(width, heigth); float min = 9999; float max = -9999; for (int x = 0; x < width; x++) { for (int y = 0; y < heigth; y++) { if (Data[x][y]>max) { max = Data[x][y]; } else { if (Data[x][y]<min) { min = Data[x][y]; } } } } float amin = Math.Abs(min); float kor = 1 / (max + amin); for (int x = 0; x < width; x++) { for (int y = 0; y < heigth; y++) { Data[x][y] = Data[x][y] + amin; Data[x][y] = Data[x][y] * kor * 16*50; Data[x][y] = Data[x][y] * Data[x][y]; } } double dd, dd2,d,dd3,d2; byte d1, d3, d4,d5; Color c; for (int x = 0; x < width; x++) { dd = 0; dd2 = 0; for (int y = 0; y < heigth; y++) { d = Math.Ceiling(Data[x][y]); dd3 = 0; if (d>255) { d = 255; } if (d < 0) { d = 0; } dd = dd * 100 + d; dd = dd / 101; dd2 = dd2 * 10 + d; dd2 = dd2 / 11; d1=(byte)d; d2 = Math.Ceiling(dd2); d3= (byte)d2; d4 = (byte)Math.Ceiling(dd) ; dd3 = d4 + d3 + d1; dd3 = dd3 / 3; d5 = (byte)Math.Ceiling(dd3); c = Color.FromArgb(255, d3,d4, d5); Image.SetPixel(x, y, c); } } //glfrm.BackgroundImage = Image; //glfrm.BackgroundImageLayout = ImageLayout.Zoom; //glfrm.Invalidate(); //Application.DoEvents(); //glfrm.Show (); //Thread.Sleep(3000); //glfrm.Close(); return Image; }