back to list

[tuning] Scala sequence file note frequency in hertz?

🔗Marcel de Velde <m.develde@...>

12/8/2009 10:50:05 AM

I'm bussy writing an algorithm that automatically generates Just Intonation
chord progressions.
I've just finished the most simple form of my algorithm, it outputs a scala
sequence file with notes specified in frequency between parentheses.
Like this for instance:
5280 note (505.679012) 480
5760 note (568.888889) 480

Now I thought when one specifies note (xx.xx) that one is giving the
frequency in hertz to be played.
Yet Scala renders nonsense pitches in the output when I do "transform
sequence to midi file", and I can't figure out why.
Am I wrong in thinking "note (xx.xx)" is for note pitches in hertz?
Or did I do something else wrong?
Or is this a bug in Scala?

Any help would be greatly apreciated as this one is driving me crazy.
I really want to hear the output of my algorithm.

Many thanks!
Marcel

🔗Petr Parízek <p.parizek@...>

12/8/2009 11:10:03 AM

Hi Marcel.

If you use decimal points, then these are cents, not ratios.

Petr

🔗Marcel de Velde <m.develde@...>

12/8/2009 2:06:49 PM

Hi Petr,

If you use decimal points, then these are cents, not ratios.
>
> Petr
>

Yes you are right.
Thank you!

I wanted to write the frequency in Hertz, but it seems that this can't be
done in the "note" statement.
I've come up with the following solution by using the frequency statement:
0 frequency 300.000000
0 note c 480
480 frequency 166.666667
480 note c 480
960 frequency 250.000000
960 note c 1440
2400 frequency 187.500000
2400 note c 480
2880 frequency 266.666667
2880 note c 480
3360 frequency 250.000000
3360 note c 960

Works perfectly now :)
Will post the first algorithm and a few mp3 files soon.

Marcel

🔗Marcel de Velde <m.develde@...>

12/8/2009 5:20:11 PM

The most messy code ever written (I'm not a programmer) but it's working :)
Here the first output of my algorithm for those interested.

http://www.develde.net/

It's completely random only following certain basic harmonic and modulation
rules comming from my harmonic permuation JI theory.
The 5limit output is most interesting for now.
The 6limit output I still have to limit the permutations a bit in certain
ways as right now it gives ugly chromatic voices making the melodies too
hard to follow through all this random movement.
Will write more interesting and musical algorithms soon.

Marcel

🔗Petr Parízek <p.parizek@...>

12/8/2009 9:12:59 PM

Marcel wrote:

> I wanted to write the frequency in Hertz, but it seems that this can't be done
> in the "note" statement.

Why should absolute frequencies be better than frequency ratios?

> I've come up with the following solution by using the frequency statement:

Wow, let me laugh a bit, this is really weird! :-D I've never ever seen a sequence file like this. But ... Well, you've got what you wanted, of course, that's undeniable.

Petr

🔗Marcel de Velde <m.develde@...>

12/8/2009 9:26:17 PM

> Why should absolute frequencies be better than frequency ratios?
>

It was easyer for me to write the algorithm this way.
It modulates randomly all over the place and the ratios could get really
big.
This way I don't have to do a lot of math for the ratios but simply use the
previous chord to calculate the frequencies of the current chord.

> I've come up with the following solution by using the frequency statement:
>
> Wow, let me laugh a bit, this is really weird! :-D I’ve never ever seen a
> sequence file like this. But ... Well, you’ve got what you wanted, of
> course, that’s undeniable.
>
> Petr
>
Hehe yeah it looks weird indeed :)
Looks like Scala's sequence format wasn't ment for this. But the great thing
about Scala is that even if it wasn't ment for something in advance there's
usually a way to still do it! Love Scala!

I put an mp3 up on my site www.develde.net of the algorithm output which I
optimised a bit just now.
It sounds like real music to me :)

Marcel

🔗Petr Parízek <p.parizek@...>

12/8/2009 9:49:35 PM

> It modulates randomly all over the place and the ratios could get really big.
> This way I don't have to do a lot of math for the ratios but simply use the previous chord to
> calculate the frequencies of the current chord.

