SuperCollider Forum
May 21, 2013, 04:56:50 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The SuperCollider forum is currently experiencing a rash of spambot registrations. New user requests may not be approved quickly as a result -- and if your email address looks like spam, it might not be approved at all. We are working to improve the security of the registration process, and to provide alternate means to contact the administrators to get a new account. Thanks for your patience.
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Max (float) to trigger a sound in SC  (Read 5257 times)
0 Members and 1 Guest are viewing this topic.
tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« on: October 15, 2008, 01:35:30 PM »

Dear SC user,

I would like to ask for some help concerning the following. I have some rhythmically changing floats in Max/Msp which I would like to use in SC. I have used OSC before but I still have not mastered it.

 The floats already represent amplitude. (0.0 - 1.0) so I am not sure, should I embed these numbers in the Envelopes of the Synths somehow?
Screenshot:
http://www.tedor2.extra.hu/issue.jpg

 If anyone could tell me what the easiest way of getting around is, please?

Help appreciated,
Krisztian
Logged
dewdrop_world
AdminGroup
Full Member
*

Karma: 9
Posts: 193



View Profile WWW
« Reply #1 on: October 15, 2008, 05:45:02 PM »

No, a number coming in by an OSC message can't be embedded in an envelope.

Are you using one synth, that should retrigger when receiving the number from Max? Or, should each number make a new synth?

If the former, use a t_trig argument for the 'gate' EnvGen input.

Code:
SynthDef(..., { |t_trig = 1, ...|
var envpeak = Latch.kr(t_trig, t_trig),
envelope = Env([0, envpeak, 0], [attack, decay], ...),
envgen = EnvGen.kr(env, t_trig);
...
})

The purpose of Latch is to hold the trigger value until the next trigger comes in.

If it should be a new Synth, then it's easy -- just do Synth(...) in your OSCresponderNode.

Sorry this is kind of sketchy... time is short this morning.

hjh
Logged

tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« Reply #2 on: October 16, 2008, 09:20:26 AM »

hi,

I think I will need some more help as I got stuck:

|...| do this strait brackets replace arg?  |t_trig = 1, ...|
if I it without the strait brackets it does not give me an error concerning it in the post window.

the values I am receiving do not go under 0 (the changing float is between 0.0 and 1.0) Can still use Latch?

thank you dewdrop
Krisztian

Code:


(

//_____________________OSC ARGUMENTS____________________

var maxrate01 = 0;
var maxrate02 = 0;

//_____________________VARIABLES____________________



var quake, bim;


//_____________________SYNTH'S____________________



quake    = {arg nfr1 = 30, nb=1, muli=1, addi=1000, vol=0, pa=0;
         Out.ar(0, Pan2.ar(LFNoise1.ar( nfr1
         + SinOsc.ar(nb, mul: muli, add: addi),
         mul:  vol), pa) )}.play;


bim =
                   {                          
                                       arg t_trig = 1,
                                       cfq=1500, mfq=200, idex=1, ammodfq = 15, ammul = 0.3;
                                
                                      var  sound, out;
                                      var envpeak = Latch.kr(t_trig, t_trig);
                                      var envelope = Env([0, envpeak, 0], [0.1,0.5], ['exp', 'lin']).circle.postcs;
                                       var envgen = EnvGen.kr(envelope, doneAction: t_trig);
                                    
                                       sound = PMOsc.ar(cfq, mfq, idex, 0,
                                       mul: SinOsc.ar(ammodfq, mul:ammul));
                                   
                                        
                                    Out.ar( 0, Pan2.ar(sound * e,0))                                          
                               }.play;


         

//_____________________OSC RESPONDERS
n = NetAddr("10.37.129.2", 57120); // Sets up the OSC responders' address


OSCresponder(nil, '/maxrate01', { arg time,responder,msg,addr;
   maxrate01 = msg[1];
   bim.set(\t_trig, maxrate01);
}).add;



OSCresponder(nil, '/maxrate02', { arg time,responder,msg,addr;
   maxrate02 = msg[1].postln;
   quake.set( \vol, maxrate02);
}).add;

)



