Something like mean~

View: New views
4 Messages — Rating Filter:   Alert me  

Something like mean~

by KHofstadter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello

I am wondering how I could change the volume of a background sound?
I receive two values within a Task. Each is a sum of an array of 16 floats. By subtracting one from the other and using the absolute of result I receive a float every 1/4 a second. (also divided by 100, see below in code)

I would like to use the mean (reset every 10 sec) of these values. Whenever the value is keeping itself close to "0" the amplitude of the background synth should get higher (slowly). When the value is getting higher again, the background sound should fade out.

Any help appreciated,
Krisztian

code:
differ = (differ1 - differ2).abs; //make it to absolute number
                        mydiffer = (differ/100);
                        //differ1.postln;
                        //differ2.postln;
                        mydiffer.postln;

post window:

2.880859375
0.244140625
1.953125
0
0.048828125
1.13525390625
0.9521484375
1.08642578125
2.28271484375
4.28466796875
0.354003875
6.4208983125
0.96435546875
3.369140625
2.9052734375
0.927734375
4.18701171875
0.7080078125
2.79541015625
0.537109375
0.79345703125
2.72216796875
0.76904296875
2.9541015625
1.01318359375
1.55029296875
1.28173828125
0.048828125
0.9521484375
2.89306640625
0.57373046875
1.611328125
1.4892578125
1.59912109375
2.3681640625
0.9033203125
1.07421875



Re: Something like mean~

by nescivi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 09 April 2009 12:20:09 KHofstadter wrote:

> Hello
>
> I am wondering how I could change the volume of a background sound?
> I receive two values within a Task. Each is a sum of an array of 16 floats.
> By subtracting one from the other and using the absolute of result I
> receive a float every 1/4 a second. (also divided by 100, see below in
> code)
>
> I would like to use the mean (reset every 10 sec) of these values. Whenever
> the value is keeping itself close to "0" the amplitude of the background
> synth should get higher (slowly). When the value is getting higher again,
> the background sound should fade out.

RunningMean (or something like that) on the server,
or call
mean
on the array with values gathered over the time period on the language side.

sincerely,
Marije

>
> Any help appreciated,
> Krisztian
>
> code:
> differ = (differ1 - differ2).abs; //make it to absolute number
> mydiffer = (differ/100);
> //differ1.postln;
> //differ2.postln;
> mydiffer.postln;
>
> post window:
>
> 2.880859375
> 0.244140625
> 1.953125
> 0
> 0.048828125
> 1.13525390625
> 0.9521484375
> 1.08642578125
> 2.28271484375
> 4.28466796875
> 0.354003875
> 6.4208983125
> 0.96435546875
> 3.369140625
> 2.9052734375
> 0.927734375
> 4.18701171875
> 0.7080078125
> 2.79541015625
> 0.537109375
> 0.79345703125
> 2.72216796875
> 0.76904296875
> 2.9541015625
> 1.01318359375
> 1.55029296875
> 1.28173828125
> 0.048828125
> 0.9521484375
> 2.89306640625
> 0.57373046875
> 1.611328125
> 1.4892578125
> 1.59912109375
> 2.3681640625
> 0.9033203125
> 1.07421875



_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Something like mean~

by Dan Stowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi -

Rather than "resetting" the mean every ten seconds, maybe you might
consider using the exponentially-weighted mean, also called "recursive
averaging"? It's very easy to implement:

~smoothingfactor = 0.9;
~rate = 0.1;
~ravg = 0.0;
~min = 10.0;
~max = 11.0;
(
t = Task{
  loop{
    ~somevalue = rrand(~min, ~max); // simulated data

    ~ravg = (~ravg * ~smoothingfactor) + (~somevalue * (1-~smoothingfactor));
    [~somevalue, ~ravg].postln;

    ~rate.wait;
  }
}.play;
)

// You can change ~max and ~min of the simulated data
// to watch how fast the average changes.

t.stop;

The smoothing factor, and the rate that you receive new values,
together determine how quickly the mean converges.

HTH
Dan


2009/4/9, KHofstadter <tedor2@...>:

>
>  Hello
>
>  I am wondering how I could change the volume of a background sound?
>  I receive two values within a Task. Each is a sum of an array of 16 floats.
>  By subtracting one from the other and using the absolute of result I receive
>  a float every 1/4 a second. (also divided by 100, see below in code)
>
>  I would like to use the mean (reset every 10 sec) of these values. Whenever
>  the value is keeping itself close to "0" the amplitude of the background
>  synth should get higher (slowly). When the value is getting higher again,
>  the background sound should fade out.
>
>  Any help appreciated,
>  Krisztian
>
>  code:
>  differ = (differ1 - differ2).abs; //make it to absolute number
>                         mydiffer = (differ/100);
>                         //differ1.postln;
>                         //differ2.postln;
>                         mydiffer.postln;
>
>  post window:
>
>  2.880859375
>  0.244140625
>  1.953125
>  0
>  0.048828125
>  1.13525390625
>  0.9521484375
>  1.08642578125
>  2.28271484375
>  4.28466796875
>  0.354003875
>  6.4208983125
>  0.96435546875
>  3.369140625
>  2.9052734375
>  0.927734375
>  4.18701171875
>  0.7080078125
>  2.79541015625
>  0.537109375
>  0.79345703125
>  2.72216796875
>  0.76904296875
>  2.9541015625
>  1.01318359375
>  1.55029296875
>  1.28173828125
>  0.048828125
>  0.9521484375
>  2.89306640625
>  0.57373046875
>  1.611328125
>  1.4892578125
>  1.59912109375
>  2.3681640625
>  0.9033203125
>  1.07421875
>
>
>
>  --
>  View this message in context: http://www.nabble.com/Something-like-mean%7E-tp22974436p22974436.html
>  Sent from the Supercollider - User mailing list archive at Nabble.com.
>
>
>  _______________________________________________
>  sc-users mailing list
>
>  info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
>  archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
>  search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>


--
http://www.mcld.co.uk

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Something like mean~

by KHofstadter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
thank you for your help!

I could use the "recursive averaging"! Was easy to implement as you said.
Though I have to do my algebra homework now.

best
K