comparison data/model/RangeSummarisableTimeValueModel.h @ 410:9c7ebf2cd956

* Halve space requirements for range (waveform peak) caches
author Chris Cannam
date Fri, 16 May 2008 13:27:07 +0000
parents 166c22eff678
children 8c5b0eec6fe9
comparison
equal deleted inserted replaced
409:6075c90744d4 410:9c7ebf2cd956
33 Q_OBJECT 33 Q_OBJECT
34 34
35 public: 35 public:
36 RangeSummarisableTimeValueModel() { } 36 RangeSummarisableTimeValueModel() { }
37 37
38 struct Range 38 #define RANGE_USE_SHORT 1
39 #ifdef RANGE_USE_SHORT
40 class Range
39 { 41 {
40 float min; 42 public:
41 float max;
42 float absmean;
43 Range() : 43 Range() :
44 min(0.f), max(0.f), absmean(0.f) { } 44 m_min(0), m_max(0), m_absmean(0) { }
45 Range(const Range &r) : 45 Range(const Range &r) :
46 min(r.min), max(r.max), absmean(r.absmean) { } 46 m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
47 Range(float min_, float max_, float absmean_) : 47 Range(float min, float max, float absmean)
48 min(min_), max(max_), absmean(absmean_) { } 48 { setMin(min); setMax(max); setAbsmean(absmean); }
49
50 float min() const { return i2f(m_min); }
51 float max() const { return i2f(m_max); }
52 float absmean() const { return i2f(m_absmean); }
53
54 void setMin(float min) { m_min = f2i(min); }
55 void setMax(float max) { m_max = f2i(max); }
56 void setAbsmean(float absmean) { m_absmean = f2i(absmean); }
57
58 private:
59 static inline int16_t f2i(float f) {
60 if (f > 1.f) f = 1.f;
61 if (f < -1.f) f = -1.f;
62 return int16_t(f * 32767.f);
63 }
64 static inline float i2f(int16_t i) {
65 return float(i) / 32767.f;
66 }
67
68 int16_t m_min;
69 int16_t m_max;
70 int16_t m_absmean;
49 }; 71 };
72 #else
73 class Range
74 {
75 public:
76 Range() :
77 m_min(0.f), m_max(0.f), m_absmean(0.f) { }
78 Range(const Range &r) :
79 m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
80 Range(float min, float max, float absmean) :
81 m_min(min), m_max(max), m_absmean(absmean) { }
82
83 float min() const { return m_min; }
84 float max() const { return m_max; }
85 float absmean() const { return m_absmean; }
86
87 void setMin(float min) { m_min = min; }
88 void setMax(float max) { m_max = max; }
89 void setAbsmean(float absmean) { m_absmean = absmean; }
90
91 private:
92 float m_min;
93 float m_max;
94 float m_absmean;
95 };
96 #endif
50 97
51 typedef std::vector<Range> RangeBlock; 98 typedef std::vector<Range> RangeBlock;
52 99
53 /** 100 /**
54 * Return ranges from the given start frame, corresponding to the 101 * Return ranges from the given start frame, corresponding to the