Hmmm, .. I don’t know; I sttill think ratios allow much greater versatility than absolute frequencies do. For example, if we decide for a starting frequency of 90Hz and we want to use 166.6667Hz in the piece, then the first thing which comes to my mind is the fact that the frequency in question could be multiplied by 3 and therefore the entire ratio could be multiplied by 3, which would result in 500/270, and it’s just upon your own choice if you decide to write 500/270 or 50/27. Similarly, if the fractional part of an absolute frequency value ends with something like „142857142857..“ or „857142857142“, then the first thing which comes to my mind (I mean, without any great thinking, it just pops up in my head) is that I can multiply the ratio by 7.

> I put an mp3 up on my site www.develde.net of the algorithm output which I optimised
> a bit just now.

Thanx, maybe I’ll get some time for it during the weekend.

Petr

🔗Marcel de Velde <m.develde@...>

12/8/2009 10:17:29 PM

> Hmmm, .. I don’t know; I sttill think ratios allow much greater versatility
> than absolute frequencies do. For example, if we decide for a starting
> frequency of 90Hz and we want to use 166.6667Hz in the piece, then the first
> thing which comes to my mind is the fact that the frequency in question
> could be multiplied by 3 and therefore the entire ratio could be multiplied
> by 3, which would result in 500/270, and it’s just upon your own choice if
> you decide to write 500/270 or 50/27. Similarly, if the fractional part of
> an absolute frequency value ends with something like „142857142857..“ or
> „857142857142“, then the first thing which comes to my mind (I mean, without
> any great thinking, it just pops up in my head) is that I can multiply the
> ratio by 7.

Yes you're right.
It doesn't much matter in the end.
Except, for ratios i'd have to use 2 variables to store it and work with it.
For frequencies only one.
I have to work with a seperate permutation array anyway because of how the
algorithm works.

Btw I'm making a php page where one can control many aspects of the
algorithm, and hope to make many outputs available in several formats, also
direct midi tuned by pitchbends.
In time hope to make a sourceforge project out of it where several people
can collaborate on working on the algorithm.
Perhaps you'd be interested too? :)
I'll let know when I've gotten a bit further with it.

Marcel

🔗Mike Battaglia <battaglia01@...>

12/9/2009 4:00:25 AM

>
> Btw I'm making a php page where one can control many aspects of the
> algorithm, and hope to make many outputs available in several formats, also
> direct midi tuned by pitchbends.
> In time hope to make a sourceforge project out of it where several people
> can collaborate on working on the algorithm.
> Perhaps you'd be interested too? :)
> I'll let know when I've gotten a bit further with it.
>

I am certainly interested. I wrote a javascript MIDI library a while ago
actually that operates on data URIs and might be suited for this purpose,
unless a free and easy PHP MIDI library is already available.

But seriously man, what are you doing here? I'd love to see this algorithm.
It sounds great and I'd love to see if it can be extended to 7-limit just or
tempered tunings as well. It seems like you have a predefined list of
chords, and that you just move from each chord to a random adjacent one with
a common tone, but with some rules (V always goes to I, etc) while figuring
out the voice leading on the spot. It would be neat to extend that to some
of the more interesting chords I like to use in plain old simple 12-tet.

The truly remarkable thing about this is that you have created a very clever
algorithm for a computer to generate fluid-sounding and natural chord
progressions, microtonal or not -- it would be nice to hear an explanation
of how your algorithm works at least.

🔗Marcel de Velde <m.develde@...>

12/9/2009 12:42:23 PM

Hi Mike,

I am certainly interested. I wrote a javascript MIDI library a while ago
> actually that operates on data URIs and might be suited for this purpose,
> unless a free and easy PHP MIDI library is already available.
>

Ok great! :)
It's my greatest wish to work together with people on this.
I just did it in php now because i did a few things in it many years ago so
was atleast a bit familiar, and php.net is a great help in figuring out how
to write something.
But javascript is fine too.
I do belief that php also has a midi output 3rd party script, i one ran
across it but haven't looked for it again yet.

> But seriously man, what are you doing here? I'd love to see this algorithm.
> It sounds great and I'd love to see if it can be extended to 7-limit just or
> tempered tunings as well.
>

