| Author |
Message |
fraukefroehlich
Joined: May 11, 2007 Posts: 22 Location: home
Audio files: 1
|
Posted: Mon Jun 02, 2008 9:57 am Post subject:
how to play 2 notes contemporaneous? |
 |
|
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
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Mon Jun 02, 2008 12:38 pm Post subject:
|
 |
|
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
|
|
 |
fraukefroehlich
Joined: May 11, 2007 Posts: 22 Location: home
Audio files: 1
|
Posted: Mon Jun 02, 2008 10:47 pm Post subject:
|
 |
|
| 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
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Mon Jun 02, 2008 11:49 pm Post subject:
|
 |
|
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
|
|
 |
fraukefroehlich
Joined: May 11, 2007 Posts: 22 Location: home
Audio files: 1
|
|
|
Back to top
|
|
 |
|