MythTV  master
videovisualdefs.h
Go to the documentation of this file.
1 #ifndef VIDEOVISUAL_DEFS_H
2 #define VIDEOVISUAL_DEFS_H
3 
4 #include <cmath>
5 
6 class LogScale
7 {
8  public:
9  explicit LogScale(int maxscale = 0, int maxrange = 0)
10  {
11  setMax(maxscale, maxrange);
12  }
13 
15  {
16  delete [] m_indices;
17  }
18 
19  int scale() const { return m_s; }
20  int range() const { return m_r; }
21 
22  void setMax(int maxscale, int maxrange)
23  {
24  if (maxscale == 0 || maxrange == 0)
25  return;
26 
27  m_s = maxscale;
28  m_r = maxrange;
29 
30  delete [] m_indices;
31 
32  auto domain = (long double) maxscale;
33  auto range = (long double) maxrange;
34  long double x = 1.0;
35  long double dx = 1.0;
36  long double e4 = 1.0E-8;
37 
38  m_indices = new int[maxrange];
39  for (int i = 0; i < maxrange; i++)
40  m_indices[i] = 0;
41 
42  // initialize log scale
43  for (uint i = 0; i < 10000 && (std::abs(dx) > e4); i++)
44  {
45  long double t = std::log((domain + x) / x);
46  long double y = (x * t) - range;
47  long double yy = t - (domain / (x + domain));
48  dx = y / yy;
49  x -= dx;
50  }
51 
52  double alpha = x;
53  for (int i = 1; i < (int) domain; i++)
54  {
55  int scaled = (int) floor(0.5 + (alpha * log((double(i) + alpha) / alpha)));
56  if (scaled < 1)
57  scaled = 1;
58  if (m_indices[scaled - 1] < i)
59  m_indices[scaled - 1] = i;
60  }
61  }
62 
63  int operator[](int index) const
64  {
65  return m_indices[index];
66  }
67 
68 
69  private:
70  int *m_indices {nullptr};
71  int m_s {0};
72  int m_r {0};
73 };
74 
75 static inline void stereo16_from_stereopcm8(short *l,
76  short *r,
77  const uchar *c,
78  long cnt)
79 {
80  while (cnt >= 4L)
81  {
82  l[0] = c[0];
83  r[0] = c[1];
84  l[1] = c[2];
85  r[1] = c[3];
86  l[2] = c[4];
87  r[2] = c[5];
88  l[3] = c[6];
89  r[3] = c[7];
90  l += 4;
91  r += 4;
92  c += 8;
93  cnt -= 4L;
94  }
95 
96  if (cnt > 0L)
97  {
98  l[0] = c[0];
99  r[0] = c[1];
100  if (cnt > 1L)
101  {
102  l[1] = c[2];
103  r[1] = c[3];
104  if (cnt > 2L)
105  {
106  l[2] = c[4];
107  r[2] = c[5];
108  }
109  }
110  }
111 }
112 
113 static inline void stereo16_from_stereopcm16(short *l,
114  short *r,
115  const short *s,
116  long cnt)
117 {
118  while (cnt >= 4L)
119  {
120  l[0] = s[0];
121  r[0] = s[1];
122  l[1] = s[2];
123  r[1] = s[3];
124  l[2] = s[4];
125  r[2] = s[5];
126  l[3] = s[6];
127  r[3] = s[7];
128  l += 4;
129  r += 4;
130  s += 8;
131  cnt -= 4L;
132  }
133 
134  if (cnt > 0L)
135  {
136  l[0] = s[0];
137  r[0] = s[1];
138  if (cnt > 1L)
139  {
140  l[1] = s[2];
141  r[1] = s[3];
142  if (cnt > 2L)
143  {
144  l[2] = s[4];
145  r[2] = s[5];
146  }
147  }
148  }
149 }
150 
151 static inline void mono16_from_monopcm8(short *l,
152  const uchar *c,
153  long cnt)
154 {
155  while (cnt >= 4L)
156  {
157  l[0] = c[0];
158  l[1] = c[1];
159  l[2] = c[2];
160  l[3] = c[3];
161  l += 4;
162  c += 4;
163  cnt -= 4L;
164  }
165 
166  if (cnt > 0L)
167  {
168  l[0] = c[0];
169  if (cnt > 1L)
170  {
171  l[1] = c[1];
172  if (cnt > 2L)
173  {
174  l[2] = c[2];
175  }
176  }
177  }
178 }
179 
180 static inline void mono16_from_monopcm16(short *l,
181  const short *s,
182  long cnt)
183 {
184  while (cnt >= 4L)
185  {
186  l[0] = s[0];
187  l[1] = s[1];
188  l[2] = s[2];
189  l[3] = s[3];
190  l += 4;
191  s += 4;
192  cnt -= 4L;
193  }
194 
195  if (cnt > 0L)
196  {
197  l[0] = s[0];
198  if (cnt > 1L)
199  {
200  l[1] = s[1];
201  if (cnt > 2L)
202  {
203  l[2] = s[2];
204  }
205  }
206  }
207 }
208 
209 #ifdef FFTW3_SUPPORT
210 
211 #include <complex>
212 extern "C" {
213 #include <fftw3.h>
214 #define myth_fftw_float double /* need to use different plan function to change */
215 #define fftw_real myth_fftw_float
216 #define myth_fftw_complex std::complex<myth_fftw_float>
217 #if (myth_fftw_float == double)
218 #define myth_fftw_complex_cast fftw_complex
219 #elif (myth_fftw_float == float)
220 #define myth_fftw_complex_cast fftwf_complex
221 #endif
222 }
223 
224 static inline void fast_short_set(short *p,
225  short v,
226  long c)
227 {
228  while (c >= 4L) {
229  p[0] = v;
230  p[1] = v;
231  p[2] = v;
232  p[3] = v;
233  p += 4;
234  c -= 4L;
235  }
236 
237  if (c > 0L) {
238  p[0] = v;
239  if (c > 1L) {
240  p[1] = v;
241  if (c > 2L) {
242  p[2] = v;
243  }
244  }
245  }
246 }
247 
248 static inline void fast_real_set_from_short(fftw_real *d,
249  const short *s,
250  long c)
251 {
252  while (c >= 4L) {
253  d[0] = fftw_real(s[0]);
254  d[1] = fftw_real(s[1]);
255  d[2] = fftw_real(s[2]);
256  d[3] = fftw_real(s[3]);
257  d += 4;
258  s += 4;
259  c -= 4L;
260  }
261 
262  if (c > 0L) {
263  d[0] = fftw_real(s[0]);
264  if (c > 1L) {
265  d[1] = fftw_real(s[1]);
266  if (c > 2L) {
267  d[2] = fftw_real(s[2]);
268  }
269  }
270  }
271 }
272 
273 static inline void fast_reals_set(fftw_real *p1,
274  fftw_real *p2,
275  fftw_real v,
276  long c)
277 {
278  while (c >= 4L) {
279  p1[0] = v;
280  p1[1] = v;
281  p1[2] = v;
282  p1[3] = v;
283  p2[0] = v;
284  p2[1] = v;
285  p2[2] = v;
286  p2[3] = v;
287  p1 += 4;
288  p2 += 4;
289  c -= 4L;
290  }
291 
292  if (c > 0L) {
293  p1[0] = v;
294  p2[0] = v;
295  if (c > 1L) {
296  p1[1] = v;
297  p2[1] = v;
298  if (c > 2L) {
299  p1[2] = v;
300  p2[2] = v;
301  }
302  }
303  }
304 }
305 
306 #endif // FFTW3_SUPPORT
307 #endif // VIDEOVISUAL_DEFS_H
mono16_from_monopcm8
static void mono16_from_monopcm8(short *l, const uchar *c, long cnt)
Definition: videovisualdefs.h:151
LogScale::m_indices
int * m_indices
Definition: videovisualdefs.h:70
LogScale::operator[]
int operator[](int index) const
Definition: videovisualdefs.h:63
d
static const uint16_t * d
Definition: iso6937tables.cpp:1025
LogScale::m_r
int m_r
Definition: videovisualdefs.h:72
LogScale::LogScale
LogScale(int maxscale=0, int maxrange=0)
Definition: videovisualdefs.h:9
mono16_from_monopcm16
static void mono16_from_monopcm16(short *l, const short *s, long cnt)
Definition: videovisualdefs.h:180
hardwareprofile.config.p
p
Definition: config.py:33
hardwareprofile.i18n.t
t
Definition: i18n.py:36
LogScale::range
int range() const
Definition: videovisualdefs.h:20
p2
static guint32 * p2
Definition: goom_core.cpp:30
stereo16_from_stereopcm16
static void stereo16_from_stereopcm16(short *l, short *r, const short *s, long cnt)
Definition: videovisualdefs.h:113
LogScale::setMax
void setMax(int maxscale, int maxrange)
Definition: videovisualdefs.h:22
LogScale::scale
int scale() const
Definition: videovisualdefs.h:19
uint
unsigned int uint
Definition: compat.h:140
LogScale::m_s
int m_s
Definition: videovisualdefs.h:71
p1
static guint32 * p1
Definition: goom_core.cpp:30
LogScale::~LogScale
~LogScale()
Definition: videovisualdefs.h:14
stereo16_from_stereopcm8
static void stereo16_from_stereopcm8(short *l, short *r, const uchar *c, long cnt)
Definition: videovisualdefs.h:75
common.utilities.log
def log(debug, txt)
Definition: utilities.py:7
LogScale
Definition: videovisualdefs.h:6