#include #include "patron.h" note_val next_note(position pos, score *sc, int track) { unsigned char ii, n = track; for (ii = 0; ii != 4; ii++) { unsigned char idx = pos & 3; pos >>= 2; n = (*sc)[ii][n & width_mask][idx]; } return n; } void generate_score(score *sc) { unsigned char ii, jj, kk; for (ii = 0; ii != 4; ii++) { for (jj = 0; jj != width; jj++) { for (kk = 0; kk != 4; kk++) { (*sc)[ii][jj][kk] = rand() >> 8; } } } } void mutate_score(score *sc) { unsigned char ii = rand(), jj = rand(), kk = rand(); (*sc)[ii & 3][jj & width_mask][kk & 3] = rand() >> 8; } // Interpret a note_val as a frequency, // within a couple of octaves /* Use the first 8 of these: >>> [int(round(256 * 2**((x * 7 % 24)/12.0))) for x in range(25)] [256, 384, 575, 861, 323, 483, 724, 271, 406, 609, 912, 342, 512, 767, 287, 431, 645, 967, 362, 542, 813, 304, 456, 683, 256] */ int freq(note_val n) { static int table[] = { 256, 384, 575, 861, 323, 483, 724, 271, 406, 609, 912, 342, 512, 767, 287, 431, 645, 967, 362, 542, 813, 304, 456, 683, 256 }; if (!(n & 8)) return 0; // silence ½ of the time return table[n & 7]; }