annotate src/libSAD/noicegen.c @ 4508:246244ead30e

renamed skin.* to ui_skin.* and moved ui_skinned_widget_draw() to it
author mf0102 <0102@gmx.at>
date Tue, 22 Apr 2008 13:27:32 +0200
parents b0ca963fd965
children bb0638143fc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4232
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
1 #include <stdio.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
2 #include <assert.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
3 #include "../../config.h"
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
4
4233
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
5 #ifdef HAVE_SSE2
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
6 # define SSE2 1
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
7 #endif
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
8
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
9 #ifdef HAVE_ALTIVEC
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
10 # define ALTIVEC 1
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
11 #endif
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
12
4232
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
13 #define MEXP 19937
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
14
4251
1046f9c3174d - compile fix: add extra.mk to Makefile
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4250
diff changeset
15 #include "SFMT.h"
4232
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
16 #include "SFMT.c"
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
17
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
18 #include "noicegen.h"
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
19
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
20 int triangular_dither_noise(int nbits)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
21 {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
22 // parameter nbits : the peak-to-peak amplitude desired (in bits)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
23 // use with nbits set to 2 + nber of bits to be trimmed.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
24 // (because triangular is made from two uniformly distributed processes,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
25 // it starts at 2 bits peak-to-peak amplitude)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
26 // see The Theory of Dithered Quantization by Robert Alexander Wannamaker
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
27 // for complete proof of why that's optimal
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
28
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
29 int v = (gen_rand32() / 2 - gen_rand32() / 2); // in ]-2^31, 2^31[
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
30 //int signe = (v>0) ? 1 : -1;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
31 int P = 1 << (32 - nbits); // the power of 2
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
32 v /= P;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
33 // now v in ]-2^(nbits-1), 2^(nbits-1) [
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
34
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
35 return v;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
36 }
4233
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
37
4256
b0ca963fd965 adaptive scaler added, disabled hard limiter
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4251
diff changeset
38 double triangular_dither_noise_f() {
4233
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
39 // Сonditionally assume we have 16 bits in fractional part
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
40 // Please, check it thoroughly: is this assumption correct in floatin-point arithmetic?
4256
b0ca963fd965 adaptive scaler added, disabled hard limiter
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4251
diff changeset
41 return (double) triangular_dither_noise(17) / 65536.0;
4233
74c6f3d3cf1d it buids successfully :)
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4232
diff changeset
42 }
4234
b293ce14a01a partially works...
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4233
diff changeset
43
b293ce14a01a partially works...
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4233
diff changeset
44 void noicegen_init_rand(uint32_t seed) {
b293ce14a01a partially works...
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4233
diff changeset
45 init_gen_rand(seed);
b293ce14a01a partially works...
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4233
diff changeset
46 }