electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks GalleryGallery 
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Preparing a Class to use as a sound player for sequencing
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
kijjaz



Joined: Sep 20, 2004
Posts: 465
Location: bangkok, thailand
Audio files: 2

PostPosted: Sat Nov 18, 2006 2:31 pm    Post subject: Preparing a Class to use as a sound player for sequencing Reply with quote  Mark this post and the followings unread

i've been preparing some ways to play sounds
using sequencing or some other kinds of sporking.
i hope this kind of class-building is okay.
please check out and give some comments.
i'm trying to make it mainly for it to be easy to use..

the new thing i'm implementing here is the functions for connecting and disconnecting with another UGen.
i guess it's quite user-friendly now.


Code:
class BD {
   // SinOsc as the main oscillator to Sine Waveshaper
   // (set sync = 1 for phasemod to use w as a waveshaper)
   // and mute the sound.
   SinOsc s => SinOsc w;   
   0.0 => s.gain;   
   1 => w.sync;
   
   // initial values:
   // bass drum's start frequency
   80.0 => float freqStart;
   // stop frequency
   0.0 => float freqStop;
   // duration of a note
   0.5::second => dur duration;
   // drive ratio to feed into the waveshaper.
   // .. > 0.5 will start sine clipping
   1.1 => float drive;
   // output gain
   1.0 => float gain;
   
   // use connect to chuck the result with another UGen.
   fun void connect(UGen x) {
      w => x;
   }
   
   // use disconnect to unchuck
   fun void disconnect(UGen x) {
      w =< x;
   }
   
   // play
   fun void play() {
      // reset the phase to 0
      0 => s.phase;
      // use t as a counter for falling sound effect.
      for(1 => float t; t > 0; 0.001 -=> t) {
         // calculate frequency using linear fall
         (freqStart - freqStop) * t + freqStop => s.freq;
         // drive goes to s's gain.
         drive * 0.5 * t => s.gain;
         // gain goes to w's gain.
         gain * t => w.gain;
         // calculate 1000 times for the whole length
         // eh.. i think this is not a good idea -_-"
         duration * 0.001 => now;
      }
      // mute the whole thing after playing.
      0.0 => w.gain => s.gain;
   }   
}

// new bassdrum!
BD bd1;

// connect it to dac, set drive, simply play.
bd1.connect(dac);
1.5 => bd1.drive;
bd1.play();

// try another start frequency and simply play.
60 => bd1.freqStart;
bd1.play();

// disconnect from dac
bd1.disconnect(dac);

// set up an echo
Echo fx1 => dac;
1 :: second => fx1.max;
0.3 :: second => fx1.delay;
// set up the echo's feedback into itself, with feedback gain
// (delay line should work better -_-")
fx1 => Gain fx1gain => fx1 => blackhole;
0.3 => fx1.mix;
0.5 => fx1gain.gain;

// connect the bassdrum to the effect.
bd1.connect(fx1);
0.5 => bd1.gain;
// try playing it right away.
bd1.play();
1::second => now;

// use a faster bass drum for the next sequence
0.05::second => bd1.duration;

for(int i; i < 64; i++) {
   // overdrive increases each time.
   i * 0.1 => bd1.drive;
   // start frequency randomly changes each time.
   Std.rand2f(50, 150) => bd1.freqStart;
   // spork a bassdrum play function
   spork ~ bd1.play();
   // wait till next beat
   0.2::second => now;
}


thanks Razz
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
jimmysword



Joined: Jan 11, 2008
Posts: 12
Location: Leeds, W Yorks

PostPosted: Wed Jan 23, 2008 8:01 am    Post subject: Reply with quote  Mark this post and the followings unread

I think this approach is a great idea! Even using samples (which I am doing), the class approach will make things neater and easier to follow..

I'm having a problem figuring out a good way to sequence (there are so many different ways of doing stuff with chuck it's not even funny) but this class business will make it easier Smile
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


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

PostPosted: Wed Jan 23, 2008 11:39 am    Post subject: Reply with quote  Mark this post and the followings unread

Assuming the real "meat" to this demo is the connect&disconnect functionality then yes, makes perfect sense to me. Very cool strategy, will probably be easy to read back later or for others as well.

Another trick; in a comparable sort of class I build for a envelope follower kind of thing I connect a chain of Ugens to blackhole. This class has a .free() function which breaks this connection to blackhole and so makes the instance stop using the CPU. I found freeing the CPU from custom "Ugen-like" objects a bit of a tricky issue but this technique seems quite clean and logical to me.

jimmysword, I recommend starting with a list of what you like and hate about existing sequencers and work from there. There are a lot of sequencers out there and nearly all of them have some good ideas and some bad stuff so learn from those. It's hard to start with a technological framework if you don't know yet what it will have to do and what functionality you don't like or need. Why not download the manuals of some different sequencers in soft and hardware and see where they place the emphasis? Also interesting is taking a MIDI controller, imagining it's a sequencer and think about how this would work.

_________________
Modern technology offers an endless field day to any deviant strains in our personalities. --J.G.Ballard
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor



Joined: Oct 13, 2007
Posts: 1330
Location: Florida, USA
Audio files: 52

PostPosted: Wed Jan 23, 2008 2:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

Maybe this is a stupid question, but I cannot easily find the answer in the manuals. How can I write a ChucK script? I want it to start a chuck file, wait some time, then stop it, then start a wav file, then stop it, etc. Rather than typing that in by hand in a performance, I'd like it to do it automatically for me. How do I do that?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kassen
Janitor
Janitor


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

PostPosted: Wed Jan 23, 2008 5:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

Inventor wrote:
Maybe this is a stupid question, but I cannot easily find the answer in the manuals. How can I write a ChucK script?


Well..... I use Notepad++ or the MiniAudicle, depending on my mood ;¬)

Quote:
I want it to start a chuck file, wait some time, then stop it, then start a wav file, then stop it, etc. Rather than typing that in by hand in a performance, I'd like it to do it automatically for me. How do I do that?


Code:
Machine.add("my_file.ck") => int my_id;

some_time => now;

Machine.remove(my_id);

//etc


Like that?

Not sure I understand the question.

_________________
Modern technology offers an endless field day to any deviant strains in our personalities. --J.G.Ballard
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor



Joined: Oct 13, 2007
Posts: 1330
Location: Florida, USA
Audio files: 52

PostPosted: Wed Jan 23, 2008 7:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Kassen, that's the boost I needed to write the sequencer for our math and music project. Now it plays all six pieces.


ChucK.ck
 Description:
super simple sequencer for ChucK math and music project.

Download
 Filename:  ChucK.ck
 Filesize:  564 Bytes
 Downloaded:  18 Time(s)

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 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

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003, 2004, 2005, 2006 and 2007 by electro-music.com