1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-22 12:30:01 +00:00

POKEY music

This commit is contained in:
Steven Hugg 2017-04-20 09:45:35 -04:00
parent 29117e7cb6
commit 2ac80509f7
4 changed files with 121 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -191,16 +191,16 @@ var POKEYDeviceChannel = function() {
if (d > 0 && d < 1 && v > 0) {
var wav = waveforms[i];
var cnt = counters[i] += d;
if (cnt > POLY17_SIZE+1) {
counters[i] -= POLY17_SIZE+1;
if (cnt > wav.length) {
cnt = counters[i] = cnt - Math.floor(cnt / wav.length) * wav.length;
}
var on = wav[Math.floor(cnt % wav.length)];
var on = wav[Math.floor(cnt)];
if (on) {
sample += v;
}
}
}
sample *= 273;
sample *= 128;
buffer[s] = sample;
buffer[s+1] = sample;
}

View File

@ -7,6 +7,7 @@ var VECTOR_PRESETS = [
{id:'font.c', name:'Vector Fonts'},
{id:'threed.c', name:'3D Transformations'},
{id:'game.c', name:'Space Game'},
{id:'music.c', name:'POKEY Music'},
]
var ASTEROIDS_KEYCODE_MAP = makeKeycodeMap([

View File

@ -12,6 +12,7 @@ args = parser.parse_args()
test_notes = args.upper
final_notes = args.length
basehz = args.freq
bias = args.bias
results = []
@ -19,7 +20,7 @@ for a440 in range(4300,4500):
error = 0
for note in range(1,test_notes):
notehz = a440 / 10.0 * math.pow(2.0, (note - 49) / 12.0);
period = int(round(basehz / notehz))
period = int(round(basehz / notehz))
tonehz = basehz / period
error += abs(notehz-tonehz)
#print a440,note,notehz,notehz-tonehz,period
@ -35,6 +36,6 @@ print '//', best_a440, best_error, test_notes
print "const int note_table[%d] = {" % final_notes
for note in range(0,final_notes):
notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0);
period = int(round(basehz / notehz))
period = int(round(basehz / notehz)) - bias
print '%d,' % period,
print "};"