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