Logged
tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« Reply #3 on: October 16, 2008, 03:38:16 PM »

I was trying an other way:
(kinda works with buffer, but would like to see the idea you suggested working as well, will be working on it...)
Code:
(


//_____________________OSC ARGUMENTS____________________

var maxrate01 = 0;
var maxrate02 = 0;
var maxrate03 = 0;
var maxrate04 = 0;

//_____________________VARIABLES____________________



var audio01;
var audio02;


//_____________________SYNTH'S____________________
b = Buffer.read(s,"/Users/krisztianhofstadter/Desktop/RICHARD/sounds/01.aif");
c = Buffer.read(s,"/Users/krisztianhofstadter/Desktop/RICHARD/sounds/02.aif");

audio01 = { arg out=0, bufnum=0, bang=0, vol=0.5;
var trig;
trig = bang;
Out.ar(out,
vol *
PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), trig, 5000), 1)
}.play(s,[\out, 0, \bufnum, b]);

audio02 = { arg out=1, bufnum=1, bang=0, vol=0.5;
var trig;
trig = bang;
Out.ar(out,
vol *
PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), trig, 5000), 1)
}.play(s,[\out, 0, \bufnum, b]);


//_____________________OSC RESPONDERS
n = NetAddr("10.37.129.2", 57120); // Sets up the OSC responders' address


OSCresponder(nil, '/maxrate01', { arg time,responder,msg,addr;
   maxrate01 = msg[1];
   audio01.set(\bang, maxrate01);
}).add;

OSCresponder(nil, '/maxrate02', { arg time,responder,msg,addr;
   maxrate02 = msg[1];
   audio01.set(\vol, maxrate02);
}).add;

OSCresponder(nil, '/maxrate03', { arg time,responder,msg,addr;
   maxrate03 = msg[1].postln;
   audio02.set(\bang, maxrate03);
}).add;

OSCresponder(nil, '/maxrate04', { arg time,responder,msg,addr;
   maxrate04 = msg[1].postln;
   audio02.set(\vol, maxrate04);
}).add;
)


Logged
dewdrop_world
AdminGroup
Full Member
*

Karma: 9
Posts: 193



View Profile WWW
« Reply #4 on: October 16, 2008, 05:48:27 PM »

|...| do this strait brackets replace arg?  |t_trig = 1, ...|

Yes -- use either arg or |...| but not both.

the values I am receiving do not go under 0 (the changing float is between 0.0 and 1.0) Can still use Latch?

Yes -- a t_ argument holds its value for one control cycle, then drops to 0 -- intended for trigger inputs that need to reset frequently.

EnvGen.kr(envelope, doneAction: t_trig);

t_trig should go into the gate argument of EnvGen, not doneAction.

Out.ar( 0, Pan2.ar(sound * e,0))

sound * envgen instead? I don't see in your code what 'e' is. Probably a typo.
Logged

tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« Reply #5 on: October 18, 2008, 03:15:35 PM »



wow, Supercollider is exciting.

I followed your hints, but could not find the solution...

