Author |
Message |
jeff harrington

Joined: Nov 08, 2003 Posts: 84 Location: Brooklyn
|
Posted: Fri Apr 06, 2007 8:15 am Post subject:
Microtuning and Best Practices Approach |
 |
|
Hi, learning chuck - and really interested in realizing microtonal music with its great phymod instruments.
What's the best way to express say a 19ET tuning so that I could give it a MIDI file (expressed as 12ET) and have it render it appropriately. Some type of remapping of the pitchs to the 0-127 space etc? Any code examples would be much appreciated...
jeff _________________ music
portal
blog |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Apr 06, 2007 9:51 am Post subject:
|
 |
|
Hi, Jeff!
The easiest way to go about this would likely be a array. You'd have to create a array of 128 locations (one per note) that would hold a floatingpoint number that expressed the amount of Hz that note has in your tuning.
You would then use your notenumber to point at a location in that array, that would be quite easy and is basically covered by the manual section on arrays.
Right now our "mtof' (Midi note TO Frequency) converter only supports equal-temperd conventional tuning. I could imagine a future update to that, maybe even to be able to load Scala files.
There's more on dealing with notes and mapping to pitch here;
http://electro-music.com/forum/topic-14051.html
That might be interesting as well?
I'm not at all sure about loading MIDI files, I don't think you can. You could however use a MIDI loopback-driver with a extrenal MID player.
 _________________ Kassen |
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Fri Apr 06, 2007 11:16 am Post subject:
|
 |
|
For 19 tone equal temperament
i have one simple idea for implementing with Std.mtof function..
Let's say.. we have a root note (.. for example starting on C, midi number = 60)
i can generate an array containing the frequency of all notes in the 19-tone ET
by this: (starting from middle C)
Code: | float Scale19ET[19];
for(int i; i < 19; i++) Std.mtof(i $ float / 19 * 12 + 60) => Scale19ET[i];
|
so now we'll have an array containing those frequency values ready to use.
but it's just one octave. we can expand it quite easily to cover other octaves
by multiplying or deviding by 2 for each octave up or down.
..
another way to create a function for 19ET's frequency.
Code: | fun float Freq19ET(float BaseFreq, float NoteNumber, int Octave) {
return BaseFreq * Math.pow(2.0, NoteNumber / 19 + Octave);
} |
this might be an easier and less-code solution for a frequency-generating function.
now let's build an array that will link 12ET midi number to the 19 tones.
Code: | [0, 1, 3, 5, 6, 8, 10, 12, 13, 15, 16, 18] @=> int ScaleMapping1[]; |
and set up a melody line ..
Code: | [0, 4, 7, 8, 9, 8, 11, 8] @=> int Melody1[]; |
then try playing them with a Triangle Wave Oscillator:
Code: | // let's combine the whole code
fun float Freq19ET(float BaseFreq, float NoteNumber, int Octave) {
return BaseFreq * Math.pow(2.0, NoteNumber / 19 + Octave);
}
[0, 1, 3, 5, 6, 8, 10, 12, 13, 15, 16, 18] @=> int ScaleMapping1[];
[0, 4, 7, 8, 9, 8, 11, 8] @=> int Melody1[];
TriOsc s => dac;
0.5 => s.gain;
140.0 => float BPM;
minute / BPM => dur Beat;
// let's use middle C (midi number 60) as the base freq
Std.mtof(60) => float BaseFreq;
for(int i; i < Melody1.cap(); i++) {
Freq19ET(BaseFreq, ScaleMapping1[Melody1[i]], 0) => s.freq;
Beat => now;
} |
|
|
Back to top
|
|
 |
jeff harrington

Joined: Nov 08, 2003 Posts: 84 Location: Brooklyn
|
Posted: Fri Apr 06, 2007 11:35 am Post subject:
|
 |
