Skip to content

Commit

Permalink
added DBAP4.ck panner
Browse files Browse the repository at this point in the history
  • Loading branch information
hoch committed Oct 19, 2012
1 parent a7dabb5 commit ca23bae
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
59 changes: 59 additions & 0 deletions panning/DBAP4.ck
@@ -0,0 +1,59 @@
// @title DBAP4.ck
// @author Hongchan Choi (hongchan@ccrma)
// @desc General purpose panner for 4-channel configuration. Based
// on DBAP (distance based amplitude panning) method.
// @revision 2
// @version chuck-1.3.1.3


class DBAP4
{
// position of speakers: LF, RF, RR, LR
[[-1.0, 1.0], [1.0, 1.0], [1.0, -1.0], [-1.0, -1.0]]
@=> float _spks[][];

// position of source
float _x, _y;

// UGens
UGen @ _source;
Envelope _in;
Envelope _out[4];

// initialization
20::ms => _in.duration;
1.0 => _in.target;
for (0 => int i; i < 4; ++i) {
_in => _out[i] => dac.chan(i);
20::ms => _out[i].duration;
1.0 => _out[i].target;
}

// setSource(): obsolete. will be replace with Chubgraph
fun void setSource(UGen source) {
if (_source != NULL) _source =< _in;
source @=> _source;
_source => _in;
}

// setPosition(): implements simple DBAP. the radius
// of sound is set to 2.0 by default.
fun void setPosition(float x, float y) {
x => _x;
y => _y;
for(0 => int i; i < 4; ++i) {
_spks[i][0] - _x => float dx;
_spks[i][1] - _y => float dy;
dx * dx => dx;
dy * dy => dy;
Math.sqrt(dx + dy) => float dist;
Math.max(0.0, 2.0 - dist) => dist;
dist => _out[i].target;
}
}

// setGain(): set overall gain
fun void setGain(float gain) {
gain => _in.target;
}
}
12 changes: 5 additions & 7 deletions testtones/DacBeeps.ck
Expand Up @@ -16,27 +16,25 @@ SinOsc sine[nChans];

// iterate on each channel
for (0 => int i; i < nChans; ++i) {
// mute it
0.0 => sine[i].gain;
// connect it to a dac channel
sine[i] => dac.chan(i);
}

// beep(): beep once for channel 0, twice for channel 1, etc.
fun void beepChannel(int id) {
id - 1 => int channel;
for (0 => int i; i < id; ++i) {
sine[channel].gain(VOLUME); // unmute
100::ms => now; // stall
0.0 => sine[channel].gain; // mute
100::ms => now; // stall
sine[channel].gain(VOLUME);
100::ms => now;
0.0 => sine[channel].gain;
100::ms => now;
}
}

// create an infinite pattern that rotates around the speakers
while(true) {
for (1 => int i; i <= nChans; ++i) {
beepChannel(i);
500::ms => now; // wait for next beep
500::ms => now;
}
}

0 comments on commit ca23bae

Please sign in to comment.