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 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
Microtuning and Best Practices Approach
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jeff harrington



Joined: Nov 08, 2003
Posts: 84
Location: Brooklyn

PostPosted: Fri Apr 06, 2007 8:15 am    Post subject: Microtuning and Best Practices Approach Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website AIM Address
Kassen
Janitor
Janitor


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

PostPosted: Fri Apr 06, 2007 9:51 am    Post subject: Reply with quote  Mark this post and the followings unread

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.
welcome

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



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

PostPosted: Fri Apr 06, 2007 11:16 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
jeff harrington



Joined: Nov 08, 2003
Posts: 84
Location: Brooklyn

PostPosted: Fri Apr 06, 2007 11:35 am    Post subject: Reply with quote  Mark this post and the followings unread

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.
welcome


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... Wink

Jeff

_________________
music
portal
blog
Back to top
View user's profile Send private message Visit poster's website AIM Address
jeff harrington



Joined: Nov 08, 2003
Posts: 84
Location: Brooklyn

PostPosted: Fri Apr 06, 2007 11:39 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website AIM Address
seraph
Editor
Editor


Joined: Jun 21, 2003
Posts: 12398
Location: Firenze, Italy
Audio files: 33
G2 patch files: 2

PostPosted: Fri Apr 06, 2007 12:02 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi Jeff
I am writing only to say that a new sub forum and a link section about microtuning have been created:
http://electro-music.com/forum/forum-147.html
http://electro-music.com/forum/links.php?id=31
p.s.
did you know we both are featured on this list?
http://xenharmonic.wikispaces.com/MicrotonalListeningList
Very Happy

_________________
homepage - blog - forum - youtube

Quote:
Don't die with your music still in you - Wayne Dyer
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


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

PostPosted: Fri Apr 06, 2007 12:03 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
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 [7 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