//public int spawnModifer = 10; // Use this for initialization void Start() { sampleRate = audioSource.clip.frequency; onset = FindObjectOfType <OnsetDetector>(); amplitude = FindObjectOfType <AmplitudeDetector>(); spawner = FindObjectOfType <EnemySpawner>(); }
// Use this for initialization void Start() { onset = FindObjectOfType <OnsetDetector>(); audio = gameObject.AddComponent <AudioSource>(); audio.clip = Resources.Load("sfx_aura") as AudioClip; audio.loop = true; audio.spatialBlend = 1.0f; audio.Play(); }
public AudioFeatures(DetectorOptions options, string csvDirectory, float correction, IProgress <string> progress = null) { //force garbage collection GC.Collect(2, GCCollectionMode.Forced, true); _csvDirectory = csvDirectory; _outerProgressReporter = progress ?? new Progress <string>(); _correction = correction; _innerProgressReporter = new Progress <string>(status => { _outerProgressReporter.Report(_currentTask + ":" + status); }); _onsetDetector = new OnsetDetector(options, _innerProgressReporter); }
static void Main(string[] args) { double[][] inputs = { }; int[] outputs = { }; if (LearningModel.doTraining) { for (int i = 1; i <= Training.LearningModel.noteCount; i++) { string training_file = "C:\\UCLA\\MrChorder-master\\MrChorder\\Training\\LearningModelData\\piano" + i.ToString() + ".wav"; OnsetDetector onsetDetector = new OnsetDetector(training_file, null); double[][] FAData = onsetDetector.GenerateTrainingFAData(); inputs = ConcatVector(inputs, FAData); int[] arr = new int[FAData.Length]; for (int j = 0; j < arr.Length; j++) { arr[j] = i - 1; } outputs = ConcatElement(outputs, arr); Console.WriteLine("Training FA Data generated."); } } LearningModel svm = new LearningModel(inputs, outputs); Console.WriteLine("Testing."); string testFile = "C:\\UCLA\\MrChorder-master\\MrChorder\\Training\\LearningModelData\\test3.wav"; OnsetDetector testDetector = new OnsetDetector(testFile, svm); double[][] notes = testDetector.GenerateNotes(); double[][] labels = { }; foreach (string line in File.ReadLines("C:\\UCLA\\MrChorder-master\\MrChorder\\Training\\LearningModelData\\label3", Encoding.UTF8)) { double[][] t = new double[1][]; t[0] = new double[2]; string[] s = line.Split(' '); t[0][0] = Double.Parse(s[0]); t[0][1] = Double.Parse(s[1]); labels = ConcatVector(labels, t); } double[] acc = GetAccuracy(notes, labels); Console.WriteLine("End"); }
public void SendFile() { // Process file. string resultFilePath = System.IO.Path.Combine(Server.MapPath("~\\Generate\\"), System.IO.Path.GetFileName("AnalyseResult.pdf")); while (!System.IO.File.Exists(resultFilePath)) { // TODO(allenxie): Fancy work on filename processing. double[][] inputs = { }; int[] outputs = { }; LearningModel svm = new LearningModel(inputs, outputs); // Pre-trained OnsetDetector od = new OnsetDetector(filename, svm); double[][] music = od.GenerateNotes(); for (int i = 0; i < music.Length; i++) { music[i][0] = music[i][0] + 1; // Sync Training module and ToPDF module } ToPDF PDFGenerator = new ToPDF(resultFilePath, music, music.Length, musicname); } Response.Write("Return file successfully!"); Response.End(); }
public List <Note> Detection() { List <Note> noteList = new List <Note>(); //Console.WriteLine("Press any key to convert to .WAV file..."); //Console.ReadLine(); int i; //Open MP3 file and convert to WAV file. WaveOutEvent waveOut = new WaveOutEvent(); Mp3FileReader mp3Reader = new Mp3FileReader(@"C:\Users\Fazle\source\repos\Practice\Media\twinkle.mp3"); toWAV(mp3Reader); //Console.WriteLine(".WAV file created! Press any key to continue..."); //Console.ReadLine(); StereoToMono(@"C:\Users\Fazle\source\repos\Practice\Media\current.wav"); int sampleRate; double[] data = null, R = null; ReadWavFile(out sampleRate); openWav(@"C:\Users\Fazle\source\repos\Practice\Media\currentMono.wav", out data, out R); //Console.WriteLine(data.Length); Progress <string> progress = new Progress <string>(); OnsetDetector detector = new OnsetDetector(DetectorOptions.Default, progress); List <Onset> list = detector.Detect(@"C:\Users\Fazle\source\repos\Practice\Media\currentMono.wav"); /*Console.WriteLine("Time Amp"); * for (i = 0; i < list.Count; i++) * { * Console.Write(list[i].OnsetTime); * Console.Write(" "); * Console.Write(list[i].OnsetAmplitude); * Console.Write(" "); * Console.WriteLine(); * } * Console.WriteLine();*/ int startPos = 0, stopPos = 0, flag = 0; double freq = 0, duration = 0; double[] temp; double[] result; CSCore.Utils.Complex[] complex; for (i = 0; i < list.Count - 1; i++) { startPos = (int)Math.Ceiling(list[i].OnsetTime * sampleRate); stopPos = (int)Math.Floor(list[i + 1].OnsetTime * sampleRate); temp = new double[stopPos - startPos]; result = new double[stopPos - startPos]; complex = new CSCore.Utils.Complex[stopPos - startPos]; Array.ConstrainedCopy(data, startPos, temp, 0, temp.Length); for (int j = 0; j < complex.Length; j++) { complex[j] = new Complex((float)temp[j]); //Console.WriteLine(complex[j]); } //Console.ReadLine(); Note note = new Note(); note.Frequency = CalculateFFT(result, complex, flag); note.Name = UtilMethods.FreqToNote(note.Frequency); note.Duration = list[i + 1].OnsetTime - list[i].OnsetTime; noteList.Add(note); } //Last Note startPos = (int)Math.Floor(list[i].OnsetTime * sampleRate); stopPos = data.Length - 1; temp = new double[stopPos - startPos]; result = new double[stopPos - startPos]; complex = new CSCore.Utils.Complex[stopPos - startPos]; Array.ConstrainedCopy(data, startPos, temp, 0, temp.Length); for (int j = 0; j < complex.Length; j++) { complex[j] = new Complex((float)temp[j]); } flag = 1; Note lastNote = new Note(); lastNote.Frequency = CalculateFFT(result, complex, flag); lastNote.Name = UtilMethods.FreqToNote(lastNote.Frequency); lastNote.Duration = (data.Length / sampleRate) - list[i].OnsetTime; noteList.Add(lastNote); //Console.WriteLine("Press any key to terminate."); //Console.ReadLine(); mp3Reader.Dispose(); return(noteList); }