the funny thing is, that it just started to work as I made an equation ( a = SynthDef("alfa", ... )
and then I had to use "a.set(\t_triga, maxrate01)".

I could work out to trigger the sounds, with a percussive envelope:
Code:
//4th with a percussive Envelope
(

//_____________________OSC ARGUMENTS____________________

var maxrate01 = 0;
var maxrate02 = 0;

//_____________________VARIABLES____________________

var alfa;
var beta;

//_____________________SYNTH'S____________________

a = SynthDef("alfa", {                         
                                       |t_triga = 1|
                               
                                      var  sound, out;
 // var envpeak = Latch.kr(t_triga, t_triga);
//                                   var envelope = Env([0, envpeak, 0], [1,1], ['exp', 'lin']).circle.postcs;
                                      var envgen = EnvGen.kr(Env.perc(0.05, 1, 1, -4), t_triga);
                                     
                                      sound = Mix.new( Array.fill(8, { SinOsc.ar(500 + 500.0.rand, 0, 0.05) }) );
                                   
                                       
                                    Out.ar( 0, Pan2.ar(sound * envgen,0))                                         
                               }).play;

b = SynthDef("beta", {                         
                                       |t_trigb = 1|
                               
                                      var  sound, out;
// var envpeak = Latch.kr(t_trigb, t_trigb);
//                                   var envelope = Env([0, envpeak, 0], [1,1], ['exp', 'lin']).circle.postcs;
                                      var envgen = EnvGen.kr(Env.perc(0.05, 1, 1, -4), t_trigb);
                                     
                                      sound = Mix.new( Array.fill(8, { SinOsc.ar(500 + 100.0.rand, 0, 0.05) }) );
                                   
                                       
                                    Out.ar( 0, Pan2.ar(sound * envgen,0))                                         
                               }).play;

//_____________________OSC RESPONDERS

n = NetAddr("10.37.129.2", 57120); // Sets up the OSC responders' address

OSCresponder(nil, '/maxrate01', { arg time,responder,msg,addr;
   maxrate01 = msg[1].postln;
   a.set(\t_triga, maxrate01);
}).add;

OSCresponder(nil, '/maxrate02', { arg time,responder,msg,addr;
   maxrate02 = msg[1].postln;
   b.set(\t_trigb, maxrate02);
}).add;

But the Latch part still does not work, which should be the one which adjusts the volume of each sound.
Code:
//5th does not work
(

//_____________________OSC ARGUMENTS____________________

var maxrate01 = 0;
var maxrate02 = 0;

//_____________________VARIABLES____________________

var alfa;
var beta;

//_____________________SYNTH'S____________________

a = SynthDef("alfa", {                         
                                       |t_triga = 1|
                               
                                      var  sound, out;
                                      var envpeak = Latch.kr(t_triga, t_triga);
                                      var envelope = Env([0, envpeak, 0], [1,1], ['exp', 'lin']).circle.postcs;
                                      var envgen = EnvGen.kr(envelope, t_triga);                                     
                                      sound = Mix.new( Array.fill(8, { SinOsc.ar(500 + 500.0.rand, 0, 0.05) }) );
                                   
                                       
                                    Out.ar( 0, Pan2.ar(sound * envgen,0))                                         
                               }).play;

b = SynthDef("beta", {                         
                                       |t_trigb = 1|
                               
                                      var  sound, out;
                                      var envpeak = Latch.kr(t_trigb, t_trigb);
                                      var envelope = Env([0, envpeak, 0], [1,1], ['exp', 'lin']).circle.postcs;
                                      var envgen = EnvGen.kr(envelope, t_trigb);
                                     
                                      sound = Mix.new( Array.fill(8, { SinOsc.ar(500 + 100.0.rand, 0, 0.05) }) );
                                   
                                       
                                    Out.ar( 0, Pan2.ar(sound * envgen,0))                                         
                               }).play;

//_____________________OSC RESPONDERS

n = NetAddr("10.37.129.2", 57120); // Sets up the OSC responders' address

OSCresponder(nil, '/maxrate01', { arg time,responder,msg,addr;
   maxrate01 = msg[1].postln;
   a.set(\t_triga, maxrate01);
}).add;

OSCresponder(nil, '/maxrate02', { arg time,responder,msg,addr;
   maxrate02 = msg[1].postln;
   b.set(\t_trigb, maxrate02);
}).add;

)


If you think you could still advise me, I would greatly appreciate it!
Best,
Krisztian

ps.: data received:
http://www.tedor2.extra.hu/mix/Picture 1.jpg

« Last Edit: October 18, 2008, 03:27:57 PM by tedor2 » Logged
joshp
AdminGroup
Full Member
*

Karma: 5
Posts: 121



View Profile WWW
« Reply #6 on: October 18, 2008, 11:14:23 PM »

So = I think this may work:

                                      var envpeak = Latch.kr(t_triga, t_triga);
                                      var envelope = Env([0.00001, 1, 0.00001], [1,1], ['exp', 'lin']).circle * envpeak;

I am also changing the level to 0 (since 'exp' and zero are, well, bad)

Josh
Logged
tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« Reply #7 on: October 19, 2008, 11:13:15 AM »

thank you Josh for the help, but this is the post I got

ERROR: Message '*' not understood.
RECEIVER:
Instance of Env {    (14BD9A90, gc=6C, fmt=00, flg=00, set=03)
  instance variables [6]
    levels : instance of Array (1536A660, size=5, set=3)
    times : instance of Array (15448C10, size=4, set=2)
    curves : instance of Array (15D71520, size=4, set=2)
    releaseNode : Integer 3
    loopNode : Integer 0
    array : nil


best,
krisztian
Logged
joshp
AdminGroup
Full Member
*

Karma: 5
Posts: 121



View Profile WWW
« Reply #8 on: October 19, 2008, 11:32:50 AM »

oops! That should be * the EnvGen
Logged
tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« Reply #9 on: October 20, 2008, 12:56:56 AM »

same error Sad
but I will get it somehow!
Logged
dewdrop_world
AdminGroup
Full Member
*

Karma: 9
Posts: 193



View Profile WWW
« Reply #10 on: October 20, 2008, 07:55:22 AM »

sound * envgen * envpeak

?

James
Logged

tedor2
Newbie
*

Karma: 0
Posts: 42


View Profile
« Reply #11 on: October 20, 2008, 10:43:23 AM »

Dear Both,

the only thing I could do was to use an other osc responter, where I did not use "t_".

I multiplied the Env.gen with the the same number.
Works, would not work without your help:)
all the best,
krisztian


Code:
//my try

(

//_____________________OSC ARGUMENTS____________________

var maxrate01 = 0;
var maxrate02 = 0;
var maxrate03 = 0;
var maxrate04 = 0;

//_____________________VARIABLES____________________

var alfa;
var beta;

//_____________________SYNTH'S____________________

a = SynthDef("alfa", {                         
                                       |t_triga = 1, vola|
                                
                                      var  sound, out;
                                      //var envpeak = Latch.kr(t_triga, t_triga);
//                             var envelope = Env([0.00001, 1, 0.00001], [1,1], ['exp', 'lin']).circle;                          
var envgen = vola * EnvGen.kr(Env.perc(0.05, 1, 1, -4), t_triga);
                                      sound = Mix.new( Array.fill(8, { SinOsc.ar(500 + 500.0.rand, 0, 0.05) }) );
                                   
                                        
                                    Out.ar( 0, Pan2.ar(sound * envgen,0))                                          
                               }).play;

b = SynthDef("beta", {                         
                                       |t_trigb = 1, volb|
                                
                                      var  sound, out;
                                      //var envpeak = Latch.kr(t_trigb, t_trigb);
//                             var envelope = Env([0.00001, 1, 0.00001], [1,1], ['exp', 'lin']).circle;                                    
var envgen = volb * EnvGen.kr(Env.perc(0.05, 1, 1, -4), t_trigb);                                    
                                      sound = Mix.new( Array.fill(8, { SinOsc.ar(500 + 100.0.rand, 0, 0.05) }) );
                                   
                                        
                                    Out.ar( 0, Pan2.ar(sound * envgen,0))                                          
                               }).play;

//_____________________OSC RESPONDERS

n = NetAddr("10.37.129.2", 57120); // Sets up the OSC responders' address

OSCresponder(nil, '/maxrate01', { arg time,responder,msg,addr;
   maxrate01 = msg[1].postln;
   a.set(\t_triga, maxrate01);
}).add;

OSCresponder(nil, '/maxrate02', { arg time,responder,msg,addr;
   maxrate02 = msg[1].postln;
   b.set(\t_trigb, maxrate02);
}).add;

OSCresponder(nil, '/maxrate03', { arg time,responder,msg,addr;
   maxrate03 = msg[1].postln;
   a.set(\vola, maxrate03);
}).add;

OSCresponder(nil, '/maxrate04', { arg time,responder,msg,addr;
   maxrate04 = msg[1].postln;
   b.set(\volb, maxrate04);
}).add;

)
« Last Edit: October 20, 2008, 10:45:06 AM by tedor2 » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!