hello there,
i am working on a pd patch for panning sound on a multispeaker setting using a usb-joystick. i am using the xjimmies library for dealing with the spatialsation. i also use the hid object joystick to the values on the x and y axis. currently i am struggling with the maths of it all.
more in detail this means that the xjimmies library gives me the opportunity to controll the sound distribution on a horizontal slider. the slider outputs the values 0-360, representing the degress of a circle. my difficulties is how to match up the x and y output values of the joystick. my approach is to use angle the beween the x and the y axis, sending both values to an atan2 object. before that i extend their range from 0...1 to -1..1 i understand that atan2 outputs radiants and not degrees. if i divide atan2's output by pi and then multiply it with 180 the results are not at all, what i imagine them to be,. all i am trying to achieve is to translate the circular motion on the joystick into space.. any ideas what i am doing wrong ? (i apologize for not putting the objects in brackets, these dont live on my keyboard)
best regards
alexandre r. decoupigny
alexandre r. decoupigny wrote:
i understand that atan2 outputs radiants and not degrees. if i divide atan2's output by pi and then multiply it with 180 the results are not at all, what i imagine them to be,.
hmm...you are not really giving loads of information away... first of all: what do you expect and what do you get and how are the values related to the input? (some numbers might be really really helpful)
(i apologize for not putting the objects in brackets, these dont live on my keyboard)
but how do you create [objects] without brackets ;-)
mfg.asdr IOhannes
hmm...you are not really giving loads of information away... first of all: what do you expect and what do you get and how are the values related to the input? (some numbers might be really really helpful)
sorry abou that.. dont have any number example in the top of my head.. what i know is that [joystick] outputs numbers between zero and one on two outlets (x axis and y axis). now i wonder how to put these numbers together with a horizontal slider that represents a circle. this horizontal slider outputs values from 0-360 each representing a point on a circle. i dont know if i made my problem any clearer..
(i apologize for not putting the objects in brackets, these dont live on my keyboard)
but how do you create [objects] without brackets ;-)
just like that: [objects] ; )
greetings alexandre
mfg.asdr IOhannes
Hallo, alexandre r. decoupigny hat gesagt: // alexandre r. decoupigny wrote:
sorry abou that.. dont have any number example in the top of my head.. what i know is that [joystick] outputs numbers between zero and one on two outlets (x axis and y axis). now i wonder how to put these numbers together with a horizontal slider that represents a circle. this horizontal slider outputs values from 0-360 each representing a point on a circle. i dont know if i made my problem any clearer..
Lets first summarize where you are already:
You could think of the Joystick as drawing a circle. If you scale both outlets of the joystick to go from -1 to 1 you would basically have a unit circle described by the Joystick's movement. Scaling from (0,1) to (-1,1) is easily made with x*2-1 rsp. y*2-1
Now you can get the tangent of the angle in a joystick's position by just divinging opposite and adjacent sides of the triangle made by the angle, or in joystick coordinates this is: y/x=tan(phi) ==> phi=atan(y/x)
In Pd you use [atan2] for this and according to the help-patch this works like this:
"The arc tangent takes two forms. The atan2 version takes an (x, y) pair and gives you an output between -pi and pi."
Which is an angle in radians!
So that's where you are: You want to map a range (-pi,pi) to a range (0,360). It's actually easy as well: Assume z=atan2(x,y), range (-pi,pi)
z/pi will be in a range (-1,1) then.
180*z/pi will be in (-180,180) (this is what rad2deg.pd from zexy (?) gives you.
180 + 180*z/pi will be in (0,360)
Done.
Now what is left is how to get PI? I just use [expr 4*atan(1)] normally. I have it in an abstraction called [M_PI].
Frank Barknecht _ ______footils.org_ __goto10.org__
On Oct 23, 2006, at 2:06 PM, alexandre r. decoupigny wrote:
hmm...you are not really giving loads of information away... first of all: what do you expect and what do you get and how are the values related to the input? (some numbers might be really really
helpful)sorry abou that.. dont have any number example in the top of my head.. what i know is that [joystick] outputs numbers between zero and
one on two outlets (x axis and y axis). now i wonder how to put these numbers
together with a horizontal slider that represents a circle. this horizontal slider outputs values from 0-360 each representing a point on a circle. i dont know if i made my problem any clearer..
You might be interested in [mapping/polar] which will convert your
x,y coords to polar coords (angle, radius). You could use the angle
for the panning location, and the radius for some kind of distance
algorithm with reverb or something.
.hc
(i apologize for not putting the objects in brackets, these dont
live on
my keyboard)
but how do you create [objects] without brackets ;-)
just like that: [objects] ; )
greetings alexandre
mfg.asdr IOhannes
-- alexandre r. decoupigny
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/ listinfo/pd-list
News is what people want to keep hidden and everything else is
publicity. - Bill Moyers
You might be interested in [mapping/polar] which will convert your x,y coords to polar coords (angle, radius). You could use the angle for the panning location, and the radius for some kind of distance algorithm with reverb or something.
.hc
thanks for that suggestion : ) yes i am indeed interested..sounds fab.. are these externals ? what library do they refer to ? .. i tried to make a [mapping] and then a [polar] and then a [mapping/polar] and it did not work.. im using PD extended version.
alexandre
On Nov 2, 2006, at 4:16 AM, alexandre r. decoupigny wrote:
You might be interested in [mapping/polar] which will convert your x,y coords to polar coords (angle, radius). You could use the angle for the panning location, and the radius for some kind of distance algorithm with reverb or something.
.hc
thanks for that suggestion : ) yes i am indeed interested..sounds
fab.. are these externals ? what library do they refer to ? .. i
tried to make a [mapping] and then a [polar] and then a [mapping/ polar] and it did not work.. im using PD extended version.
[polar] is a object written in Pd that's included in the mapping
library. The mapping library is included in recent test builds and
nightly builds.
.hc
As we enjoy great advantages from inventions of others, we should be
glad of an opportunity to serve others by any invention of ours; and
this we should do freely and generously. - Benjamin Franklin
Hallo!
all i am trying to achieve is to translate the circular motion on the joystick into space.. any ideas what i am doing wrong ?
I would suggest you to use the vbap (vector based amplitude panning) external, which does exactly what you are trying to achive ...
LG Georg
On 23/10/06, Georg Holzmann grhPD@gmx.at wrote:
Hallo!
all i am trying to achieve is to translate the circular motion on the joystick into space.. any ideas what i am doing wrong ?
I would suggest you to use the vbap (vector based amplitude panning) external, which does exactly what you are trying to achive ...
LG Georg
just checking it out .. thanks
alexandre
Howdy all,
Georg Holzmann wrote:
I would suggest you to use the vbap (vector based amplitude panning) external, which does exactly what you are trying to achive ...
The VBAP objects are great, except for one thing that is inherent in all vector-based systems: try to pan a sound directly from left to right through the middle of the loudspeaker circle you have defined. At a certain point (exactly the middle), the sound will audibly "flip over" from one side of the sound field to the other. This is a result of making a radical shift in the radiant of this circle, which is the basis for all measurements in a vector-based panning system.
For four-channel panning, at least, I've been much more satisfied with a quad-panning system based on a chain of stereo panners, going from front/back to front:left/right and back:left/right. For a four channel system, and when you want the sound to move within the bounds of the phsyical speaker locations (as opposed to using a direct sound vs. reverberated sound system to simulate sounds outside the bounds of the speaker locations), this has given the best results for me. Otherwise, I'd love to see a better implementation of VBAP that accounts for this "hole in the middle" problem.
best, derek
Greets, Alexandre
i understand that atan2 outputs radiants and not degrees. if i divide atan2's output by pi and then multiply it with 180 the results are not at all, what i imagine them to be,.
the result of this operation, should be between -180 and 180, right? To put that between 0 and 360, I would use something like | [moses 0] | | [+360] | | / [f ]
This would be kind of tricky in terms of math, if you want for the intermediate joystick values (not just the direction) to control the sound distribution. You likely want to have the sum of squares of your output signals to remain constant (constant total intensity) regardless of joystick position.
Chuck
On 23/10/06, Charles Henry czhenry@gmail.com wrote:
Greets, Alexandre
i understand that atan2 outputs radiants and not degrees. if i divide atan2's output by pi and then multiply it with 180 the results are not at all, what i imagine them to be,.
the result of this operation, should be between -180 and 180, right?
the result of the operation above, eg. the values that [atan2] is outputting are between -pi and plus pi... and i dont quite know how to translate this result into 0-360.. and still i am facing a dilemma, which is what you mentioned:
This would be kind of tricky in terms of math, if you want for the intermediate joystick values (not just the direction) to control the sound distribution. You likely want to have the sum of squares of your output signals to remain constant (constant total intensity) regardless of joystick position.
well thats the thing or exactly the issue i am having..there are so many intermediate joystick values and i have no clue how to deal with them.. can you explain what you mean with "the sum of squares of your output signal" ? i also wonder if there is a way to have a full representation of all the intermediate values: eg. resting the joystick in the middle means to distribute it evenly amongst all four.. thanks for all your guys help... i will keep you up to date.. such a simple task and such a complicated way to do it : ) complicity.. simplexity..
best
alexandre
alexandre r. decoupigny wrote:
On 23/10/06, Charles Henry czhenry@gmail.com wrote:
Greets, Alexandre
i understand that atan2 outputs radiants and not degrees. if i divide atan2's output by pi and then multiply it with 180 the results are not at all, what i imagine them to be,.
the result of this operation, should be between -180 and 180, right?
the result of the operation above, eg. the values that [atan2] is outputting are between -pi and plus pi... and i dont quite know how to translate this result into 0-360.. and still i am facing a dilemma, which is what you
as zexy's author i would suggest: [rag2deg] and [wrap 0 360] (note that there are several versions of [wrap]; the only one i know that would wrap -180..180 into 0..360 is the one from zexy.
mf.adsr IOhannes
On Mon, 23 Oct 2006, alexandre r. decoupigny wrote:
explain what you mean with "the sum of squares of your output signal"
This is because sound power is the square of sound amplitude. Therefore if you want to halve the sound level you need to do [*~ 0.7071] instead of [*~ 0.5]. You need to do this with panning, if you want it to be energy-preserving (no change in used watts no matter how's the mix like).
I made this mistake again last thursday - I computed sound amplitude of some kind of omnidirectional source as being r^-2 where r is the distance. However, I believe that it's energy that should be r^-2, therefore amplitude should be r^-1. That's assuming ideal 3-D dispersion (no ceilings and no walls). Is that right?
i also wonder if there is a way to have a full representation of all the intermediate values: eg. resting the joystick in the middle means to distribute it evenly amongst all four..
If you have 0<=x<=1 and 0<=y<=1, then you could use those two formulas for the volumes a,b,c,d of the four speakers:
a = x * y b = (1-x) * y c = x * (1-y) d = (1-x) * (1-y)
but then to preserve energy, you should use some square root there. another idea is to use sin and cos, which already add up to 1 when squared:
a = cos(x) * cos(y) b = sin(x) * cos(y) c = cos(x) * sin(y) d = sin(x) * sin(y)
complicity.. simplexity..
Personally I reserve those two words for when complexity becomes genuinely counterintuitive and I want to mean that simplicity is not a simple thing to think about and so on.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada
On Mon, 23 Oct 2006, Mathieu Bouchard wrote:
but then to preserve energy, you should use some square root there. another idea is to use sin and cos, which already add up to 1 when squared:
a = cos(x) * cos(y) b = sin(x) * cos(y) c = cos(x) * sin(y) d = sin(x) * sin(y)
replace every x by x*pi/2 and every y by y*pi/2, but then I'm really not convinced that this is any better than the previous simpler formulas provided that square root has been used on them.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada
hola,
first of all.. thank you all so much for your support. it is great to have input from you.
i finished a first sketch. i am not using the vbap, but use objects form the nSlam 1.0 and the the xjimmies library. i found some objects there that are workable for me. however there remains the difficultiy that derek mentioned with vbap, which is that there is some sort of gap occuring in the panning process.. this i can decrease with a parameter from e.g. an [opan2~] object (eight speaker panning object) that lets you set the fadetime in miliseconds. still it is not that satisfactory if i pan from left to right.. circular motion is good. this is due to to frank's (who took me step by step, for which im supergrateful because it made me understad what im actually doing) and iohannes input. i combined the two approaches. you can see this in the example patch that is attached to this email. to run it you need the xjimmies library, which you can get at http://tot.sat.qc.ca/eng/nslam.html. http://tot.sat.qc.ca/eng/nslam.html in the patch there is also a feature that allows to record movement in space. so the idea develops into that of an instrument that allows you to play with sound in space using a simple usb-joystick.
however there remain a lot of issues, like the ones that mathieu discusses (thanks for explaining !).
first i dont know what the r is in the following: "However, I believe that it's energy that should be r^-2, therefore amplitude should be r^-1. That's assuming ideal 3-D dispersion (no ceilings and no walls). Is that right?"
then i obviously still face some problems in the sketch: for example that the way it is set up, the patch only reacts if there is movement on both axis.. for example if i put the joystick all the way to the front and move it from left to right, nothing happens.. no idea how to deal with it..
right now i hope to use more of the parameters offered by the xjimmies library for their panning objects: seperation and fade time and later maybe find better ways to deal with the x and y outputs of the joystick.. i would also love to make it more dynamic, which takes me back to mathieus points. i just dont seem to have knowledge in maths to be able to to follow mathieus explanation : )
more hopefully soon and it would be great if you have any ideas. of course this means everybody as well.
best
alexandre
On Wed, 25 Oct 2006, alexandre r. decoupigny wrote:
first i dont know what the r is in the following: "However, I believe that it's energy that should be r^-2, therefore amplitude should be r^-1. That's assuming ideal 3-D dispersion (no ceilings and no walls). Is that right?"
r is for radius, synonym for distance. I've been using the [pow -2] object to convert distance to amplitude, but apparently that's wrong, i have to add a square root object like [pow 0.5] because [pow -2] is the formula for distance to energy. Both pow objects can be merged together as one [pow -1] object.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada
Hallo, alexandre r. decoupigny hat gesagt: // alexandre r. decoupigny wrote:
then i obviously still face some problems in the sketch: for example that the way it is set up, the patch only reacts if there is movement on both axis.. for example if i put the joystick all the way to the front and move it from left to right, nothing happens.. no idea how to deal with it..
This is because you have the triggering wrong in the part where you convert the joystick coordinates to a degree value.
Correct triggering is hard to get right until you get used to it, just search the archives how often this is mentioned. I'd say it's the most important next thing for you to learn in Pd. Really.
I reworked that part of your patch and commented it a lot. I hope you can follow it, but if there are more questions, please ask: Without understanding trigger you will spend a lot of time hunting for seemingly strange bugs in your patches.
Frank Barknecht _ ______footils.org_ __goto10.org__
I made this mistake again last thursday - I computed sound amplitude of some kind of omnidirectional source as being r^-2 where r is the distance. However, I believe that it's energy that should be r^-2, therefore amplitude should be r^-1. That's assuming ideal 3-D dispersion (no ceilings and no walls). Is that right?
Exactly right. For that ideal environment, we have the intensity (W/m^2) distributed evenly on the surface of a sphere at radius r. So, since the surface area of the sphere varies as r^2, the intensity falls off at a rate of r^-2. The energy of the wave is (mostly) conserved, it just gets spread out over a larger area.
Chuck
this is an interesting line of discussion coming out of this. thats nice : ) again i am very grateful to frank for pointing out what i missed. i will take your comments serious. triggering was indeed something i was not very aware of. now i see it is of essence. obviously..one has to be aware of the flow of things in things if one hopes for certain results.. this makes sense to me.. i looked at the patch and it was well explained. so actually i am amazed by the way you explain. thanks frank !
please dont think im ignorant towards the xy_to_amp because i have not answered to it. im just taking it step by step. once i understand what i did and doing i can understand other approaches as well : )
best
alexandre
I fixed the bugs in that patch xy_to_amp.pd.....can't believe I was trying such a dumb approach (perhaps I should believe it). This one works! You may want to modify it, a little, because I have set it to trigger calculations whenever x changes or y changes. This could result in a redundant calculation, if both x and y are provided (y first, then x). You can just remove the [f ] on x (left inlet), and the [t b f] on y (right inlet) to change this to trigger a calculation on x, only.
Chuck
hey all,
first of all there was a light problem in frank's solution.. it did resolve triggering problem, but that also created a new issue: since the y value was stored in a [f] object and was triggered from an anything bang of the [t] object that depended on the input of the x value, everytime you would move only on the y axis while keeping x consant, no triggering took place and as a result nothing happened. i got around it by inserting a [metro] that only gets triggered when x is static.. see the attached patch : )
merci charles.. it is amazing for me to have this support and that other people also working on this solution. as soon as i will have acces to a proper 4 speaker set up i will put these two patches into a practical test and see whats working well.. now here is another question charles.. is it possible to work this thing on eight speakers ? my problem is i do not get the maths behing your set up.. : ( i really tried, but i seem to miss some basic mathematical knowledge..
best
alexandre
On 28/10/06, Charles Henry czhenry@gmail.com wrote:
I fixed the bugs in that patch xy_to_amp.pd.....can't believe I was trying such a dumb approach (perhaps I should believe it). This one works! You may want to modify it, a little, because I have set it to trigger calculations whenever x changes or y changes. This could result in a redundant calculation, if both x and y are provided (y first, then x). You can just remove the [f ] on x (left inlet), and the [t b f] on y (right inlet) to change this to trigger a calculation on x, only.
Chuck
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
it possible to work this thing on eight speakers ?
Good question. I've been thinking about just that same thing. The nice thing about this xy_to_amp patch is that when you pan all the way to R/L/F/Back, it all goes to just one speaker. And when you pan all the way (.707,.707) in between two speakers, your opposite speakers all have value of zero. You want to have the same thing for 8 (or any number of speakers)...
As for the math, just draw a little picture of a circle, radius .5, with a variable center location, and try some different positions for the center.
BTW, I have only only two speakers, so I have no idea whether or not it sounds good
Chuck
Hallo, alexandre r. decoupigny hat gesagt: // alexandre r. decoupigny wrote:
first of all there was a light problem in frank's solution.. it did resolve triggering problem, but that also created a new issue: since the y value was stored in a [f] object and was triggered from an anything bang of the [t] object that depended on the input of the x value, everytime you would move only on the y axis while keeping x consant, no triggering took place and as a result nothing happened. i got around it by inserting a [metro] that only gets triggered when x is static.. see the attached patch : )
Sorry, late answer here: You don't need to use a metro here, in fact especially with the GUI-bang objects inbetween doing so will eat your CPU cycles quickly. What you sh/could do, if you want to move the y-value alone, is just connect the y-value to the *left* inlet of the [f] object after the [t b a] instead of to the right. Then you would also get a new output if only y changes. However if the value is coming from the joystick-object you should normally always get both x- and y-values at the same time.
Frank Barknecht _ ______footils.org_ __goto10.org__
I have been thinking about this problem and think that I've got a suggestion now, but I'm struggling with the implementation. I'll enclose the suggested patch anyway....and hopefully someone will have an idea how to fix it.
The equations I suggest for four signal amplitudes whose squares add up to 1 comes from a geometric idea. If we have a circle of radius 1/2, and center coordinates x1,y1 within a circle (radius 1/2) centered at the origin, then the squares of the locations of intercepts always add up to 1.
So, I tried to implement this, in a few steps:
limit it to 1 2. divide the radius by 2, and convert back to cartesian coordinates 3. use the following equations for signal amplitudes s1=y1+sqrt( 0.25 - x1^2) s2=sqrt( 0.25 - x1^2) - y1 s3=x1+sqrt( 0.25 - y1^2) s4=sqrt( 0.25 - y1^2) - x1
s1 and s2 correspond to the speakers opposite from one another, same with s3, s4
what a mess....
Chuck