Esempio n. 1
0
        // Loads Histogram for tab 2

        public void loadHistogram()
        {
            // HISTOGRAMo

            float fs      = waveIn.SampleRate;
            float divisor = fs / stftRep.wSamp;

            noteGraph LOWEST  = new noteGraph(110, divisor);
            noteGraph LOW     = new noteGraph(220, divisor);
            noteGraph MIDDLE  = new noteGraph(440, divisor);
            noteGraph HIGH    = new noteGraph(880, divisor);
            noteGraph HIGHEST = new noteGraph(1760, divisor);

            int rows = stftRep.wSamp / 2;

            float[] column = new float[rows];

            for (int i = 0; i < rows; i++)
            {
                column[i] = stftRep.timeFreqData[i][(int)Math.Floor(slider1.Value)];
            }

            LOWEST.setRectHeights(column);
            LOW.setRectHeights(column);
            MIDDLE.setRectHeights(column);
            HIGH.setRectHeights(column);
            HIGHEST.setRectHeights(column);

            double[] maxi = new double[5];

            maxi[0] = LOWEST.heights.Max() / 60;
            maxi[1] = LOW.heights.Max() / 60;
            maxi[2] = MIDDLE.heights.Max() / 60;
            maxi[3] = HIGH.heights.Max() / 60;
            maxi[4] = HIGHEST.heights.Max() / 60;

            double absMax = maxi.Max();

            // DYNAMIC RECTANGLES

            SolidColorBrush myBrush = new SolidColorBrush(Colors.Black);

            //Lowest Octif

            Rectangle[] lowestRects = null;
            lowestRects = new Rectangle[(int)Math.Floor(110 / divisor)];
            for (int ii = 0; ii < (int)Math.Floor(110 / divisor); ii++)
            {
                double lowestMarg = Math.Log(((110 + ii * divisor) / 110), 2) * 240;

                lowestRects[ii]        = new Rectangle();
                lowestRects[ii].Fill   = myBrush;
                lowestRects[ii].Width  = 1;
                lowestRects[ii].Height = LOWEST.heights[ii] / absMax; //maxi[0];
                lowestRects[ii].Margin = new Thickness(10 + lowestMarg, 0, 0, 0);
                LowestOctif.Children.Insert(ii, lowestRects[ii]);
            }

            //Low Octif

            Rectangle[] lowRects = null;
            lowRects = new Rectangle[(int)Math.Floor(220 / divisor)];
            for (int ii = 0; ii < (int)Math.Floor(220 / divisor); ii++)
            {
                double lowMarg = Math.Log(((220 + ii * divisor) / 220), 2) * 240;

                lowRects[ii]        = new Rectangle();
                lowRects[ii].Fill   = myBrush;
                lowRects[ii].Width  = 1;
                lowRects[ii].Height = LOW.heights[ii] / absMax; //maxi[1];
                lowRects[ii].Margin = new Thickness(10 + lowMarg, 0, 0, 0);
                LowOctif.Children.Insert(ii, lowRects[ii]);
            }

            //Middle Octif

            Rectangle[] midRects = null;
            midRects = new Rectangle[(int)Math.Floor(440 / divisor)];

            for (int ii = 0; ii < (int)Math.Floor(440 / divisor); ii++)
            {
                double midMarg = Math.Log(((440 + ii * divisor) / 440), 2) * 240;

                midRects[ii]        = new Rectangle();
                midRects[ii].Fill   = myBrush;
                midRects[ii].Width  = 1;
                midRects[ii].Height = MIDDLE.heights[ii] / absMax; //maxi[2];
                midRects[ii].Margin = new Thickness(10 + midMarg, 0, 0, 0);
                MiddleOctif.Children.Insert(ii, midRects[ii]);
            }

            //High Octif

            Rectangle[] highRects = null;
            highRects = new Rectangle[(int)Math.Floor(880 / divisor)];

            for (int ii = 0; ii < (int)Math.Floor(880 / divisor); ii++)
            {
                double highMarg = Math.Log(((880 + ii * divisor) / 880), 2) * 240;

                highRects[ii]        = new Rectangle();
                highRects[ii].Fill   = myBrush;
                highRects[ii].Width  = 1;
                highRects[ii].Height = HIGH.heights[ii] / absMax; //maxi[3];
                highRects[ii].Margin = new Thickness(10 + highMarg, 0, 0, 0);
                HighOctif.Children.Insert(ii, highRects[ii]);
            }

            //Highest Octif

            Rectangle[] highestRects = null;
            highestRects = new Rectangle[(int)Math.Floor(1760 / divisor)];

            for (int ii = 0; ii < (int)Math.Floor(1760 / divisor); ii++)
            {
                double highestMarg = Math.Log(((1760 + ii * divisor) / 1760), 2) * 240;

                highestRects[ii]        = new Rectangle();
                highestRects[ii].Fill   = myBrush;
                highestRects[ii].Width  = 1;
                highestRects[ii].Height = HIGHEST.heights[ii] / absMax; //maxi[4];
                highestRects[ii].Margin = new Thickness(10 + highestMarg, 0, 0, 0);
                HighestOctif.Children.Insert(ii, highestRects[ii]);
            }
        }
        // Loads Histogram for tab 2
        public void loadHistogram()
        {
            // HISTOGRAM

            float fs = waveIn.SampleRate;
            float divisor = fs / stftRep.wSamp;

            noteGraph LOWEST = new noteGraph(110, divisor);
            noteGraph LOW = new noteGraph(220, divisor);
            noteGraph MIDDLE = new noteGraph(440, divisor);
            noteGraph HIGH = new noteGraph(880, divisor);
            noteGraph HIGHEST = new noteGraph(1760, divisor);

            int rows = stftRep.wSamp / 2;

            float[] column = new float[rows];

            for (int i = 0; i < rows; i++)
            {
                column[i] = stftRep.timeFreqData[i][(int)Math.Floor(slider1.Value)];
            }

            LOWEST.setRectHeights(column);
            LOW.setRectHeights(column);
            MIDDLE.setRectHeights(column);
            HIGH.setRectHeights(column);
            HIGHEST.setRectHeights(column);

            double[] maxi = new double[5];

            maxi[0] = LOWEST.heights.Max() / 60;
            maxi[1] = LOW.heights.Max() / 60;
            maxi[2] = MIDDLE.heights.Max() / 60;
            maxi[3] = HIGH.heights.Max() / 60;
            maxi[4] = HIGHEST.heights.Max() / 60;

            double absMax = maxi.Max();

            // DYNAMIC RECTANGLES

            SolidColorBrush myBrush = new SolidColorBrush(Colors.Black);

            //Lowest Octif

            Rectangle[] lowestRects = null;
            lowestRects = new Rectangle[(int)Math.Floor(110 / divisor)];
            for (int ii = 0; ii < (int)Math.Floor(110 / divisor); ii++)
            {
                double lowestMarg = Math.Log(((110 + ii * divisor) / 110), 2) * 240;

                lowestRects[ii] = new Rectangle();
                lowestRects[ii].Fill = myBrush;
                lowestRects[ii].Width = 1;
                lowestRects[ii].Height = LOWEST.heights[ii] / absMax; //maxi[0];
                lowestRects[ii].Margin = new Thickness(10 + lowestMarg, 0, 0, 0);
                LowestOctif.Children.Insert(ii, lowestRects[ii]);
            }

            //Low Octif

            Rectangle[] lowRects = null;
            lowRects = new Rectangle[(int)Math.Floor(220 / divisor)];
            for (int ii = 0; ii < (int)Math.Floor(220 / divisor); ii++)
            {
                double lowMarg = Math.Log(((220 + ii * divisor) / 220), 2) * 240;

                lowRects[ii] = new Rectangle();
                lowRects[ii].Fill = myBrush;
                lowRects[ii].Width = 1;
                lowRects[ii].Height = LOW.heights[ii] / absMax; //maxi[1];
                lowRects[ii].Margin = new Thickness(10 + lowMarg, 0, 0, 0);
                LowOctif.Children.Insert(ii, lowRects[ii]);
            }

            //Middle Octif

            Rectangle[] midRects = null;
            midRects = new Rectangle[(int)Math.Floor(440 / divisor)];

            for (int ii = 0; ii < (int)Math.Floor(440 / divisor); ii++)
            {
                double midMarg = Math.Log(((440 + ii * divisor) / 440), 2) * 240;

                midRects[ii] = new Rectangle();
                midRects[ii].Fill = myBrush;
                midRects[ii].Width = 1;
                midRects[ii].Height = MIDDLE.heights[ii] / absMax; //maxi[2];
                midRects[ii].Margin = new Thickness(10 + midMarg, 0, 0, 0);
                MiddleOctif.Children.Insert(ii, midRects[ii]);
            }

            //High Octif

            Rectangle[] highRects = null;
            highRects = new Rectangle[(int)Math.Floor(880 / divisor)];

            for (int ii = 0; ii < (int)Math.Floor(880 / divisor); ii++)
            {
                double highMarg = Math.Log(((880 + ii * divisor) / 880), 2) * 240;

                highRects[ii] = new Rectangle();
                highRects[ii].Fill = myBrush;
                highRects[ii].Width = 1;
                highRects[ii].Height = HIGH.heights[ii] / absMax; //maxi[3];
                highRects[ii].Margin = new Thickness(10 + highMarg, 0, 0, 0);
                HighOctif.Children.Insert(ii, highRects[ii]);
            }

            //Highest Octif

            Rectangle[] highestRects = null;
            highestRects = new Rectangle[(int)Math.Floor(1760 / divisor)];

            for (int ii = 0; ii < (int)Math.Floor(1760 / divisor); ii++)
            {
                double highestMarg = Math.Log(((1760 + ii * divisor) / 1760), 2) * 240;

                highestRects[ii] = new Rectangle();
                highestRects[ii].Fill = myBrush;
                highestRects[ii].Width = 1;
                highestRects[ii].Height = HIGHEST.heights[ii] / absMax; //maxi[4];
                highestRects[ii].Margin = new Thickness(10 + highestMarg, 0, 0, 0);
                HighestOctif.Children.Insert(ii, highestRects[ii]);
            }
        }