summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/portaudio/src/common/pa_dither.c
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/portaudio/src/common/pa_dither.c')
-rw-r--r--3rdparty/portaudio/src/common/pa_dither.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/3rdparty/portaudio/src/common/pa_dither.c b/3rdparty/portaudio/src/common/pa_dither.c
index 140e480afbc..0d1666a7741 100644
--- a/3rdparty/portaudio/src/common/pa_dither.c
+++ b/3rdparty/portaudio/src/common/pa_dither.c
@@ -26,13 +26,13 @@
*/
/*
- * The text above constitutes the entire PortAudio license; however,
+ * The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
- * they can be incorporated into the canonical version. It is also
- * requested that these non-binding requests be included along with the
+ * they can be incorporated into the canonical version. It is also
+ * requested that these non-binding requests be included along with the
* license above.
*/
@@ -72,10 +72,10 @@ PaInt32 PaUtil_Generate16BitTriangularDither( PaUtilTriangularDitherGenerator *s
/* Generate triangular distribution about 0.
* Shift before adding to prevent overflow which would skew the distribution.
- * Also shift an extra bit for the high pass filter.
+ * Also shift an extra bit for the high pass filter.
*/
#define DITHER_SHIFT_ ((sizeof(PaInt32)*8 - PA_DITHER_BITS_) + 1)
-
+
current = (((PaInt32)state->randSeed1)>>DITHER_SHIFT_) +
(((PaInt32)state->randSeed2)>>DITHER_SHIFT_);
@@ -100,7 +100,7 @@ float PaUtil_GenerateFloatTriangularDither( PaUtilTriangularDitherGenerator *sta
/* Generate triangular distribution about 0.
* Shift before adding to prevent overflow which would skew the distribution.
- * Also shift an extra bit for the high pass filter.
+ * Also shift an extra bit for the high pass filter.
*/
current = (((PaInt32)state->randSeed1)>>DITHER_SHIFT_) +
(((PaInt32)state->randSeed2)>>DITHER_SHIFT_);
@@ -137,7 +137,7 @@ things like this: r3=(r1 & 0x7F)<<8; instead of calling rand() again.
float s1, s2; //error feedback buffers
float s = 0.5f; //set to 0.0f for no noise shaping
float w = pow(2.0,bits-1); //word length (usually bits=16)
- float wi= 1.0f/w;
+ float wi= 1.0f/w;
float d = wi / RAND_MAX; //dither amplitude (2 lsb)
float o = wi * 0.5f; //remove dc offset
float in, tmp;
@@ -148,19 +148,19 @@ things like this: r3=(r1 & 0x7F)<<8; instead of calling rand() again.
r2=r1; //can make HP-TRI dither by
r1=rand(); //subtracting previous rand()
-
+
in += s * (s1 + s1 - s2); //error feedback
- tmp = in + o + d * (float)(r1 - r2); //dc offset and dither
-
+ tmp = in + o + d * (float)(r1 - r2); //dc offset and dither
+
out = (int)(w * tmp); //truncate downwards
if(tmp<0.0f) out--; //this is faster than floor()
- s2 = s1;
+ s2 = s1;
s1 = in - wi * (float)out; //error
---
+--
paul.kellett@maxim.abel.co.uk
http://www.maxim.abel.co.uk
*/
@@ -172,7 +172,7 @@ http://www.maxim.abel.co.uk
Type : First order error feedforward dithering code
References : Posted by Jon Watte
-Notes :
+Notes :
This is about as simple a dithering algorithm as you can implement, but it's
likely to sound better than just truncating to N bits.
@@ -183,36 +183,36 @@ and integer SIMD type instructions, or CMOV.
Last, if sound quality is paramount (such as when going from > 16 bits to 16
bits) you probably want to use a higher-order dither function found elsewhere
-on this site.
-
-
-Code :
-// This code will down-convert and dither a 16-bit signed short
-// mono signal into an 8-bit unsigned char signal, using a first
-// order forward-feeding error term dither.
-
-#define uchar unsigned char
-
-void dither_one_channel_16_to_8( short * input, uchar * output, int count, int * memory )
-{
- int m = *memory;
- while( count-- > 0 ) {
- int i = *input++;
- i += m;
- int j = i + 32768 - 128;
- uchar o;
- if( j < 0 ) {
- o = 0;
- }
- else if( j > 65535 ) {
- o = 255;
- }
- else {
- o = (uchar)((j>>8)&0xff);
- }
- m = ((j-32768+128)-i);
- *output++ = o;
- }
- *memory = m;
-}
+on this site.
+
+
+Code :
+// This code will down-convert and dither a 16-bit signed short
+// mono signal into an 8-bit unsigned char signal, using a first
+// order forward-feeding error term dither.
+
+#define uchar unsigned char
+
+void dither_one_channel_16_to_8( short * input, uchar * output, int count, int * memory )
+{
+ int m = *memory;
+ while( count-- > 0 ) {
+ int i = *input++;
+ i += m;
+ int j = i + 32768 - 128;
+ uchar o;
+ if( j < 0 ) {
+ o = 0;
+ }
+ else if( j > 65535 ) {
+ o = 255;
+ }
+ else {
+ o = (uchar)((j>>8)&0xff);
+ }
+ m = ((j-32768+128)-i);
+ *output++ = o;
+ }
+ *memory = m;
+}
*/