Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Neat Panner v2018-07-06-A
- // Mono-to-binaural panner by Thomas Howe (thomashowemain@gmail.com)
- // function (run this first to add the global variable)
- (~monoToBinaural = {
- arg monoIn = PinkNoise.ar(0.1),
- rightnessOrAzimuth = 0,
- forwardnessOrDistance = 0,
- layout = 0,
- normalise = 1,
- maximumMultiplier = 3,
- earDistance = 0.00033;
- var rightness = if(layout == 0, rightnessOrAzimuth, rightnessOrAzimuth.sin * forwardnessOrDistance);
- var forwardness = if(layout == 0, forwardnessOrDistance, rightnessOrAzimuth.cos * forwardnessOrDistance);
- var distance = hypot(rightness + [1, -1], forwardness);
- var delay = earDistance * (distance + 1.0001 - ((distance[0] + distance[1]) / 2));
- var mulRaw = (distance + 0.0001) ** -2;
- var mul = if(normalise == 0, mulRaw, (mulRaw / hypot(mulRaw[0], mulRaw[1]))).min(maximumMultiplier);
- DelayN.ar(monoIn, earDistance * 3, delay, mul)
- })
- // examples
- ({ // default values (commented out)
- ~monoToBinaural.value(
- //monoIn: PinkNoise.ar(0.1), // reasonable volume pink noise for testing
- //rightnessOrAzimuth: 0, // distance right from centre of head OR the azimuth in radians
- //forwardnessOrDistance: 0, // distance forward from centre of head OR distance away from centre of head
- //layout: 0, // 0 = rightness and forwardness, anything else = azimuth and distance
- //normalise: 1, // 0 = don't adjust volumes, anything else = keep loudness the same as monoIn
- //maximumMultiplier: 3, // caps the multiplier (at 3 by default, which is +9.54dB) for both channels to prevent deafness
- //earDistance: 0.00033, // internal unit of distance, defined as the middle of head and an ear (half the maximum ITD)
- )
- }.play)
- ({ // just to the left of the left ear, forward a bit
- ~monoToBinaural.value(
- rightnessOrAzimuth: -1.3,
- forwardnessOrDistance: 0.7,
- )
- }.play)
- ({ // mapped to a 16x9 screen
- ~monoToBinaural.value(
- rightnessOrAzimuth: MouseX.kr(-4, 4),
- forwardnessOrDistance: MouseY.kr(0, 4.5),
- )
- }.play)
- ({ // by azimuth and distance, without normalisation
- ~monoToBinaural.value(
- rightnessOrAzimuth: MouseX.kr(-pi/2, pi/2),
- forwardnessOrDistance: MouseY.kr(1, 5, 1), // logarithmic distance, starting at earDistance
- layout: 1,
- normalise: 0, // watch out for that 9.54dB boost at the ear positions
- )
- }.play)
- ({ // SuperCollider's audio input mapped to a 16x9 screen without normalisation
- ~monoToBinaural.value(
- monoIn: (SoundIn.ar([0]) + SoundIn.ar([1])) * (2 ** -0.5), // convert stereo to equal power mono
- rightnessOrAzimuth: MouseX.kr(-2, 2), // with this set to 0,
- forwardnessOrDistance: MouseY.kr(0, 2.25), // and this set to 0, equal loudness to source should be achieved
- normalise: 0,
- )
- }.play)
- ({ // just some silliness
- // samples remaining till new samples remaining time is chosen, minus 2
- var fallerKR = {
- arg min = 1, max = 2;
- var buffer = Buffer.alloc(s, 1);
- var random = round(((WhiteNoise.kr(0.5, 0.5) * (max - min)) + min) * s.sampleRate / s.options.blockSize, 1) - 2;
- var previous = PlayBuf.kr(1, buffer);
- var current = Select.kr(previous < 0, [previous - 1, random]);
- RecordBuf.kr(current, buffer);
- current;
- };
- // picks new point every fallerKR trigger
- var stochasticLine = {
- arg faller = fallerKR.value, min = -1, max = 1;
- var buffer = Buffer.alloc(s, 1);
- var random = TRand.kr(min, max, faller);
- var previous = PlayBuf.kr(1, buffer);
- var current = ((random - previous) / (faller + 2)) + previous;
- RecordBuf.kr(current, buffer);
- current;
- };
- var whineRate = fallerKR.value(0.4, 0.5);
- var whine = stochasticLine.value(whineRate, 850, 880);
- var time = 0.5 ** Sweep.kr(0, 1/30);
- var locationRate = fallerKR.value(4 * time, 5 * time);
- ~monoToBinaural.value(
- monoIn: Saw.ar(whine, 0.005),
- rightnessOrAzimuth: stochasticLine.value(locationRate, -1.1, 1.1),
- forwardnessOrDistance: stochasticLine.value(locationRate, -1.1, 1.1),
- normalise: 0,
- )
- }.play)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement