| Author |
Message |
kijjaz

Joined: Sep 20, 2004 Posts: 409 Location: bangkok, thailand
Audio files: 2
|
Posted: Sat Nov 18, 2006 2:31 pm Post subject:
Preparing a Class to use as a sound player for sequencing |
 |
|
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  |
|
|
Back to top
|
|
 |
jimmysword

Joined: Jan 11, 2008 Posts: 12 Location: Leeds, W Yorks
|
Posted: Wed Jan 23, 2008 8:01 am Post subject:
|
 |
|
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  |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 5961 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Jan 23, 2008 11:39 am Post subject:
|
 |
|
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. _________________ while(!machine.crash() ) <<<"all is well">>>; |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Wed Jan 23, 2008 2:26 pm Post subject:
|
 |
|
| 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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 5961 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Jan 23, 2008 5:32 pm Post subject:
|
 |
|
| 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. _________________ while(!machine.crash() ) <<<"all is well">>>; |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
|
|
Back to top
|
|
 |
|