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 
 Forum index » DIY Hardware and Software » ChucK programming language
how to play 2 notes contemporaneous?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
fraukefroehlich



Joined: May 11, 2007
Posts: 22
Location: home
Audio files: 1

PostPosted: Mon Jun 02, 2008 9:57 am    Post subject:  how to play 2 notes contemporaneous? Reply with quote  Mark this post and the followings unread

hello there,

just wanted to know, how to produce two sounds on one instrument simultaneously, or if it's even possible.

thx
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Mon Jun 02, 2008 12:38 pm    Post subject: Reply with quote  Mark this post and the followings unread

hmm.. basically you need more than 1 generators to do that.
one tidy way is to make an array of the UGens you wanna play,
and chuck it to the same place to combine all the signals.

If it's an STK instrument, it's gonna be quite convenient,
because with noteOn and noteOff, that'd dp the amplitude enveloping (attack and release) automatically for you.

but if you're using more basic oscillators,
you might have to connect to some more filters and amplitude envelopes.
that also depends on how much you want to control the whole sound.

let's talk about this some more.
i'll write some small examples for this:
- - -

Three SawOscs
Code:
[[0,3,7],[2,5,10],[3,7,12],[2,5,10]] @=> int melody1[][];
57 => int BaseNote;

140.0 => float BPM;
minute / BPM => dur Beat;

SawOsc s[3]; // build a set of saw oscillators
Gain mix => dac; // mix of all the oscillators
.3 => mix.gain; // set overall mix gain
for(int i; i < s.cap(); i++)
{
    s[i] => mix; // connect each oscillator to the mix
}

while(true)
{
    for(int i; i < melody1.cap(); i++) // for each step in the sequencer
    {
        for(int j; j < melody1[i].cap(); j++) // for each oscillator
        {
            // assign frequency to the oscillator
            Std.mtof(BaseNote + melody1[i][j]) => s[j].freq;       
        }
        .25::Beat => now; // play 16-note
    }   
}

note: see how i create SawOsc as an array and connect each of them,
see how I loop and update frequency of each oscillator in each 16 note.
- - -

Code:
[[0,3,7],[2,5,10],[3,7,12],[2,5,10]] @=> int melody1[][];
57 => int BaseNote;

140.0 => float BPM;
minute / BPM => dur Beat;

SawOsc s[3]; // build a set of saw oscillators
Envelope lpf_freq => blackhole; // a value for a lowpass filter frequency
Gain mix => LPF filter => dac; // mix of all the oscillators

.3 => mix.gain; // set overall mix gain
1 => filter.Q; // set lowpass filter's Q
.06 => lpf_freq.time; // set envelope decay time

for(int i; i < s.cap(); i++)
{
    s[i] => mix; // connect each oscillator to the mix
}


spork ~ update(); // update control values

while(true)
{
    for(int i; i < melody1.cap(); i++) // for each step in the sequencer
    {
        for(int j; j < melody1[i].cap(); j++) // for each oscillator
        {
            // assign frequency to the oscillator
            Std.mtof(BaseNote + melody1[i][j]) => s[j].freq;       
        }
        1 => lpf_freq.value;
        lpf_freq.keyOff();
        .25::Beat => now; // play 16-note
    }   
}

fun void update()
{
    while(true)
    {
        lpf_freq.value() * 2000 + 10 => filter.freq; // update filter freq
        ms => now; // control rate
    }
}


This one has filter and filter freq envelope also.
the filter is applied to the mix of all the signals from all oscillators.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
fraukefroehlich



Joined: May 11, 2007
Posts: 22
Location: home
Audio files: 1

PostPosted: Mon Jun 02, 2008 10:47 pm    Post subject: Reply with quote  Mark this post and the followings unread

kijjaz wrote:
hmm.. basically you need more than 1 generators to do that.
one tidy way is to make an array of the UGens you wanna play,
and chuck it to the same place to combine all the signals.

good idea, i'll try that...
Quote:

If it's an STK instrument, it's gonna be quite convenient,
because with noteOn and noteOff, that'd dp the amplitude enveloping (attack and release) automatically for you.

