Beispiel #1
0
        private List <PossibleHeldNote> GetHeldNotesFromFrequencyBand(FrequencyBand newFrequencyBand)
        {
            List <PossibleHeldNote> heldNotes = new List <PossibleHeldNote>();

            FrequencyBand.FBPoint lastValidPoint = null;

            float amplitudeSum = 0;
            int   amplitudesN  = 0;

            float timeDelta = newFrequencyBand.FBPoints[1].Time - newFrequencyBand.FBPoints[0].Time;

            foreach (FrequencyBand.FBPoint fbPoint in newFrequencyBand.FBPoints)
            {
                if (fbPoint.MinimumSquaredErrorToPrevious < MaximumSquaredError)
                {
                    if (lastValidPoint == null)
                    {
                        lastValidPoint = fbPoint;
                    }

                    amplitudeSum += fbPoint.Amplitude;
                    amplitudesN++;
                }
                else
                {
                    if (lastValidPoint != null)
                    {
                        float timeDifference = fbPoint.Time - lastValidPoint.Time;

                        if (timeDifference > MinimumTimeWidth)
                        {
                            PossibleHeldNote heldNote = new PossibleHeldNote();

                            heldNote.StartTime = lastValidPoint.Time;
                            heldNote.EndTime   = fbPoint.Time - timeDelta;

                            float amplitudeMeanValue = amplitudeSum / amplitudesN;

                            heldNote.AmplitudeMeanValue = amplitudeMeanValue;
                            heldNote.Applicability      = amplitudeMeanValue;

                            heldNotes.Add(heldNote);
                        }

                        lastValidPoint = null;
                    }

                    amplitudeSum = 0;
                    amplitudesN  = 0;
                }
            }

            return(heldNotes);
        }
        private void AddFrequencyToFrequencyBand(FrequencyBand frequencyBand, float time, float[] spectrum)
        {
            int numberOfSpectrumBands = frequencyBand.SpectrumBands.Count;

            float[] frequencyValues = new float[numberOfSpectrumBands];

            for (int i = 0; i < numberOfSpectrumBands; i++)
            {
                frequencyValues[i] = spectrum[frequencyBand.SpectrumBands[i]];
            }

            frequencyBand.AddAmplitudes(time, frequencyValues);
        }
Beispiel #3
0
        public SongPropertyValues CreateSongPropertyValuesTest(int index)
        {
            FrequencyBand fb = heldNoteDetection.GetFrequencyBands()[index];

            SongPropertyValues spv = new SongPropertyValues("Freqband " + fb.LeftFrequencyMargin + " - " + fb.RightFrequencyMargin);

            spv.Points = new List <Util.MyPoint>(fb.Points);

            spv.Normalize();

            rectangularDetection.RectangulateSongPropertyValues(spv);

            return(spv);
        }
Beispiel #4
0
        private void AddFrequencyToFrequencyBands(FrequencyBand frequencyBand, float time, float[] spectrum)
        {
            int start = frequencyBand.LeftFrequencyMargin;
            int end   = Math.Min(frequencyBand.RightFrequencyMargin, spectrum.Length);

            float maxValue = 0;

            for (int i = start; i < end; i++)
            {
                if (spectrum[i] > maxValue)
                {
                    maxValue = spectrum[i];
                }
            }

            frequencyBand.AddFrequency(time, maxValue);
        }
        private void CreateFrequencyBands()
        {
            float firstKey = 16;            // C2
            float lastKey  = 75;            // B6

            for (float i = firstKey; i < lastKey; i += 0.5f)
            {
                float lowestFrequency  = GetFrequency(i);
                float highestFrequency = GetFrequency(i + 1);

                int lowestFFTBand  = (int)Math.Floor(lowestFrequency / fftFrequencyBandWidth);
                int highestFFTBand = (int)Math.Ceiling(highestFrequency / fftFrequencyBandWidth);

                FrequencyBand frequencyBand = new FrequencyBand();

                for (int j = lowestFFTBand; j <= highestFFTBand; j++)
                {
                    frequencyBand.AddSpectrumBand(j);
                }

                frequencyBands.Add(frequencyBand);
            }
        }