electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
Looper w. volume control in chuck
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [12 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Mon Oct 22, 2007 4:34 am    Post subject: Looper w. volume control in chuck Reply with quote  Mark this post and the followings unread

Hello there,
I've tuned one of the basic examples in chuck to have a kind of looper. The code looks like that:

.35::second => dur T;
T - (now % T) => now;
fun void loop(int ch, string smp, int per){
SndBuf buf => dac;
while( true ){
smp => buf.read;
0 => buf.pos;
per::T => now;
}
}
spork ~ loop(0,"E:/STUDIO/SAMPLES/JUNGLE-LOOP/SEQUENC170.wav",Cool;
spork ~ loop(1,"E:/STUDIO/SAMPLES/JUNGLE-LOOP/ASHES 170.wav",Cool;
while( true ){
100::ms => now;
//I'd like to control volumes of sporks in here
}


It run two loops indexed 0 and 1 and what i need is a control of the volume inside the main loop, but I do not know how to do that smoothly.
Please help.

Sorry if the question was already raised as I am new to the forum.
Regards

RR
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Oct 22, 2007 4:40 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi, reverbrick & welcome on board!

Could you re-post your code using the "code' tag and switch off smileys & HTML? The board will muck it all up otherwise.

Where would you like the volume controll to come from?

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Mon Oct 22, 2007 4:59 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks! I've forgot about this tag...I'd like to control volume by midi events later on.

Code:
.35::second => dur T;
T - (now % T) => now;
fun void loop(int ch, string smp, int per){
    SndBuf buf => dac;
    while( true ){
        smp => buf.read;
        0 => buf.pos;
        per::T => now;
    }
}
spork ~ loop(0,"E:/STUDIO/SAMPLES/JUNGLE-LOOP/SEQUENC170.wav",8);
spork ~ loop(1,"E:/STUDIO/SAMPLES/JUNGLE-LOOP/ASHES  170.wav",8);
while( true ){
    100::ms => now;
    //I'd like to control volumes of sporks in here
}
[/code]
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Oct 22, 2007 5:24 am    Post subject: Reply with quote  Mark this post and the followings unread

How about using "Envelope" in your signal chain for smooth volume controll using .target() ?

To make those adressable by MIDI I'd turn those instruments into classes. This is not so much extra code and it'll get you super smooth volume tweaks and the controll structure can remain quite clear and simple.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Mon Oct 22, 2007 5:30 am    Post subject: Reply with quote  Mark this post and the followings unread

Thank you for the response...It looks like I've need to learn more about classes.

Best Regards
RR
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Oct 22, 2007 5:38 am    Post subject: Reply with quote  Mark this post and the followings unread

I think classes will suit you as they are very good for what you are doing above already. The big bonus is a name-space that's adressable from outside of them, unlike functions.

Just give a shout if/when you get stuck.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Mon Oct 22, 2007 5:40 am    Post subject: Reply with quote  Mark this post and the followings unread

I'll do so...thanks again!
Back to top
View user's profile Send private message
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Mon Oct 22, 2007 10:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

Kasen, it works! I've put all into class and added midi functionality to controll volume settings of 8 channels thats the code:

Code:
//tempo stuff 140=.212
.2165::second => dur T;
T - (now % T) => now;

//class
class loop{
    SndBuf buf => Gain gai => dac;
   0 => gai.gain;
   fun void load(string smp){
      smp => buf.read;
   }
    fun void go(int per){
        while( true ){
            0 => buf.pos;
            per::T => now;
        }
    }
}

//midi stuff
2 => int device;
MidiIn min;
MidiMsg msg;
if( !min.open( device ) ) me.exit();

//loops
loop l1,l2,l3,l4,l5,l6,l7,l8;
l1.load("sample1.wav");
l2.load("sample2.wav");
l3.load("sample3.wav");
l4.load("sample4.wav");
l5.load("sample5.wav");
l6.load("sample6.wav");
l7.load("sample7.wav");
l8.load("sample8.wav");
spork ~ l1.go(8);
spork ~ l2.go(8);
spork ~ l3.go(32);
spork ~ l4.go(32);
spork ~ l5.go(32);
spork ~ l6.go(32);
spork ~ l7.go(32);
spork ~ l8.go(16);

//main loop
while( true ){
    min => now;
    while(min.recv(msg)){
      //1-8
   if(me.arg(0)=="1"){
        if (msg.data2==0) msg.data3/127.0 => l1.gai.gain;
        if (msg.data2==1) msg.data3/127.0 => l2.gai.gain;
        if (msg.data2==2) msg.data3/127.0 => l3.gai.gain;
        if (msg.data2==3) msg.data3/127.0 => l4.gai.gain;
        if (msg.data2==4) msg.data3/127.0 => l5.gai.gain;
        if (msg.data2==5) msg.data3/127.0 => l6.gai.gain;
        if (msg.data2==6) msg.data3/127.0 => l7.gai.gain;
        if (msg.data2==7) msg.data3/127.0 => l8.gai.gain;   
      }
      //9-16
   if(me.arg(0)=="2"){
        if (msg.data2==8) msg.data3/127.0 => l1.gai.gain;
        if (msg.data2==9) msg.data3/127.0 => l2.gai.gain;
        if (msg.data2==10) msg.data3/127.0 => l3.gai.gain;
        if (msg.data2==11) msg.data3/127.0 => l4.gai.gain;
        if (msg.data2==12) msg.data3/127.0 => l5.gai.gain;
        if (msg.data2==13) msg.data3/127.0 => l6.gai.gain;
        if (msg.data2==14) msg.data3/127.0 => l7.gai.gain;
        if (msg.data2==15) msg.data3/127.0 => l8.gai.gain;   
      }                        
      //<<<msg>>>;
    }
}


The only thing I'll need to do is somehow smooth the volume change as on some "sound textures" there are noises noticeable during fading. Another one if you see thee script runs with one parameter (1 or 2) it tels the script to be controlled by fader 1-8 or 9-16 because I'd like it to be used for life performance one by one and the problem is when I for example run chuck + script1.ck:1 it runs well and after that i run chuck + script2.ck:2 then audio from script1 stops for a second. Have you got any ideas?

Thanks
RR
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Oct 23, 2007 3:27 am    Post subject: Reply with quote  Mark this post and the followings unread

The audio is probably stopping because you are loading a batch of larger(?) wave files. In the manual is some documentation about making SndBuf load files in chunks instead of all at once, I'd have a look at that if I were you. I see you aren't using stereo so I'd also make sure those waves are mono as that will save you half the file-size already.

For volume glides you could try "Envelope" instead of those gains. then give it a reasonable duration for the smoothing (75::ms or so?) and use .target() instead of ".gain(()", that should give you smooth volume adjustments without a high price.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Wed Oct 24, 2007 6:37 am    Post subject: Reply with quote  Mark this post and the followings unread

I was trying to load lamples in 100::ms, 500::ms and 1::sec periods and it's even worse SadSad ...
Back to top
View user's profile Send private message
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Wed Oct 24, 2007 6:39 am    Post subject: Reply with quote  Mark this post and the followings unread

maybe a solution might be filtering clicks? neeee....
Back to top
View user's profile Send private message
reverbrick



Joined: Oct 22, 2007
Posts: 8
Location: Poland

PostPosted: Wed Oct 24, 2007 6:46 am    Post subject: Reply with quote  Mark this post and the followings unread

got it!!!!
now after understanding what chunks are set 10 => buf=>chunks and it works!!!! smoothly

Thanks again!!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [12 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use