yeah, i'm gonna use stk instruments, so i think it's gonna be a bit easier with less code lines...

one thing i don't understand is your array assignment in the first line of your code... what does this array look like?
Quote:

Three SawOscs
Code:
[[0,3,7],[2,5,10],[3,7,12],[2,5,10]] @=> int melody1[][];


as i see it, you put 4 vectors with 3 elements each into a 2-dim array..? i'm really not sure what that's gonna look like...
the rest, though, seems very simple... i try to get things to work... afterwards i'll show you.

thx 4 help!
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Mon Jun 02, 2008 11:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

I designed the intrument to be a trio playing a harmony (or chords) to form a polysynth choir hahah -_-"
So I was finding a way to easily key in series of notes.

There, I have a 2D int array..
those 4 units in there are 4 chords I'd like to play,
and each chord has 3 notes (assigning to 3 oscillators each time)

now I have base note = 57 which is A

[0,3,7] are the notes that are going to be added with the base note,
so the first chord would be 0+57, 3+57, 7+57 in midi note
= 57, 60, 6f = A C' E' thus forming an A minor triad.

It's just one easy way to put in notes for chords.
One thing that is convenience is that..
we can supply less number of values if we don't need to give to the rest of the oscs,
for example..

Code:
[[0,3,12],[2-12],[0-12],[-2-12],[-5-12,5],[-5],[2],[-2,7,10]] @=> int melody1[][];
57 => int BaseNote;

140.0 => float BPM;
minute / BPM => dur Beat;

SawOsc s[3]; // build a set of saw oscillators
Envelope lpf_freq => blackhole; // a value for a lowpass filter frequency
Gain mix => LPF filter => dac; // mix of all the oscillators

.3 => mix.gain; // set overall mix gain
1 => filter.Q; // set lowpass filter's Q
.06 => lpf_freq.time; // set envelope decay time

for(int i; i < s.cap(); i++)
{
    s[i] => mix; // connect each oscillator to the mix
}


spork ~ update(); // update control values

while(true)
{
    for(int i; i < melody1.cap(); i++) // for each step in the sequencer
    {
        for(int j; j < melody1[i].cap(); j++) // for each oscillator
        {
            // assign frequency to the oscillator
            Std.mtof(BaseNote + melody1[i][j]) => s[j].freq;       
        }
        1 => lpf_freq.value;
        lpf_freq.keyOff();
        .25::Beat => now; // play 16-note
    }   
}

fun void update()
{
    while(true)
    {
        lpf_freq.value() * 2000 + 10 => filter.freq; // update filter freq
        ms => now; // control rate
    }
}


this is the same example,
put the melody array has more notes,
and some notes has only 1-2 members (not all 3)
so that the for j loop will read and execute for only the first oscillators,
thus sustaining other notes at the same value.

This one I move the first osc a lot to create a bass line.

You can try this array also:

Code:
int A[0];

[[0,3,12],[-12],A,A,
A,A,A,A,
A,A,A,[0-12],
[-2-12],[-5-12,5],[-5],[2],[-2,7,10]] @=> int melody1[][];

Those referring to A is to an int array with no members hahaahh.
so there won't be any change in the notes of the oscillators.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
fraukefroehlich



Joined: May 11, 2007
Posts: 22
Location: home
Audio files: 1

PostPosted: Fri Jun 06, 2008 2:29 am    Post subject: Reply with quote  Mark this post and the followings unread

ok... i have now finished lab3 for audio lecture.

goal was to chuck an algorithmic composition using cellular automata and markov chains.
the cellular automata defines the notes being played. it's rule changes periodically and a random value determines which rule applies next. => the melody is different every time the prog is launched.

the markov chain with its probabilities determines the length of notes or pauses.

for now i'll just post one result of the code i wrote, since the deadline is 13. of june and i don't want my code to be copied. after that date i'll post the code and maybe we can discuss it a little.

cheers


secondTry.wav.ff.mp3
 Description:

Download (listen)
 Filename:  secondTry.wav.ff.mp3
 Filesize:  1.39 MB
 Downloaded:  587 Time(s)


_________________
u said it man... nobody chucks with the jesus...
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 [5 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