Skip to content

Commit

Permalink
added hash for no-ext random
Browse files Browse the repository at this point in the history
  • Loading branch information
LFSaw committed Jan 26, 2021
1 parent 116f80e commit a0edc20
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 42 deletions.
66 changes: 33 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# faust-sc
*2020, LFSaw ([interaction](http://tai-studio.org) | [music](http://lfsaw.de))*

DSP function definitions for the [FAUST](https://faustdoc.grame.fr/) dsp language inspired by the interface of [SuperCollider](http://supercollider.github.io) functionality.
DSP function definitions for the [FAUST](https://faustdoc.grame.fr/) dsp language inspired by [SuperCollider](http://supercollider.github.io) functionality.


* [scUgens.lib](#scugenslib)
Expand Down Expand Up @@ -96,19 +96,19 @@ sc = import("scUGens.lib")
```
process = sc.hasher(v) : _;
```
See [Hasher](http://doc.sccode.org/Classes/Hasher.html) (SuperCollider reference) for details.
See SuperCollider reference for [Hasher](http://doc.sccode.org/Classes/Hasher.html) for details.

#### impulse
```
process = sc.impulse(freq, phase) : _;
```
See [Impulse](http://doc.sccode.org/Classes/Impulse.html) (SuperCollider reference) for details.
See SuperCollider reference for [Impulse](http://doc.sccode.org/Classes/Impulse.html) for details.

#### lfsaw
```
process = sc.lfsaw(freq, phase) : _;
```
See [LFsaw](http://doc.sccode.org/Classes/LFSaw.html) (SuperCollider reference) for details.
See SuperCollider reference for [LFsaw](http://doc.sccode.org/Classes/LFSaw.html) for details.

#### lfsaw_uni
unipolar `LFSaw`
Expand All @@ -121,31 +121,31 @@ process = sc.lfsaw_uni(freq, phase) : _;
```
process = sc.sinosc(freq, phase)
```
See [SinOsc](http://doc.sccode.org/Classes/SinOsc.html) (SuperCollider reference) for details.
See SuperCollider reference for [SinOsc](http://doc.sccode.org/Classes/SinOsc.html) for details.

#### lfpulse
```
process = sc.lfpulse(freq, width, phase)
```
See [LFPulse](http://doc.sccode.org/Classes/LFPulse.html) (SuperCollider reference) for details.
See SuperCollider reference for [LFPulse](http://doc.sccode.org/Classes/LFPulse.html) for details.

#### lftri
```
process = sc.lftri(freq, phase)
```
See [LFTri](http://doc.sccode.org/Classes/LFTri.html) (SuperCollider reference) for details.
See SuperCollider reference for [LFTri](http://doc.sccode.org/Classes/LFTri.html) for details.

#### pmosc
```
process = sc.sc.pmosc(...);
```
See [PMOsc](http://doc.sccode.org/Classes/PMOsc.html) (SuperCollider reference) for details.
See SuperCollider reference for [PMOsc](http://doc.sccode.org/Classes/PMOsc.html) for details.

#### sinoscfb
```
process = sc.sinoscfb(freq, feedback) : _;
```
See [SinOscFB](http://doc.sccode.org/Classes/SinOscFB.html) (SuperCollider reference) for details.
See SuperCollider reference for [SinOscFB](http://doc.sccode.org/Classes/SinOscFB.html) for details.

#### sinoscfb_p
SinOscFB with additional phase modulation input
Expand All @@ -157,27 +157,27 @@ process = sinoscfb_p(freq, phase, feedback) : _;
```
process = sc.sc.pmosc(...);
```
See [PMOsc](http://doc.sccode.org/Classes/PMOsc.html) (SuperCollider reference) for details.
See SuperCollider reference for [PMOsc](http://doc.sccode.org/Classes/PMOsc.html) for details.

### Noise

#### whitenoise
```
process = sc.whitenoise(amp) : _;
```
See [WhiteNoise](http://doc.sccode.org/Classes/WhiteNoise.html) (SuperCollider reference) for details.
See SuperCollider reference for [WhiteNoise](http://doc.sccode.org/Classes/WhiteNoise.html) for details.

#### pinknoise
```
process = sc.pinknoise(amp) : _;
```
See [PinkNoise](http://doc.sccode.org/Classes/PinkNoise.html) (SuperCollider reference) for details.
See SuperCollider reference for [PinkNoise](http://doc.sccode.org/Classes/PinkNoise.html) for details.

#### dust
```
process = sc.dust(density) : _;
```
See [Dust](http://doc.sccode.org/Classes/Dust.html) (SuperCollider reference) for details.
See SuperCollider reference for [Dust](http://doc.sccode.org/Classes/Dust.html) for details.



Expand All @@ -191,7 +191,7 @@ See [Dust](http://doc.sccode.org/Classes/Dust.html) (SuperCollider reference) fo
```
process = _ : sc.lpf(freq) : _;
```
See [LPF](http://doc.sccode.org/Classes/LPF.html) (SuperCollider reference) for details.
See SuperCollider reference for [LPF](http://doc.sccode.org/Classes/LPF.html) for details.



Expand All @@ -214,7 +214,7 @@ process = sc.mod(a, b);
#### linlin

SC-style linear mapping.
See [linlin](http://doc.sccode.org/Overviews/Methods.html#linlin) (SuperCollider reference) for details.
See SuperCollider reference for [linlin](http://doc.sccode.org/Overviews/Methods.html#linlin) for details.
```
process = _ : sc.linlin(0, 1, 4, 10) : _;
```
Expand All @@ -225,7 +225,7 @@ process = _ : sc.linlin(0, 1, 4, 10) : _;

#### size
SuperCollider `Array:size`.
See [size](http://doc.sccode.org/Overviews/Methods.html#size). (SuperCollider reference) for details.
See SuperCollider reference for [size](http://doc.sccode.org/Overviews/Methods.html#size) for details.


```
Expand All @@ -236,15 +236,15 @@ process = sc.size((a, b, ...)) : N;
#### wrapAt

SuperCollider `Array:wrapAt`.
See [wrapAt](http://doc.sccode.org/Overviews/Methods.html#wrapAt). (SuperCollider reference) for details.
See SuperCollider reference for [wrapAt](http://doc.sccode.org/Overviews/Methods.html#wrapAt) for details.

```
process = sc.wrapAt((a, b, ...), IDX) : _;
```

#### at
SuperCollider `Array:at`.
See [at](http://doc.sccode.org/Overviews/Methods.html#at). (SuperCollider reference) for details.
See SuperCollider reference for [at](http://doc.sccode.org/Overviews/Methods.html#at) for details.


```
Expand All @@ -254,7 +254,7 @@ process = sc.at((a, b, ...), IDX) : _;

#### rotate
SuperCollider `Array:rotate`.
See [rotate](http://doc.sccode.org/Overviews/Methods.html#rotate). (SuperCollider reference) for details.
See SuperCollider reference for [rotate](http://doc.sccode.org/Overviews/Methods.html#rotate) for details.

```
process = sc.rotate(list, AMOUNT) : si.bus(sc.size(list));
Expand All @@ -264,7 +264,7 @@ process = sc.rotate(list, AMOUNT) : si.bus(sc.size(list));
#### drop

SC-style `drop` for lists (drop N left elements).
See [drop](http://doc.sccode.org/Overviews/Methods.html#drop). (SuperCollider reference) for details.
See SuperCollider reference for [drop](http://doc.sccode.org/Overviews/Methods.html#drop) for details.

```
process = sc.drop(list, N) : si.bus(sc.size(list)-N);
Expand All @@ -275,7 +275,7 @@ process = sc.drop(list, N) : si.bus(sc.size(list)-N);
#### keep

SC-style `keep` for lists (keep N left elements).
See [keep](http://doc.sccode.org/Overviews/Methods.html#keep). (SuperCollider reference) for details.
See SuperCollider reference for [keep](http://doc.sccode.org/Overviews/Methods.html#keep) for details.

```
process = sc.keep(list, N) : si.bus(N);
Expand All @@ -285,7 +285,7 @@ process = sc.keep(list, N) : si.bus(N);
#### reverse

SC-style `reverse` for lists (reverse N left elements).
See [reverse](http://doc.sccode.org/Overviews/Methods.html#reverse). (SuperCollider reference) for details.
See SuperCollider reference for [reverse](http://doc.sccode.org/Overviews/Methods.html#reverse) for details.

```
process = sc.reverse(list) : si.bus(sc.size(list));
Expand All @@ -299,7 +299,7 @@ process = sc.reverse(list) : si.bus(sc.size(list));
#### wrap2

SC-style `wrap2` a signal.
See [wrap2](http://doc.sccode.org/Overviews/Methods.html#wrap2) (SuperCollider reference) for details.
See SuperCollider reference for [wrap2](http://doc.sccode.org/Overviews/Methods.html#wrap2) for details.

```
process = _ : sc.wrap2(hi) : _;
Expand All @@ -309,7 +309,7 @@ process = _ : sc.wrap2(hi) : _;
#### wrap

SC-style `wrap` a signal.
See [wrap](http://doc.sccode.org/Overviews/Methods.html#wrap) (SuperCollider reference) for details.
See SuperCollider reference for [wrap](http://doc.sccode.org/Overviews/Methods.html#wrap) for details.

```
process = _ : sc.wrap(lo, hi) : _;
Expand All @@ -319,7 +319,7 @@ process = _ : sc.wrap(lo, hi) : _;
#### clip2

SC-style `clip2` a signal.
See [clip2](http://doc.sccode.org/Overviews/Methods.html#clip2) (SuperCollider reference) for details.
See SuperCollider reference for [clip2](http://doc.sccode.org/Overviews/Methods.html#clip2) for details.

```
process = _ : sc.clip2(hi) : _;
Expand All @@ -329,7 +329,7 @@ process = _ : sc.clip2(hi) : _;
#### clip

SC-style `clip` a signal.
See [clip](http://doc.sccode.org/Overviews/Methods.html#clip) (SuperCollider reference) for details.
See SuperCollider reference for [clip](http://doc.sccode.org/Overviews/Methods.html#clip) for details.


```
Expand All @@ -340,7 +340,7 @@ process = _ : sc.clip(lo, hi) : _;
#### fold

SC-style `fold` a signal.
See [fold](http://doc.sccode.org/Overviews/Methods.html#fold) (SuperCollider reference) for details.
See SuperCollider reference for [fold](http://doc.sccode.org/Overviews/Methods.html#fold) for details.

```
process = _ : sc.fold(lo, hi) : _;
Expand All @@ -350,7 +350,7 @@ process = _ : sc.fold(lo, hi) : _;
#### fold2

SC-style `fold2` a signal.
See [fold2](http://doc.sccode.org/Overviews/Methods.html#fold2) (SuperCollider reference) for details.
See SuperCollider reference for [fold2](http://doc.sccode.org/Overviews/Methods.html#fold2) for details.

```
process = _ : sc.fold2(hi) : _;
Expand All @@ -364,22 +364,22 @@ process = _ : sc.fold2(hi) : _;
#### trig_1

SC-style `Trig` with 1-sample duration .
See [Trig](http://doc.sccode.org/Classes/Trig.html) (SuperCollider reference) for details.
See SuperCollider reference for [Trig](http://doc.sccode.org/Classes/Trig.html) for details.

#### trig1_1

SC-style `Trig1` with 1-sample duration.
See [Trig1](http://doc.sccode.org/Classes/Trig1.html) (SuperCollider reference) for details.
See SuperCollider reference for [Trig1](http://doc.sccode.org/Classes/Trig1.html) for details.

#### latch

SC-style `Latch`.
See [Latch](http://doc.sccode.org/Classes/Latch.html) (SuperCollider reference) for details.
See SuperCollider reference for [Latch](http://doc.sccode.org/Classes/Latch.html) for details.

#### gate

SC-style `Gate`.
See [Gate](http://doc.sccode.org/Classes/Gate.html) (SuperCollider reference) for details.
See SuperCollider reference for [Gate](http://doc.sccode.org/Classes/Gate.html) for details.



Expand All @@ -388,7 +388,7 @@ See [Gate](http://doc.sccode.org/Classes/Gate.html) (SuperCollider reference) fo
#### demand_1

an attempt at `Demand-like functionality`
See [Demand](http://doc.sccode.org/Classes/Demand.html) (SuperCollider reference) for details.
See SuperCollider reference for [Demand](http://doc.sccode.org/Classes/Demand.html) for details.

```
process = _ : sc.demand_1(f) : _;
Expand Down
11 changes: 6 additions & 5 deletions include/scUGens.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdint.h>
// #include <bitset>
// #include <string>
// #include <iostream>
Expand Down Expand Up @@ -42,13 +43,13 @@ int bitHash( int val) {
}

float hasher (float val) {
int32_t z = *(uint32*)&val; // direct cast
int32_t z = *(uint32_t*)&val; // direct cast

union {
float f;
int i;
} u;
u.i = 0x40000000 | ((uint32)bitHash(z) >> 9);
u.i = 0x40000000 | ((uint32_t)bitHash(z) >> 9);
return (u.f - 3.f);
}

Expand Down Expand Up @@ -78,9 +79,9 @@ int bit_rightShift(int a, int b) {
}

// trand(int s1, int s2, int s3) {
// s1 = ((s1 & (uint32)-2) << 12) ^ (((s1 << 13) ^ s1) >> 19);
// s2 = ((s2 & (uint32)-8) << 4) ^ (((s2 << 2) ^ s2) >> 25);
// s3 = ((s3 & (uint32)-16) << 17) ^ (((s3 << 3) ^ s3) >> 11);
// s1 = ((s1 & (uint32_t)-2) << 12) ^ (((s1 << 13) ^ s1) >> 19);
// s2 = ((s2 & (uint32_t)-8) << 4) ^ (((s2 << 2) ^ s2) >> 25);
// s3 = ((s3 & (uint32_t)-16) << 17) ^ (((s3 << 3) ^ s3) >> 11);

// return s1 ^ s2 ^ s3;
// }
Expand Down
32 changes: 31 additions & 1 deletion lib/taiRand-noExt.lib
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,41 @@ declare author "LFSaw";
declare copyright "MIT";

import("stdfaust.lib");
import("taiUtils.lib");
lf = library("taiStudio.lib");
sc = library("scUGens.lib");


IMAX = 2147483647;
UMAX = -1;
B31 = 1073741824; // 0x40000000 == 2bin01000000000000000000000000000000
not(v) = xor(v, UMAX);
l_shift (v, n) = v << n;

r_shift(v, 0) = v;
r_shift(v, n) = r_shift_a(ma.signum(v), v, n) with {
// r_shift_a( 1, v, n ) = v >> n;
// r_shift_a( -1, v, n ) = ((v & IMAX) >> n) | (1 << (31 - n));
r_shift_a ( s, v, n ) = select2(s > 0, v >>n, ((v & IMAX) >> n) | (1 << (31 - n)));

};


bitHash(val) = a6 with {
a1 = val + (l_shift(val, 15) : not);
a2 = xor(a1, r_shift(a1, 10));
a3 = a2 + l_shift(a2, 3);
a4 = xor(a3, r_shift(a3, 6));
a5 = a4 + (l_shift(a4, 11) : not);
a6 = xor(a5, r_shift(a5, 16));
};

// expects normed input (-1..1)
// outputs [0, 1]
// TODO: add mod?
hasher_n(v) = bitHash(r_int(v * (IMAX-1))) / IMAX with {
r_int(x) = ba.if(x < 0, int(x - .5), int(x + .5));
};

//---------------------------------`(rnd.)taus_rand`---------------------------------------
// generates random integer values in the range [0, 2147483647] at sample rate
// based on JMC's implementation of the
Expand Down
5 changes: 2 additions & 3 deletions lib/taiRand.lib
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ declare author "LFSaw";
declare copyright "MIT";

import("stdfaust.lib");
lfutil = library("taiUtils.lib");
lf = library("taiStudio.lib");
sc = library("scUGens.lib");

Expand Down Expand Up @@ -70,7 +69,7 @@ taus_rand(s1, s2, s3) = rgen(s1, s2, s3) ~ si.bus(3) : (_ xor _ xor _) with {
rgen_1(-16, 17, 3, 11);

// last `&` ensures values between [2r0, 2r01111111111111111111111111111111]
rgen_1(a, b, c, d, s) = (lfutil.left_shift((s & a), b)) xor lfutil.right_shift( (lfutil.left_shift(s, c) xor s), d) : _ & 2147483647;
rgen_1(a, b, c, d, s) = (lf.left_shift((s & a), b)) xor lf.right_shift( (lf.left_shift(s, c) xor s), d) : _ & 2147483647;
};


Expand Down Expand Up @@ -249,6 +248,6 @@ irrand(seed, r_min, r_max) = int(rrand(seed, r_min -1, r_max + 1));
// rgen_1(-16, 17, 3, 11);

// // last `&` ensures values between [2r0, 2r01111111111111111111111111111111]
// rgen_1(a, b, c, d, s) = (lfutil.left_shift((s & a), b)) xor lfutil.right_shift( (lfutil.left_shift(s, c) xor s), d) : _ & 2147483647;
// rgen_1(a, b, c, d, s) = (lf.left_shift((s & a), b)) xor lf.right_shift( (lf.left_shift(s, c) xor s), d) : _ & 2147483647;
// };

0 comments on commit a0edc20

Please sign in to comment.