示例#1
0
        private static void Main(string[] args)
        {
            /*var files = new List<string>();
             * var data = new List<(List<double>, string)>();
             * var percent = 0.0;
             * Console.WriteLine($"Percent: {percent * 100}%");
             * foreach (var genre in Genres)
             * {
             *  for (var i = 0; i < 5; i++)
             *  {
             *      var file = $@"C:\Users\Ale\Licenta-master\Licenta-master\PopulateDatabase\music\genres\{genre}\{genre}.0000{i}.wav";
             *      var sound = SoundReader.ReadFromFile(file);
             *      var fftResult = Fft.CalculateFft(sound, keepAll: true);
             *      foreach (var res in fftResult.Result)
             *          data.Add((res.Points.Select(x => (double)x).ToList(), genre));
             *      percent += 1.0 / 50;
             *      Console.Clear();
             *
             *      Console.WriteLine($"Percent: {percent * 100}%");
             *  }
             * }*/

            var ann = new RNA(null, AnnMode.Training, ActivationFunctions.Tahn);
            var net = Utils.ReadFromBinaryFile <List <List <Neuron> > >("net");

            //var net = ann.NetInit(10, 9);
            //ann.Training(ref net, 10, 0.001, 1000);

            var sound2 = SoundReader.ReadFromFile(
                @"C:\Users\Ale\Licenta-master\Licenta-master\PopulateDatabase\music\genres\disco\disco.00001.wav");

            var result2 = Fft.CalculateFft(sound2, keepAll: true);


            //var realOutputs = ann.TestData.Select(x => x.Item2).ToList();
            ann.TestData = result2.Result.Select(x => (x.HighScores, "disco")).ToList();
            ann.TestData.Shuffle();

            var computedOutputs = ann.Evaluate(ref net, 10);

            var genres = ann.GetGeneres();

            foreach (var result in computedOutputs)
            {
                genres[ann.GetValueFromLabelVector(result)] += 1;
            }

            var s = genres.ToDictionary(x => x.Key, x => x.Value * 100.0 / computedOutputs.Count);

            //Console.Write(ann.ComputePerformance(computedOutputs, realOutputs));


            Utils.WriteToBinaryFile("net", net);

            Console.ReadKey();
        }
示例#2
0
        public void TestWav()
        {
            var musicPath = Path.GetFullPath(
                Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\bells.wav"));
            var wavSound = (WavSound)SoundReader.ReadFromFile(musicPath);

            Assert.IsNotNull(wavSound);
            Assert.AreEqual(16, wavSound.BitDepth);
            Assert.AreEqual(2, wavSound.NumChannels);
            Assert.AreEqual((uint)44100, wavSound.SampleRate);
            Assert.AreEqual(1222414, wavSound.Data.Count);
        }
示例#3
0
        private static void AddSongToDb(string musicPath, MusicItem musicItem)
        {
            using var unitOfWork = new UnitOfWork();
            var songRepo      = unitOfWork.GetRepository <Song>();
            var songPartsRepo = unitOfWork.GetRepository <SongPart>();

            var sound = SoundReader.ReadFromFile(Path.Combine(musicPath, musicItem.File));

            var newSong = new Song
            {
                Name           = musicItem.Name,
                ApparitionDate = musicItem.ApparitionDate,
                Artist         = musicItem.Artist,
                BeatPortLink   = musicItem.BeatportLink,
                SpotifyLink    = musicItem.SpotifyLink,
                YoutubeLink    = musicItem.YoutubeLink,
                Genre          = musicItem.Genre,
                Picture        = musicItem.PictureFile == "" ? null :
                                 File.ReadAllBytes(Path.Combine(musicPath, musicItem.PictureFile)).ToArray(),
                Duration = sound.Duration
            };

            songRepo.Add(newSong);

            var resultFft = Fft.CalculateFft(sound);

            resultFft.Result.ForEach(x => songPartsRepo.Add(new SongPart
            {
                SongId     = newSong.Id,
                Hashtag    = x.Hash.ToString(),
                Time       = x.Time,
                Duration   = x.Duration,
                HighScores = x.HighScores,
                Points     = x.Points
            })
                                     );
            unitOfWork.Save();
            unitOfWork.Dispose();
        }