|
Kassen wrote: | Hi, Jeff!
The easiest way to go about this would likely be a array. You'd have to create a array of 128 locations (one per note) that would hold a floatingpoint number that expressed the amount of Hz that note has in your tuning.
You would then use your notenumber to point at a location in that array, that would be quite easy and is basically covered by the manual section on arrays.
Right now our "mtof' (Midi note TO Frequency) converter only supports equal-temperd conventional tuning. I could imagine a future update to that, maybe even to be able to load Scala files.
There's more on dealing with notes and mapping to pitch here;
http://electro-music.com/forum/topic-14051.html
That might be interesting as well?
I'm not at all sure about loading MIDI files, I don't think you can. You could however use a MIDI loopback-driver with a extrenal MID player.
 |
That sounds like a good working method. I generally write to my old TG77 which has great microtuning support - with Sibelius and then when I'm ready I'll use a loopback-driver to play it for final release.
Thanks for the Welcome and the info...
Jeff _________________ music
portal
blog |
|
Back to top
|
|
 |
jeff harrington

Joined: Nov 08, 2003 Posts: 84 Location: Brooklyn
|
Posted: Fri Apr 06, 2007 11:39 am Post subject:
|
 |
|
kijjaz wrote: | For 19 tone equal temperament
i have one simple idea for implementing with Std.mtof function..
Let's say.. we have a root note (.. for example starting on C, midi number = 60)
i can generate an array containing the frequency of all notes in the 19-tone ET
by this: (starting from middle C)
Code: | float Scale19ET[19];
for(int i; i <19> Scale19ET[i];
|
so now we'll have an array containing those frequency values ready to use.
but it's just one octave. we can expand it quite easily to cover other octaves
by multiplying or deviding by 2 for each octave up or down.
..
another way to create a function for 19ET's frequency.
Code: | fun float Freq19ET(float BaseFreq, float NoteNumber, int Octave) {
return BaseFreq * Math.pow(2.0, NoteNumber / 19 + Octave);
} |
this might be an easier and less-code solution for a frequency-generating function.
now let's build an array that will link 12ET midi number to the 19 tones.
Code: | [0, 1, 3, 5, 6, 8, 10, 12, 13, 15, 16, 18] @=> int ScaleMapping1[]; |
and set up a melody line ..
Code: | [0, 4, 7, 8, 9, 8, 11, 8] @=> int Melody1[]; |
then try playing them with a Triangle Wave Oscillator:
Code: | // let's combine the whole code
fun float Freq19ET(float BaseFreq, float NoteNumber, int Octave) {
return BaseFreq * Math.pow(2.0, NoteNumber / 19 + Octave);
}
[0, 1, 3, 5, 6, 8, 10, 12, 13, 15, 16, 18] @=> int ScaleMapping1[];
[0, 4, 7, 8, 9, 8, 11, 8] @=> int Melody1[];
TriOsc s => dac;
0.5 => s.gain;
140.0 => float BPM;
minute / BPM => dur Beat;
// let's use middle C (midi number 60) as the base freq
Std.mtof(60) => float BaseFreq;
for(int i; i <Melody1> s.freq;
Beat => now;
} |
|
Excellent kijjaz! I like to get (or find) some code snippets before I dive in, especially working ones (Thanks!) and then I don't waste time looking how to express basic stupid crap from the basic but very dark corners of a new language that I never got around to reading in the spec. I appreciate the snippetage.
Jeff _________________ music
portal
blog |
|
Back to top
|
|
 |
seraph
Editor


Joined: Jun 21, 2003 Posts: 12398 Location: Firenze, Italy
Audio files: 33
G2 patch files: 2
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Apr 06, 2007 12:03 pm Post subject:
|
 |
|
jeff harrington wrote: | and then I don't waste time looking how to express basic stupid crap from the basic but very dark corners of a new language that I never got around to reading in the spec. |
Fortunately it's quite possible to learn ChucK by poking around in the examples.
One thing you could do is go over the array examples, then make one that expresses your scale. You could take that to the examples that deal with the physical modeling instruments and replace all instances of "mtof" (it gets used quite a lot) with your own array; both would act like a lookup table so they are almost interchangable aside from arrays having square brackets and mtof (being a function) having round ones.
Going through that and maybe MIDI in the example section should give you all the tools you need without ever touching a manual or specification. At that point the "basic stupid crap" will likely be under controll and you'll know what to look for in the manual to improve your little program further. _________________ Kassen |
|
Back to top
|
|
 |
|