diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-12-13 09:39:15 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-12-13 09:39:15 +0100 |
commit | d7b7723c96cdee0be6a5120293ecfde60bd65bdc (patch) | |
tree | 456cbef6b5f19fd056a086c9a6bb5b2f111788e1 /sys/src/cmd/audio | |
parent | a8b02eb198d2c35ea385aaaa962487fbff2bf89b (diff) |
audio/pcmconv: dithering
Diffstat (limited to 'sys/src/cmd/audio')
-rw-r--r-- | sys/src/cmd/audio/pcmconv/pcmconv.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/sys/src/cmd/audio/pcmconv/pcmconv.c b/sys/src/cmd/audio/pcmconv/pcmconv.c index af004e7a0..92f963ac6 100644 --- a/sys/src/cmd/audio/pcmconv/pcmconv.c +++ b/sys/src/cmd/audio/pcmconv/pcmconv.c @@ -141,7 +141,7 @@ filter(Chan *c) } int* -resample(Chan *c, int *x, int *y, ulong count) +resample(Chan *c, int *x, int *y, int count) { ulong e; int i, n; @@ -197,6 +197,20 @@ resample(Chan *c, int *x, int *y, ulong count) } void +dither(int *y, int ibits, int obits, int count) +{ + static ulong prnd; + + if(ibits >= 32 || obits >= ibits) + return; + + while(count--){ + prnd = (prnd*0x19660dL + 0x3c6ef35fL) & 0xffffffffL; + *y++ += ((int)prnd) >> ibits; + } +} + +void siconv(int *dst, uchar *src, int bits, int skip, int count) { int i, v, s, b; @@ -497,6 +511,7 @@ main(int argc, char *argv[]) l -= n; n /= i.framesz; (*iconv)(in, ibuf, i.bits, i.framesz, n); + dither(in, i.bits, o.bits, n); m = resample(&ch[0], in, out, n) - out; if(m < 1){ if(n == 0) @@ -506,6 +521,7 @@ main(int argc, char *argv[]) if(i.channels == o.channels){ for(k=1; k<i.channels; k++){ (*iconv)(in, ibuf + k*((i.bits+7)/8), i.bits, i.framesz, n); + dither(in, i.bits, o.bits, n); resample(&ch[k], in, out, n); if(m > 0) (*oconv)(out, obuf + k*((o.bits+7)/8), o.bits, o.framesz, m); |