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