~mixxxcontributors/mixxx/advanced_autodj

« back to all changes in this revision

Viewing changes to mixxx/src/analyserwaveform.h

  • Committer: Daniel Schürmann
  • Date: 2013-06-12 23:27:21 UTC
  • mfrom: (3184.1.101 mixxx-trunk)
  • Revision ID: daschuer@mixxx.org-20130612232721-ol6h11m9xbf72d2k
merge -r date:2012-06-26 lp:mixxx

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
//NOTS vrince some test to segment sound, to apply color in the waveform
14
14
//#define TEST_HEAT_MAP
15
15
 
 
16
class EngineObject;
16
17
class EngineFilterButterworth8;
 
18
class EngineFilterIIR;
17
19
class Waveform;
18
20
class AnalysisDao;
19
21
 
20
22
enum FilterIndex { Low = 0, Mid = 1, High = 2, FilterCount = 3};
21
 
enum ChannelIndex { Right = 0, Left = 1, ChannelCount = 2};
 
23
enum ChannelIndex { Left = 0, Right = 1, ChannelCount = 2};
 
24
 
 
25
inline CSAMPLE scaleSignal(CSAMPLE invalue, FilterIndex index = FilterCount) {
 
26
    if (invalue == 0.0) {
 
27
        return 0;
 
28
    } else if (index == Low || index == Mid) {
 
29
        //return pow(invalue, 2 * 0.5);
 
30
        return invalue;
 
31
    } else {
 
32
        return pow(invalue, 2.0f * 0.316f);
 
33
    }
 
34
}
22
35
 
23
36
class WaveformStride {
24
37
    inline void init( int samples) {
25
38
        m_length = samples*2;
26
 
        m_convertionFactor = (float)std::numeric_limits<unsigned char>::max()/(float)samples;
 
39
        m_postScaleConversion = (float)std::numeric_limits<unsigned char>::max();
 
40
        m_conversionFactor = 1.0; //because we are taking a max, not an average any more
 
41
 
 
42
        // This averages over the window. For now we're taking the max-envelope.
 
43
        //m_conversionFactor = 1.0 / samples;
27
44
        reset();
28
45
    }
29
46
 
40
57
    inline void store(WaveformData* data) {
41
58
        for( int i = 0; i < ChannelCount; i++) {
42
59
            WaveformData& datum = *(data + i);
43
 
            datum.filtered.all = (unsigned char)(m_convertionFactor * m_overallData[i]);
44
 
            datum.filtered.low = (unsigned char)(m_convertionFactor * m_filteredData[i][Low]);
45
 
            datum.filtered.mid = (unsigned char)(m_convertionFactor * m_filteredData[i][Mid]);
46
 
            datum.filtered.high = (unsigned char)(m_convertionFactor * m_filteredData[i][High]);
 
60
            datum.filtered.all = static_cast<unsigned char>(math_min(255.0, m_postScaleConversion * scaleSignal(m_conversionFactor * m_overallData[i]) + 0.5));
 
61
            datum.filtered.low = static_cast<unsigned char>(math_min(255.0, m_postScaleConversion * scaleSignal(m_conversionFactor * m_filteredData[i][Low], Low) + 0.5));
 
62
            datum.filtered.mid = static_cast<unsigned char>(math_min(255.0, m_postScaleConversion * scaleSignal(m_conversionFactor * m_filteredData[i][Mid], Mid) + 0.5));
 
63
            datum.filtered.high = static_cast<unsigned char>(math_min(255.0, m_postScaleConversion * scaleSignal(m_conversionFactor * m_filteredData[i][High], High) + 0.5));
47
64
        }
48
65
    }
49
66
 
54
71
    float m_overallData[ChannelCount];
55
72
    float m_filteredData[ChannelCount][FilterCount];
56
73
 
57
 
    float m_convertionFactor;
 
74
    float m_conversionFactor;
 
75
    float m_postScaleConversion;
58
76
 
59
77
  private:
60
78
    friend class AnalyserWaveform;
94
112
    int m_currentStride;
95
113
    int m_currentSummaryStride;
96
114
 
97
 
    EngineFilterButterworth8* m_filter[FilterCount];
 
115
    EngineObject* m_filter[FilterCount];
98
116
    std::vector<float> m_buffers[FilterCount];
99
117
 
100
118
    QTime* m_timer;