Example #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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
            }
        }