Java script equation

Apr 29, 2009 at 1:35pm

Java script equation

hello,

I am trying to implement an equation that calculates the sound pressure level in my patch, using the js object.
The problem is that it is not working, it doesn’t look like it is receiving correctly the information.

here is the code:

inlets = 5;

function calculate(D, rho, c, N, r){
var dbs = Math.round(20 * Math.LOG10E * Math.log(Math.pow((D * rho * c * N / (4 * Math.PI * r * r)),0.5)/0.00002));

outlet(0, dbs);
}

function msg_float(v)
{
if (jsarguments.length>5){
var D = jsarguments[0];
var rho = jsarguments[1];
var c = jsarguments[2];
var N = jsarguments[3];
var r = jsarguments[4];
}

calculate(D, rho, c, N, r);
}

rho – air density (kg/m3)
c – sound velocity (m/s)
N – sound power (W)
r – distance from source (m)
D – directivity coefficient

and gives me the SPL in dB as a result.

Thank you

#43585
Apr 29, 2009 at 3:27pm

hello,

i think you should do something like that :

inlets = 1 ; // not necessary (that’s default).
outlets = 1 ; // itou.

function calculate ()
{
var a = arrayfromargs (arguments) ;

var toto_a = a[0] ;
var toto_b = b[1] ;
etc…

var result = toto_a + toto_b ; // formula

outlet (0, result) ;
}

and just send the message “calculate 0.1 0.2 etc…” in the inlet.

or better

function list ()
{
var a = arrayfromargs (arguments) ;
var result = a[0]+a[1] ;
outlet (0, result) ;
}

and give your values as a list…

or better

use max object as [expr]

i hope that’s work, i have a very bad memory.

#156381

You must be logged in to reply to this topic.