Skip to content

Instantly share code, notes, and snippets.

@AliceLR
Last active September 22, 2021 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AliceLR/4ed73d569852311e922d8c3a953bae86 to your computer and use it in GitHub Desktop.
Save AliceLR/4ed73d569852311e922d8c3a953bae86 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import math
import random
totalnotes = 256;
def clamp(n,mn,mx):
return max(mn,min(mx,n));
def fixperiod(p):
# Attenuation/period values seem to be inverted like with other Yamaha chips.
# Alternatively, BEX does this itself for convenience...
# High values overflow (but always seem to be the highest period?).
p = ~clamp(p, 0, 1024) & 1023;
# Note: clamping to >44 to prevent ear destroying pitches.
return clamp(p, 44, 1023);
def periodtofreqNTSC(p):
return (3479545.0 / 32.0) / fixperiod(p);
def periodtofreqPAL(p):
return (3546894.93 / 32.0) / fixperiod(p);
def freqtonote(f):
return round(12.0 * math.log2(f / 440)) + 48 + 9;
notes = [ 'C-', 'C#', 'D-', 'D#', 'E-', 'F-', 'F#', 'G-', 'G#', 'A-', 'A#', 'B-' ];
def notestr(n):
return notes[n % 12] + str(clamp(n // 12, 1, 8));
def PSGtoMPT(p, prev):
n = notestr(freqtonote(periodtofreqPAL(p))) + '01';
return [ n == prev and '.....' or n, n ];
def rnd(n):
return random.randrange(n) + 1;
print('ModPlug Tracker IT');
prev0 = '';
prev1 = '';
prev2 = '';
for i in range(totalnotes):
# Title.
p0 = rnd(40) * 10 + 500;
p1 = rnd(40) * 10 + 600;
p2 = rnd(40) * 10 + 700;
# Selection screen.
#p0 = rnd(40) * 10 + 200;
#p1 = rnd(40) * 10 + 250;
#p2 = rnd(40) * 10 + 325;
[s0, prev0] = PSGtoMPT(p0, prev0);
[s1, prev1] = PSGtoMPT(p1, prev1);
[s2, prev2] = PSGtoMPT(p2, prev2);
print('|' + s0 + '......|' + s1 + '......|' + s2 + '......');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment