예제 #1
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            pbLevelMask.Height = (int)(panelLevel.Height * (1 - lastAmplitudeFrac));
            if (lastAmplitudeFrac < .9)
            {
                panelLevel.BackColor = Color.Green;
            }
            else
            {
                panelLevel.BackColor = Color.Red;
            }

            if ((spec == null) || (spec.fftList.Count == 0))
            {
                return;
            }

            if (!spec.displaySettings.renderNeeded)
            {
                return;
            }

            if (!busyRendering)
            {
                busyRendering = true;
                spec.displaySettings.renderNeeded = false;
                pbSpec.BackgroundImage            = spec.GetBitmap(
                    intensity: spec.displaySettings.brightness,
                    freqLow: spec.displaySettings.freqLow,
                    freqHigh: spec.displaySettings.freqHigh
                    );
                pbSpec.Size   = pbSpec.BackgroundImage.Size;
                busyRendering = false;
            }
        }
예제 #2
0
        public SuccessViewModel CalculateSuccess(SongViewModel song)
        {
            try
            {
                SongBE entity;
                entity = Mapper.Map <SongViewModel, SongBE>(song);
                SongDAL          songDAL          = new SongDAL();
                SuccessViewModel successViewModel = new SuccessViewModel();


                var listSongs = songDAL.GetSongsToCalculate(entity.Category);


                (int sampleRate, double[] audio) = WavFile.ReadMono(FileUtils.GetRepoMusicPath(song.SongKey));


                var spec = new Spectrogram.Spectrogram(sampleRate / 2, fftSize: (16384 / 8), stepSize: (2500 * 5), maxFreq: 2200);
                spec.Add(audio);
                var tempPath = Path.GetTempPath();
                spec.SaveImage(tempPath + "/" + song.SongKey + ".jpg", intensity: 5, dB: true);

                var file = FileUtils.GetImageBytes(tempPath + "/" + song.SongKey + ".jpg");
                successViewModel.ImageBase64 = "data:image/jpg;base64," + Convert.ToBase64String(file);

                var bmHash = this.GetHash(spec.GetBitmap());



                List <Spectrogram.Spectrogram> spectrograms = new List <Spectrogram.Spectrogram>();

                foreach (var son in listSongs)
                {
                    (int sampleRateSong, double[] audioSong) = WavFile.ReadMono(FileUtils.GetRepoMusicPath(son.SongKey));
                    var specSong = new Spectrogram.Spectrogram(sampleRateSong / 2, fftSize: (16384 / 8), stepSize: (2500 * 5), maxFreq: 2200);
                    specSong.Add(audioSong);
                    spectrograms.Add(specSong);
                }

                int equalElements = 0;

                foreach (var sp in spectrograms)
                {
                    equalElements += bmHash.Zip(this.GetHash(sp.GetBitmap()), (i, j) => i == j).Count(eq => eq);
                }

                var con = Convert.ToInt32(equalElements / spectrograms.Count);
                successViewModel.Percentage = Convert.ToInt32((con * 100) / bmHash.Count);
                return(successViewModel);
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }
예제 #3
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            double[] newAudio = listener.GetNewAudio();
            spec.Add(newAudio, process: false);

            double multiplier = Brightness / 20.0;

            if (spec.FftsToProcess > 0)
            {
                Stopwatch sw = Stopwatch.StartNew();
                spec.Process();
                //if (SpectrogamImageSource != null)
                spec.SetFixedWidth(1024);// (int)SpectrogamImageSource.Width);

                Bitmap bmpSpec = new Bitmap(spec.Width, spec.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                using (var bmpSpecIndexed = spec.GetBitmap(multiplier, Decibels, Roll))
                    using (var gfx = Graphics.FromImage(bmpSpec))
                        using (var pen = new System.Drawing.Pen(System.Drawing.Color.White))
                        {
                            gfx.DrawImage(bmpSpecIndexed, 0, 0);
                            if (Roll)
                            {
                                gfx.DrawLine(pen, spec.NextColumnIndex, 0, spec.NextColumnIndex, SpectrogramHeight);
                            }
                        }
                sw.Stop();

                //SpectrogamImageSource.Dispose();
                SpectrogamImageSource    = ImageHelpers.BitmapToImageSource(bmpSpec);
                VerticalScaleImageSource = ImageHelpers.BitmapToImageSource(spec.GetVerticalScale(75));

                RenderTime = $"Render time: {sw.ElapsedMilliseconds:D2} ms";
                Peak       = $"Peak (Hz): {spec.GetPeak().freqHz:N0}";
            }

            TotalTime     = $"Time: {listener.TotalTimeSec:N3} sec";
            FftsProcessed = $"FFTs processed: {spec.FftsProcessed:N0}";

            //Default max on the progressbar is 100 so hardcoding it here for now
            Amplitude = (int)(listener.AmplitudeFrac * 100);

            SpectrogramHeight = spec.Height;

            VerticalScaleImageSource = null;
            VerticalScaleImageSource = ImageHelpers.BitmapToImageSource(spec.GetVerticalScale(LEGEND_WIDTH));
        }