Mercurial > hg > svcore
comparison base/RangeMapper.cpp @ 241:2b40f83e7627
* Make audio file reader factory try for a reader based on the file's
extension, before trying all readers
* Remove some debug output
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2007 12:15:08 +0000 |
parents | 91fdc752e540 |
children | db8fcd280234 6f6ab834449d |
comparison
equal
deleted
inserted
replaced
240:8133ae938704 | 241:2b40f83e7627 |
---|---|
39 int position = m_minpos + | 39 int position = m_minpos + |
40 lrintf(((value - m_minval) / (m_maxval - m_minval)) | 40 lrintf(((value - m_minval) / (m_maxval - m_minval)) |
41 * (m_maxpos - m_minpos)); | 41 * (m_maxpos - m_minpos)); |
42 if (position < m_minpos) position = m_minpos; | 42 if (position < m_minpos) position = m_minpos; |
43 if (position > m_maxpos) position = m_maxpos; | 43 if (position > m_maxpos) position = m_maxpos; |
44 std::cerr << "LinearRangeMapper::getPositionForValue: " << value << " -> " | 44 // std::cerr << "LinearRangeMapper::getPositionForValue: " << value << " -> " |
45 << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; | 45 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; |
46 return position; | 46 return position; |
47 } | 47 } |
48 | 48 |
49 float | 49 float |
50 LinearRangeMapper::getValueForPosition(int position) const | 50 LinearRangeMapper::getValueForPosition(int position) const |
52 float value = m_minval + | 52 float value = m_minval + |
53 ((float(position - m_minpos) / float(m_maxpos - m_minpos)) | 53 ((float(position - m_minpos) / float(m_maxpos - m_minpos)) |
54 * (m_maxval - m_minval)); | 54 * (m_maxval - m_minval)); |
55 if (value < m_minval) value = m_minval; | 55 if (value < m_minval) value = m_minval; |
56 if (value > m_maxval) value = m_maxval; | 56 if (value > m_maxval) value = m_maxval; |
57 std::cerr << "LinearRangeMapper::getValueForPosition: " << position << " -> " | 57 // std::cerr << "LinearRangeMapper::getValueForPosition: " << position << " -> " |
58 << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; | 58 // << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; |
59 return value; | 59 return value; |
60 } | 60 } |
61 | 61 |
62 LogRangeMapper::LogRangeMapper(int minpos, int maxpos, | 62 LogRangeMapper::LogRangeMapper(int minpos, int maxpos, |
63 float ratio, float minlog, | 63 float ratio, float minlog, |
79 float mapped = m_ratio * log10(value); | 79 float mapped = m_ratio * log10(value); |
80 int position = lrintf(((mapped - m_minlog) / (m_maxlog - m_minlog)) | 80 int position = lrintf(((mapped - m_minlog) / (m_maxlog - m_minlog)) |
81 * (m_maxpos - m_minpos)); | 81 * (m_maxpos - m_minpos)); |
82 if (position < m_minpos) position = m_minpos; | 82 if (position < m_minpos) position = m_minpos; |
83 if (position > m_maxpos) position = m_maxpos; | 83 if (position > m_maxpos) position = m_maxpos; |
84 std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " | 84 // std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " |
85 << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; | 85 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; |
86 return position; | 86 return position; |
87 } | 87 } |
88 | 88 |
89 float | 89 float |
90 LogRangeMapper::getValueForPosition(int position) const | 90 LogRangeMapper::getValueForPosition(int position) const |
91 { | 91 { |
92 float value = powf(10, (position - m_minpos) / m_ratio + m_minlog); | 92 float value = powf(10, (position - m_minpos) / m_ratio + m_minlog); |
93 std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> " | 93 // std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> " |
94 << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; | 94 // << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; |
95 return value; | 95 return value; |
96 } | 96 } |
97 | 97 |