Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 135:e98130764635
* Sensible default for vertical thumbwheel on spectrogram layer
author | Chris Cannam |
---|---|
date | Mon, 21 Aug 2006 13:18:50 +0000 |
parents | 13949a6970ab |
children | a859b87162ca |
comparison
equal
deleted
inserted
replaced
134:13949a6970ab | 135:e98130764635 |
---|---|
49 m_gain(1.0), | 49 m_gain(1.0), |
50 m_threshold(0.0), | 50 m_threshold(0.0), |
51 m_colourRotation(0), | 51 m_colourRotation(0), |
52 m_minFrequency(10), | 52 m_minFrequency(10), |
53 m_maxFrequency(8000), | 53 m_maxFrequency(8000), |
54 m_initialMaxFrequency(8000), | |
54 m_colourScale(dBColourScale), | 55 m_colourScale(dBColourScale), |
55 m_colourScheme(DefaultColours), | 56 m_colourScheme(DefaultColours), |
56 m_frequencyScale(LinearFrequencyScale), | 57 m_frequencyScale(LinearFrequencyScale), |
57 m_binDisplay(AllBins), | 58 m_binDisplay(AllBins), |
58 m_normalizeColumns(false), | 59 m_normalizeColumns(false), |
64 { | 65 { |
65 if (config == MelodicRange) { | 66 if (config == MelodicRange) { |
66 setWindowSize(8192); | 67 setWindowSize(8192); |
67 setWindowHopLevel(4); | 68 setWindowHopLevel(4); |
68 // setWindowType(ParzenWindow); | 69 // setWindowType(ParzenWindow); |
70 m_initialMaxFrequency = 1000; | |
69 setMaxFrequency(1000); | 71 setMaxFrequency(1000); |
70 setColourScale(LinearColourScale); | 72 setColourScale(LinearColourScale); |
71 } else if (config == MelodicPeaks) { | 73 } else if (config == MelodicPeaks) { |
72 setWindowSize(4096); | 74 setWindowSize(4096); |
73 setWindowHopLevel(5); | 75 setWindowHopLevel(5); |
74 // setWindowType(BlackmanWindow); | 76 // setWindowType(BlackmanWindow); |
77 m_initialMaxFrequency = 2000; | |
75 setMaxFrequency(2000); | 78 setMaxFrequency(2000); |
76 setMinFrequency(40); | 79 setMinFrequency(40); |
77 setFrequencyScale(LogFrequencyScale); | 80 setFrequencyScale(LogFrequencyScale); |
78 setColourScale(MeterColourScale); | 81 setColourScale(MeterColourScale); |
79 setBinDisplay(PeakFrequencies); | 82 setBinDisplay(PeakFrequencies); |
2766 } | 2769 } |
2767 | 2770 |
2768 int | 2771 int |
2769 SpectrogramLayer::getVerticalZoomSteps(int &defaultStep) const | 2772 SpectrogramLayer::getVerticalZoomSteps(int &defaultStep) const |
2770 { | 2773 { |
2774 // Vertical zoom step 0 shows the entire range from DC -> Nyquist | |
2775 // frequency. Step 1 shows 2^(1/4) of the range of step 0, and so | |
2776 // on until the visible range is smaller than the frequency step | |
2777 // between bins at the current fft size. | |
2778 | |
2779 if (!m_model) return 0; | |
2780 | |
2781 float min, max; | |
2782 int sr = m_model->getSampleRate(); | |
2783 min = float(sr) / m_fftSize; | |
2784 max = float(sr) / 2; | |
2785 | |
2786 float dist = max - min; | |
2787 | |
2788 int n = 0; | |
2771 defaultStep = 0; | 2789 defaultStep = 0; |
2772 return 20; //!!! | 2790 float s2 = sqrtf(sqrtf(2)); |
2791 while (dist > min) { | |
2792 if (max >= m_initialMaxFrequency) { | |
2793 defaultStep = n; | |
2794 } | |
2795 ++n; | |
2796 dist /= s2; | |
2797 max = min + dist; | |
2798 } | |
2799 | |
2800 return n; | |
2773 } | 2801 } |
2774 | 2802 |
2775 int | 2803 int |
2776 SpectrogramLayer::getCurrentVerticalZoomStep() const | 2804 SpectrogramLayer::getCurrentVerticalZoomStep() const |
2777 { | 2805 { |
2787 | 2815 |
2788 float mdist = mmax - mmin; | 2816 float mdist = mmax - mmin; |
2789 float ddist = dmax - dmin; | 2817 float ddist = dmax - dmin; |
2790 | 2818 |
2791 int n = 0; | 2819 int n = 0; |
2792 float s2 = sqrtf(2); | 2820 int discard = 0; |
2821 int m = getVerticalZoomSteps(discard); | |
2822 float s2 = sqrtf(sqrtf(2)); | |
2793 while (mdist > ddist) { | 2823 while (mdist > ddist) { |
2794 if (++n > 20) break; | 2824 if (++n > m) break; |
2795 mdist /= s2; | 2825 mdist /= s2; |
2796 } | 2826 } |
2797 | 2827 |
2798 return n; | 2828 return n; |
2799 } | 2829 } |
2812 mmax = float(sr) / 2; | 2842 mmax = float(sr) / 2; |
2813 | 2843 |
2814 float ddist = mmax - mmin; | 2844 float ddist = mmax - mmin; |
2815 | 2845 |
2816 int n = 0; | 2846 int n = 0; |
2817 float s2 = sqrtf(2); | 2847 float s2 = sqrtf(sqrtf(2)); |
2818 while (n < step) { | 2848 while (n < step) { |
2819 ddist /= s2; | 2849 ddist /= s2; |
2820 ++n; | 2850 ++n; |
2821 } | 2851 } |
2822 | 2852 |