public static void onsetDetection()
        {
            Time timer = new Time();
            int starts = 0;
            int stops = 0;
            List<int> noteStops;
            List<double> pitches;

            noteStarts = new List<int>(100);
            noteStops = new List<int>(100);
            lengths = new List<int>(100);
            pitches = new List<double>(100);

            HFC = new float[stftRep.timeFreqData[0].Length];
            //timer.next("Onset setup");
            Thread[] mine = new Thread[MainProgram.Num_threads];
            for (int a = 0; a < MainProgram.Num_threads; a++)
            {
                mine[a] = new Thread(onsetloop1);
                mine[a].Start(a);
            }
            for (int a = 0; a < MainProgram.Num_threads; a++)
            {
                mine[a].Join();
            }
            //timer.next("Onset loop 1");
            float maxi = HFC.Max();

            for (int jj = 0; jj < stftRep.timeFreqData[0].Length; jj++)
            {
                HFC[jj] = (float)Math.Pow((HFC[jj] / maxi), 2);
            }
            //timer.next("Onset loop 2");
            for (int jj = 0; jj < stftRep.timeFreqData[0].Length; jj++)
            {
                if (starts > stops)
                {
                    if (HFC[jj] < 0.001)
                    {
                        noteStops.Add(jj * ((stftRep.wSamp - 1) / 2));
                        stops = stops + 1;
                    }
                }
                else if (starts - stops == 0)
                {
                    if (HFC[jj] > 0.001)
                    {
                        noteStarts.Add(jj * ((stftRep.wSamp - 1) / 2));
                        starts = starts + 1;
                    }

                }
            }
            //timer.next("Onset loop 3");
            if (starts > stops)
            {
                noteStops.Add(waveIn.data.Length);
            }

            // DETERMINES START AND FINISH TIME OF NOTES BASED ON ONSET DETECTION

            ///*
            // timer.restart();
            for (int ii = 0; ii < noteStops.Count; ii++)
            {
                lengths.Add(noteStops[ii] - noteStarts[ii]);
            }
            timer.next("Onset loop 4");

            allpitches = new List<double>[Num_threads];
            for (int a = 0; a < Num_threads; a++)
            {
                allpitches[a] = new List<double>();
                mine[a] = new Thread(onsetloopmm);
                mine[a].Start(a);
            }
            for (int a = 0; a < Num_threads; a++)
            {
                mine[a].Join();
                pitches.AddRange(allpitches[a]);
            }

            timer.next("onset mm loop");

            musicNote[] noteArray;
            noteArray = new musicNote[noteStarts.Count()];

            for (int ii = 0; ii < noteStarts.Count(); ii++)
            {
                noteArray[ii] = new musicNote(pitches[ii], lengths[ii]);
            }
            //timer.next("onset loop 6");
            int[] sheetPitchArray = new int[sheetmusic.Length];
            int[] notePitchArray = new int[noteArray.Length];

            for (int ii = 0; ii < sheetmusic.Length; ii++)
            {
                sheetPitchArray[ii] = sheetmusic[ii].pitch % 12;
            }
            //timer.next("onset loop 7");
            for (int jj = 0; jj < noteArray.Length; jj++)
            {
                notePitchArray[jj] = noteArray[jj].pitch % 12;
            }
            //timer.next("onset loop 8");
            string[] alignedStrings = new string[2];

            alignedStrings = stringMatch(sheetPitchArray, notePitchArray);

            musicNote[] alignedStaffArray = new musicNote[alignedStrings[0].Length / 2];
            musicNote[] alignedNoteArray = new musicNote[alignedStrings[1].Length / 2];
            int staffCount = 0;
            int noteCount = 0;
            //timer.next("onset stuff");
            for (int ii = 0; ii < alignedStrings[0].Length / 2; ii++)
            {

                if (alignedStrings[0][2 * ii] == ' ')
                {
                    alignedStaffArray[ii] = new musicNote(0, 0);
                }
                else
                {
                    alignedStaffArray[ii] = sheetmusic[staffCount];
                    staffCount++;
                }

                if (alignedStrings[1][2 * ii] == ' ')
                {
                    alignedNoteArray[ii] = new musicNote(0, 0);
                }
                else
                {
                    alignedNoteArray[ii] = noteArray[noteCount];
                    noteCount++;
                }
            }
            timer.end("onset last");
        }
        static void Main(string[] args)
        {
            string filename = "..//..//Jupiter.wav";
            string xmlfile = "..//..//Jupiter.xml";
            Time timewhole = new Time();
            Time timer = new Time();
            loadWave(filename);
            timer.next("\nsetup");
            freqDomain();
            timer.next("\nfreqDomain");
            sheetmusic = readXML(xmlfile);
            timer.next("\nsheetmusic");
            onsetDetection();
            timer.next("\nonsetDetection");
            //timer.next("\nloadImage");
            //timer.next("\nloadHistogram");
            //timer.next("\nplayBack");

            timer.end("\nOther stuff");
            Console.WriteLine("It is done!");
            timewhole.end("Overall time");
            Console.ReadKey();
        }