Ejemplo n.º 1
0
        public FrequencyChart BandGrouping(Bands bands, FrequencyChart chart, double threshHold)
        {
            var freqs      = bands.Frequencies;
            var workCharts = chart.Where(k => k.Level > threshHold).ToArray();
            var newChart   = new FrequencyChart(chart.TotalLevel, chart.AverageLevel, new List <FrequencyPair>());
            var curBand    = 0;
            var curUpBound = freqs[curBand];

            int curFreqInBand = 0;
            var curPair       = new FrequencyPair(curUpBound, 0);

            for (int i = 0; i < workCharts.Count; i++)
            {
                var sample = workCharts [i];

                if (sample.Frequency < curUpBound)
                {
                    curPair.Level += sample.Level;
                }
                else if (freqs.Count > curBand)
                {
                    curPair.Level /= curFreqInBand;
                    curFreqInBand  = 0;
                    while (sample.Frequency > curUpBound)
                    {
                        curBand++;
                        if (freqs.Count <= curBand)
                        {
                            curUpBound = freqs[freqs.Count - 1] * 10;
                        }
                        else
                        {
                            curUpBound = freqs[curBand];
                        }
                    }
                    newChart.Add(curPair);
                    curPair = new FrequencyPair(curUpBound, sample.Level);
                }
                curFreqInBand++;
            }


            return(newChart);
        }
Ejemplo n.º 2
0
        public FrequencyChart BandGrouping(Bands bands, FrequencyChart chart)
        {
            Debug.Assert(bands.Notes.Count >= 2);
            var freqs = bands.Notes.Select(k => k.Frequency).ToArray();


            var curBand = 0;


            var t        = new List <FrequencyPair> ();
            var lowPair  = new FrequencyPair(bands.Notes[0].Frequency, 0);
            var highPair = new FrequencyPair(bands.Notes[1].Frequency, 0);

            t.Add(highPair);
            t.Add(lowPair);

            for (int i = 0; i < chart.Count; i++)
            {
                var sample = chart [i];

                while (sample.Frequency > highPair.Frequency)
                {
                    if (curBand == bands.Notes.Count - 1)
                    {
                        goto C1;
                    }
                    lowPair = highPair;
                    curBand++;
                    highPair = new FrequencyPair(bands.Notes [curBand].Frequency, 0);
                    t.Add(highPair);
                }


                lowPair.Level  += sample.Level * Math.Round((sample.Frequency - lowPair.Frequency) / (highPair.Frequency - lowPair.Frequency));
                highPair.Level += sample.Level * Math.Round((highPair.Frequency - sample.Frequency) / (highPair.Frequency - lowPair.Frequency));
            }


            C1 :         return(new FrequencyChart(t));
        }
Ejemplo n.º 3
0
        public FrequencyChart LocalizeMaximums(FrequencyChart chart, int gapCount)
        {
            if (!chart.Any())
            {
                return(chart);
            }
            var           list          = new List <FrequencyPair> ();
            bool          raising       = true;
            FrequencyPair localMax      = chart[0];
            FrequencyPair lastMeaninful = chart[0];

            for (var i = 0; i < chart.Count; i++)
            {
                double derivation;
                var    cur = GetFromArray(chart, i);
                derivation = cur.Level - lastMeaninful.Level;

                if (raising)
                {
                    if (derivation >= 0)
                    {
                        localMax      = cur;
                        lastMeaninful = localMax;
                    }
                    else
                    {
                        bool shouldContinueRaising = false;

                        for (int j = i + 1; j <= i + gapCount; j++)
                        {
                            if (GetFromArray(chart, j).Level - lastMeaninful.Level >= 0)
                            {
                                lastMeaninful         = GetFromArray(chart, j);
                                shouldContinueRaising = true;
                                break;
                            }
                        }
                        if (!shouldContinueRaising)
                        {
                            list.Add(localMax);
                            lastMeaninful = cur;
                            raising       = false;
                        }
                    }
                }
                else
                {
                    if (derivation <= 0)
                    {
                        lastMeaninful = cur;
                    }
                    else
                    {
                        bool shouldStartRaising = true;

                        for (int j = i + 1; j <= i + gapCount; j++)
                        {
                            if (GetFromArray(chart, j).Level - lastMeaninful.Level <= 0)
                            {
                                lastMeaninful      = GetFromArray(chart, j);
                                shouldStartRaising = false;
                                break;
                            }
                        }
                        if (shouldStartRaising)
                        {
                            localMax      = cur;
                            lastMeaninful = cur;
                            raising       = true;
                        }
                    }
                }
            }
            if (raising)
            {
                list.Add(chart[chart.Count - 1]);
            }
            return(new FrequencyChart(list));
        }