In time I think it can be extended to 7-limit, it's all about permutation
rules.
For tempered tunings, it seems possible but the basis of the algorithm is
JI. Take away the JI and there is no algorithm as it's all about the pure
harmonic series and it's permutations.
But one can offcourse temper the output of the algorithm after it has
generated the music.

> It seems like you have a predefined list of chords, and that you just move
> from each chord to a random adjacent one with a common tone, but with some
> rules (V always goes to I, etc) while figuring out the voice leading on the
> spot.
>

Yes right now there's a sort of predefined list of chords, as there are only
a limited number of permutations possible.
But no functional hamonic rules yet whatsoever :) These can easily come
later though.
Also right now there's no use of octave equivalence, and it's not using all
the permutations possible yet (will write more permutation possibilities
soon), it's ony the first attempt to write some of my theory in an
algorithm, and a rushed attempt.
Also right now it only does "pure" permutations but no combinations of
permutations (which will expand the possible number of chords to almost
infinite), as I don't yet know exactly how this works and how to make sense
of it. I do know that the individual voices are very important and can think
of some rules to allow infinite chords and octave equivalence while keep
voices pure diatonic etc but it gets very difficult here, something for
later.

> It would be neat to extend that to some of the more interesting chords I
> like to use in plain old simple 12-tet.
>

It can do it :) But later.

>
> The truly remarkable thing about this is that you have created a very
> clever algorithm for a computer to generate fluid-sounding and natural chord
> progressions, microtonal or not -- it would be nice to hear an explanation
> of how your algorithm works at least.
>

I'm making the website that explain the theory and the algorithm etc soon.
(but first next few days I wish to impement a few more things in the
algorithm and make a few more songs)
I can't paste it all here and have it make sense.
I'll do so anyhow, but I warn you it's messy :) (and very incomplete
according to my theory)

Here it comes:

<?php

$num_chords = 720;
$harm_limit = 5;
$v1_start_freq = 100;
$low_freq = 73;
$high_freq = 940;
$tempo = 128;
$notelength = 480;

$harmony[0][0] = $v1_start_freq;
$hold[0][0] = 1;
for ($i = 1; $i < $harm_limit; $i++) {
$harmony[0][$i] = $v1_start_freq * ($i +1);
$hold[0][$i] = 1;
}

for ($i = 1; $i < $num_chords; $i++) {
$permseed = range(2, $harm_limit);
shuffle($permseed);
$permchord[0] = 1;
$permutation = 1;
foreach ($permseed as $perm) {
$permprev = $permutation - 1;
$permdiv = $perm - 1;
$permchord[$permutation] = ($permchord[$permprev] / $permdiv ) *
$perm;
$permutation++;
}
$modvoice = rand(0, ($harm_limit -1));
$modfactor = $harmony[$i-1][$modvoice] / $permchord[$modvoice];
$v = 0;
foreach ($permchord as $permvoice) {
$harmony[$i][$v] = $permvoice * $modfactor;
$hold[$i][$v] = 1;
$prev = $i -1;
if ( $harmony[$i][$v] == $harmony[$prev][$v]) {
$hold[$i][$v] = 0;
}
$v++;
}
if ($harmony[$i][0] < $low_freq) {
$i--;
}
if ($harmony[$i][$harm_limit-1] > $high_freq) {
$i--;
}
}
for ($v = $harm_limit -1; $v >= 0; $v--) {
$holdcount = 1;
for ($i = $num_chords -1; $i >= 0; $i--) {
if ($hold[$i][$v] == 1) {
$hold[$i][$v] = $holdcount;
$holdcount = 1;
}
if ($hold[$i][$v] == 0) {
$holdcount++;
}
}
}
for ($v = 0; $v < $harm_limit; $v++) {
$track = $v +1;
echo "0 track $track\n";
echo "0 program 58\n";
for ($i = 0; $i < $num_chords; $i++) {
if ($hold[$i][$v] != 0) {
$holdnotelength = $notelength * $hold[$i][$v];
$seq_measure = $i * 480;
echo $seq_measure ." frequency ";
printf("%f", $harmony[$i][$v]);
echo "\n";
echo $seq_measure ." note c $holdnotelength\n";
}
}
echo "\n";
}
?>

