Exemplo n.º 1
0
        public IActionResult SingQuestion()
        {
            int          Id     = int.Parse(this.RouteData.Values["id"].ToString());
            int?         userId = HttpContext.Session.GetInt32("UserId");
            var          user   = _dbContext.Users.First(a => a.Id == userId);
            PropertyInfo info   = user.GetType().GetProperty($"Answer{Id}");


            var          waveResampler    = new Resampler(null);
            Sound        freqencyDetector = new Sound();
            List <float> result           = freqencyDetector.DetectFrequency(waveResampler);
            float        mainFrequency    = FrequencyFilter.CalculateMainFreq(result);

            if (Id == 19)
            {
                FrequencyClassificator FreqClass = new FrequencyClassificator(330);
                UserAnswers.AddAnswer(FreqClass.Validate(mainFrequency));
                info.SetValue(user, FreqClass.Validate(mainFrequency));
                _dbContext.SaveChanges();
                return(RedirectToAction("Question", new { Id = Id + 1 }));
            }
            else if (Id == 20)
            {
                FrequencyClassificator FreqClass = new FrequencyClassificator(440);
                UserAnswers.AddAnswer(FreqClass.Validate(mainFrequency));
                info.SetValue(user, FreqClass.Validate(mainFrequency));
                _dbContext.SaveChanges();
                return(RedirectToAction("YourResult"));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public bool ProcessRecording(byte[] audioArray, int baseFreq)
        {
            var                    waveResampler    = new Resampler(audioArray);
            Sound                  freqencyDetector = new Sound();
            List <float>           result           = freqencyDetector.DetectFrequency(waveResampler);
            float                  mainFrequency    = FrequencyFilter.CalculateMainFreq(result);
            FrequencyClassificator FreqClass        = new FrequencyClassificator(baseFreq);
            bool                   answer           = FreqClass.Validate(mainFrequency);

            return(answer);
        }