コード例 #1
0
ファイル: AudioStream.cs プロジェクト: iainconnor/glimmr
        private void LogColor(float amplitude, string separator = "")
        {
            var hue   = HueFromAmplitude(amplitude);
            var value = amplitude > 0 ? 1 : 0;

            Console.ForegroundColor = ColorFromSystem(ColorUtil.ColorFromHsv(hue, 1, value));
            Console.Write($@"{amplitude:F2}{separator}");
        }
コード例 #2
0
ファイル: AudioStream.cs プロジェクト: iainconnor/glimmr
        private bool Procedure(int handle, IntPtr buffer, int length, IntPtr user)
        {
            if (_token.IsCancellationRequested)
            {
                LogUtil.Write("We dun canceled our token.");
                Bass.Free();
                return(false);
            }

            var samples   = 256;
            var fft       = new float[samples]; // fft data buffer
            var fftStereo = new float[3];       // fft data buffer
            // Get our FFT for "everything"
            var channelGetData = Bass.ChannelGetData(handle, fft, (int)DataFlags.FFT256);
            //LogUtil.Write($"FFT {channelGetData}: " + JsonConvert.SerializeObject(fft));
            var cData = new Dictionary <int, float>();

            for (var a = 0; a < samples; a++)
            {
                var val = fft[a];
                if (val > 0.01)
                {
                    var amp  = val * 100;
                    var freq = FftIndex2Frequency(a, samples, _frequency);
                    if (amp > _max)
                    {
                        _max = amp;
                    }
                    cData[freq] = amp;
                }
            }

            // Now get them for the stereo left/right
            channelGetData = Bass.ChannelGetData(handle, fftStereo, (int)DataFlags.FFTIndividual);
            var amps = SortChannels(cData, fftStereo);

            for (var q = 0; q < amps.Length; q++)
            {
                var amp   = amps[q];
                var value = amp > 0 ? 1 : 0;
                _colors[q] = ColorUtil.ColorFromHsv(HueFromAmplitude(amp), 1, value);
            }

            return(true);
        }