Locator


superclass: Object


A class for virtual spatialization in stereo, using delays and amplitude distances.


Class Methods



*new(right_speaker, measurement_distance)

Create a new Locator object where the left speaker is at (0,0) and the

right speaker is at (right_speaker, 0).  right_speaker should be the

distance, in meters, between the two speakers.  measurement_distance

is the minimum y-coordinate for the virtual location of spatialized sounds.



 


Instance Methods


compute_stereo_information(x_coordinate, y_coordinate, amp)

Computes the amplitude and delays for the left and right speaker for a sound

located at (x_coordinate, y_coordinate), behind the speakers.  The

amplitude for the louder speaker is amp adjusted for the distance y_coordinate.

The amplitude for the quieter speaker is reduced based on the difference

in distance between the location and the speakers.  Returns this.


left_amp()

Return the last computed amplitude for the left speaker, or nil if there has

been no computation so far

right_amp()

Return the last computed amplitude for the right speaker, or nil if there has

been no computation so far

left_delay_time()

Return the last computed delay time in seconds for the left speaker, or nil if there has

been no computation so far

right_delay_time()

Return the last computed delay time in seconds for the right speaker, or nil if there has

been no computation so far


make_a_line(number, distance_behind, amp)

Create an array of Locator objects corresponding to number virtual locations, equally 

spaced distance_behind meters behind the speaker locations.  The created Locators

hold delay and amplitude information for each virtual location.

get_stereo_information(x_coordinate, y_coordinate, amp)

Computes the distance, amplitude and delays for the left and right speaker for a sound

located at (x_coordinate, y_coordinate), behind the speakers.  The

amplitude for the louder speaker is amp adjusted for the distance y_coordinate.

The amplitude for the quieter speaker is reduced based on the difference

in distance between the location and the speakers.  Distances are in meters,

time is in seconds.

Returns an array: [left_distance, left_delay_time, left_amp, right_distance,

right_delay_time, right_amp]

(

// create a Locator with the speakers places 3 meters apart

l = Locator.new(3, 0.5);

SynthDef("help-locator", {arg out = 0, freq = 440, delay_time_left, left_amp,

delay_time_right, right_amp;

var ping, env, left, right;

env = EnvGen.kr(Env.perc(0.001, 1, 1, -8), doneAction: 2);

ping  = Klang.ar(`[ [freq, freq * 3/2, freq * 7/5],[0.33, 0.33, 0.33]]) * env;

// put the left channel thru a delay line and adjust the amplitude

left = DelayC.ar(ping, 0.05, delay_time_left, left_amp);

// put the right channel through a delay line and adjust the amplitude

right = DelayC.ar(ping, 0.05, delay_time_right, right_amp);

Out.ar(out, [left, right]);

}).store;

// Move the virtual location around randomly in a 3.0 x 2.5 meter rectangle

// behind the speakers

Pbind (

\freq,   Prand([220, 440, 330], inf),

\instrument, "help-locator",

[\left_distance, 

\left_delay_time, 

\left_amp, 

\right_distance,

\right_delay_time, 

\right_amp],

Pfunc({ l.get_stereo_information((0.5 + 2.5.rand), 

(3.0.rand), 1.0)})

).play

)