public float GetPitch() { if (RandomizePitch == true) { return(AudioFunctions.St2pitch(Pitch + GetRandomValueOffset(RandomPitch))); } else { return(AudioFunctions.St2pitch(Pitch)); } }
public float GetVol() { if (RandomizeVolume == true) { return(AudioFunctions.DbToLinear(Volume + GetRandomValueOffset(RandomVolume))); } else { return(AudioFunctions.DbToLinear(Volume)); } }
public float getVolume() { return(AudioFunctions.DbToLinear(volume)); }
public HomeViewModel() { GenreList = new ObservableRangeCollection <Genre>(); PredictedLabel = "Genre"; var entries = new[] { new ChartEntry(212) { Label = "What will it be?", ValueLabel = "212", Color = SKColor.Parse("#2c3e50") } }; CurrentChart = new DonutChart() { Entries = entries, IsAnimated = true, AnimationDuration = TimeSpan.FromSeconds(5) }; AggChart = new DonutChart() { Entries = entries, IsAnimated = true, AnimationDuration = TimeSpan.FromSeconds(5) }; recorder = new AudioRecorderService { StopRecordingOnSilence = false, //will stop recording after 2 seconds (default) StopRecordingAfterTimeout = true, //stop recording after a max timeout (defined below) TotalAudioTimeout = TimeSpan.FromSeconds(30) //audio will stop recording after 15 seconds }; //player = new AudioPlayer(); playCommand = new Command(() => { var files = Assembly.GetExecutingAssembly().GetManifestResourceNames(); Console.WriteLine($"AUDXAM ALL FILES: {files.Length} {files.ToList()} { files[0]}"); if (recorder.IsRecording != true && player.IsPlaying == false) { //player.Load(GetStreamFromFile()); player.Play(); var startTimeSpan = TimeSpan.Zero; var periodTimeSpan = TimeSpan.FromMilliseconds(60); float[] op2 = new float[10]; Array.Clear(op2, 0, op2.Length); timer = new System.Threading.Timer((e) => { if (player.IsPlaying) { //Console.WriteLine($"{tag} CURRENT PREDICTION: {op.Score[9]} curPos:{Convert.ToInt32(player.CurrentPosition)} M AT ZERO {featureTimeList[0].Mfcc0} AT FIVE {featureTimeList[5].Mfcc0} FINAL -> {ConsumeModel.Predict(featureTimeList[Convert.ToInt32(player.CurrentPosition)]).Score[5]}"); op = featureTimeList[Convert.ToInt32(player.CurrentPosition)]; for (int i = 0; i < 10; i++) { op2[i] += op[i]; } float max_sf = 0; int max_ind = 0; string[] labels = "Blues, Classical, Country, Disco, HipHop, Jazz, Metal, Pop, Reggae Rock".Split(','); for (int i = 0; i < 10; i++) { if (op2[i] > max_sf) { max_sf = op2[i]; max_ind = i; } } PredictedLabel = $"{labels[max_ind]}!"; //Pass to ML.net var entries_agg = new[] { new ChartEntry(op2[0]) { Label = "Blues", ValueLabel = $"{op2[0]}", Color = SKColor.Parse("#2c3e50") }, new ChartEntry(op2[1]) { Label = "Classical", ValueLabel = $"{op2[1]}", Color = SKColor.Parse("#77d065") }, new ChartEntry(op2[2]) { Label = "Country", ValueLabel = $"{op2[2]}", Color = SKColor.Parse("#b455b6") }, new ChartEntry(op2[3]) { Label = "Disco", ValueLabel = $"{op2[3]}", Color = SKColor.Parse("#245e50") }, new ChartEntry(op2[4]) { Label = "Hiphop", ValueLabel = $"{op2[4]}", Color = SKColor.Parse("#3498db") }, new ChartEntry(op2[5]) { Label = "Jazz", ValueLabel = $"{op2[5]}", Color = SKColor.Parse("#263e50") }, new ChartEntry(op2[6]) { Label = "Metal", ValueLabel = $"{op2[6]}", Color = SKColor.Parse("#123456") }, new ChartEntry(op2[7]) { Label = "Pop", ValueLabel = $"{op2[7]}", Color = SKColor.Parse("#654321") }, new ChartEntry(op2[8]) { Label = "Reggae", ValueLabel = $"{op2[8]}", Color = SKColor.Parse("#526784") }, new ChartEntry(op2[9]) { Label = "Rock", ValueLabel = $"{op2[9]}", Color = SKColor.Parse("#404040") } }; var entries_current = new[] { new ChartEntry(op[0]) { Label = "Blues", ValueLabel = $"{op[0]}", Color = SKColor.Parse("#2c3e50") }, new ChartEntry(op[1]) { Label = "Classical", ValueLabel = $"{op[1]}", Color = SKColor.Parse("#77d065") }, new ChartEntry(op[2]) { Label = "Country", ValueLabel = $"{op[2]}", Color = SKColor.Parse("#b455b6") }, new ChartEntry(op[3]) { Label = "Disco", ValueLabel = $"{op[3]}", Color = SKColor.Parse("#245e50") }, new ChartEntry(op[4]) { Label = "Hiphop", ValueLabel = $"{op[4]}", Color = SKColor.Parse("#3498db") }, new ChartEntry(op[5]) { Label = "Jazz", ValueLabel = $"{op[5]}", Color = SKColor.Parse("#263e50") }, new ChartEntry(op[6]) { Label = "Metal", ValueLabel = $"{op[6]}", Color = SKColor.Parse("#123456") }, new ChartEntry(op[7]) { Label = "Pop", ValueLabel = $"{op[7]}", Color = SKColor.Parse("#654321") }, new ChartEntry(op[8]) { Label = "Reggae", ValueLabel = $"{op[8]}", Color = SKColor.Parse("#526784") }, new ChartEntry(op[9]) { Label = "Rock", ValueLabel = $"{op[9]}", Color = SKColor.Parse("#404040") } }; //Update and draw graph AggChart = new DonutChart() { Entries = entries_agg, IsAnimated = false, AnimationDuration = TimeSpan.FromMilliseconds(0) }; //CurrentChart = new DonutChart() { Entries = entries_current, IsAnimated = false, AnimationDuration = TimeSpan.FromMilliseconds(0) }; //Console.WriteLine($"{tag} Updated chart! C {op.Score[9]} A ->{op2[9]}"); //Graph 1 -> Current prediciton //Graph 2 -> Aggregate of predictions so far } else { player.Seek(0.0); timer.Dispose(); } }, null, startTimeSpan, periodTimeSpan); } }); recordCommand = new Command(async() => { if (RecordStatus != "record") { PredictedLabel = "Processing audio..."; await recorder.StopRecording().ConfigureAwait(true); if (_filePath != null) { //await extractFeatures(); var stream = new FileStream(_filePath, FileMode.Open); AudioFunctions.WriteWavHeader(stream, 1, 48000, 16, (int)stream.Length - 44); stream.Close(); player.Load(GetStreamFromFile()); //player.Play(); duration = Convert.ToInt32(player.Duration); Console.WriteLine($"{tag} DUR: {duration}"); // player.Dispose(); extractFeatures(); //await predict } RecordStatus = "record"; } else { PredictedLabel = "Recording..."; IsBusy = true; RecordStatus = "stop"; var recordTask = await recorder.StartRecording().ConfigureAwait(true); _filePath = await recordTask.ConfigureAwait(true); //player.Play(_filePath } }); }
//[Test] public void EvaluateAudioTrigger_BasicShouldReturnTrue() { var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", ""); //System.IO.FileStream WaveFile = System.IO.File.OpenRead(path + "\\Data\\TestAudio.wav"); //byte[] data = new byte[WaveFile.Length]; int sampleRate; //double[] fileData = Functions.WaveFileDataPrepare(path + "\\Data\\TestAudio.wav", out sampleRate);'' List <double> fftData = new List <double>(); int BUFFERSIZE = (int)Math.Pow(2, 11); // must be a multiple of 2 WaveStream waveStream = new NAudio.Wave.WaveFileReader(path + "\\Data\\TestAudio.wav"); int bytesPerSample = (waveStream.WaveFormat.BitsPerSample / 8) * waveStream.WaveFormat.Channels; int bytesRead = 0; BufferedWaveProvider bwp = new BufferedWaveProvider(new WaveFormat(44100, 1)); bwp.BufferLength = BUFFERSIZE * 2; bwp.DiscardOnBufferOverflow = true; byte[] waveData = new byte[BUFFERSIZE * 2]; bytesRead = waveStream.Read(waveData, 0, 128 * bytesPerSample); bwp.AddSamples(waveData, 0, bytesRead); int frameSize = BUFFERSIZE; byte[] frames = new byte[frameSize]; bwp.Read(frames, 0, frameSize); var waveFormEventArgs = AudioFunctions.PrepareAudioData(frames, frameSize); fftData.AddRange(waveFormEventArgs.FastFourierTransform); while (bytesRead != 0) { bytesRead = waveStream.Read(waveData, bytesRead, 128 * bytesPerSample); bwp.AddSamples(waveData, 0, bytesRead); frameSize = BUFFERSIZE; frames = new byte[frameSize]; bwp.Read(frames, 0, frameSize); waveFormEventArgs = AudioFunctions.PrepareAudioData(frames, frameSize); fftData.AddRange(waveFormEventArgs.FastFourierTransform); } //WavFile wavFile = new WavFile(); //wavFile.ReadWav(path + "\\Data\\TestAudio.wav"); //WaveFileReader reader = new WaveFileReader(path + "\\Data\\TestAudio.wav"); //List<byte> testAudio1; // = File.ReadAllBytes(path + "\\Data\\TestAudio.wav").ToList(); //int BUFFERSIZE = (int)Math.Pow(2, 14); // must be a multiple of 2 //using (var reader = new AudioFileReader(path + "\\Data\\TestAudio.wav")) //{ // // find the max peak // byte[] buffer = new byte[BUFFERSIZE]; // int read; // do // { // read = reader.Read(buffer, 0, buffer.Length); // } while (read > 0); // testAudio1 = new List<byte>(buffer); //} Logger log = new LoggerConfiguration() .MinimumLevel.Error() .CreateLogger(); var audioEvaluator = new AudioEvaluator(log); //if (testAudio1.Count() % 2 != 0) //{ // testAudio1.RemoveAt(testAudio1.Count() - 1); //} var trigger = new Trigger(); trigger.Frequency1 = 645.7; trigger.Frequency2 = 716.10; trigger.Count = 2; trigger.Time1 = 1; //wavFile.FFT(false); //var fftData = Functions.FFT(fileData); //var fftData = wavFile._aSamples; //var result = audioEvaluator.EvaluateAudioTrigger(trigger, fftData.ToArray()); //result.Should().BeTrue(); }
public float GetVol() { return(AudioFunctions.DbToLinear(Volume)); }