This is the one that generated the mp3.
Again, it's messy, incomplete and written fast just to give an output that I
can hear soon. It's not a good representation of my theory yet.
Ohyeah and don't mind the variable names, i was feeling a bit silly :p
But I think it'd be better to wait a few weeks till i have the site ready
that will explain everything in an easy to understand way.
And I'll have thought of good ways to work together with people on this.
Though if you allready have ideas and suggestions be free to share! :)

Marcel

🔗Graham Breed <gbreed@...>

12/10/2009 4:02:41 AM

Marcel de Velde <m.develde@...> wrote:

> if ($harmony[$i][0] < $low_freq) {
> $i--;
> }
> if ($harmony[$i][$harm_limit-1] > $high_freq) {
> $i--;
> }

Shouldn't the array be sorted at this point?

Anyway, for whatever it's worth, I re-wrote the script in
Python:

http://x31eq.com/marcel.py

I don't know if it's working right but it outputs something
that looks valid.

Graham

🔗Marcel de Velde <m.develde@...>

12/10/2009 5:42:00 AM

Hi Graham,

> if ($harmony[$i][0] < $low_freq) {
> > $i--;
> > }
> > if ($harmony[$i][$harm_limit-1] > $high_freq) {
> > $i--;
> > }
>
> Shouldn't the array be sorted at this point?
>

This part only checks wether the lowest voice isn't lower than the given
$low_freq and then if the highest voice isn't higher than the given
$high_freq
If one of the voices in this chord is indeed too low or too high it simply
does $i-- and starts building a random chord again, this loop continues till
the chord "behaves" and isn't either too low or too high anymore.
I set the $low_freq to 73 hertz and the $high_freq to 940 hertz because the
choir sound I used doesn't go any lower or higher.
I have no idea what sorting an array means :) I'm not really a programmer as
you can see hehe.

>
> Anyway, for whatever it's worth, I re-wrote the script in
> Python:
>
> http://x31eq.com/marcel.py
>
> I don't know if it's working right but it outputs something
> that looks valid.
>
> Graham

Ok wow thanks, and congratulations you could convert it.
I'll go figure out how to run a python script later today.
To check the output simply copy paste it to a scala sequence file and use
scala to convert it to a midi file.
(btw if you're running the php version in a browser you need to look at the
generated page source and copy paste this)
The .scl file only needs a head. I used this one:

0 exclude 10
0 tempo 120 pm
0 velocity 96
0 frequency 261.626
0 notation E12
0 text "Harmonic Permutation JI Algorithm Output, Marcel de Velde,
Zwolle, 8 dec 2009"
!

Below this paste the output of the algorithm and it should give random
music.

btw I'm curious what the sorting of the array does in your script.
And why did you think it was needed?

Marcel

🔗Graham Breed <gbreed@...>

12/10/2009 6:55:17 AM

Marcel de Velde <m.develde@...> wrote:

> btw I'm curious what the sorting of the array does in
> your script. And why did you think it was needed?

It makes sure the first note in the chord is the lowest,
and the last note is the highest. I don't see how else
this is done.

I'll look at other things tomorrow.

Graham

🔗Marcel de Velde <m.develde@...>

12/10/2009 1:29:24 PM

> It makes sure the first note in the chord is the lowest,
> and the last note is the highest. I don't see how else
> this is done.
>

It is allready the automatic result, no sorting needed for this.
There are several ways to write the permutations I wanted, but I wrote it
the way that first the permutated chord is built, and then the whole chord
is pitched to the correct frequency.
The php script I posted works perfectly (as long as one doesn't set an
impossible low or high_freq or voice1 start frequency)
It is the exact code that generated the output I made the mp3 of that I
posted.

Marcel

🔗Graham Breed <gbreed@...>

12/10/2009 11:21:48 PM

Marcel de Velde <m.develde@...> wrote:

> It is allready the automatic result, no sorting needed
> for this. <snip>

Yes, I was wrong. The chords are always in ascending order.

Graham