Skip to content

Commit

Permalink
fix instrument table handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Oct 5, 2021
1 parent 0a92fbf commit 98ecde4
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions rmt.js
Expand Up @@ -207,7 +207,7 @@ class RMTInstrument {
let trep = data[1]
let eend = data[2]
let erep = data[3]
this.tspd = (data[4] & 0x3f) + 1
this.tspd = data[4] & 0x3f
this.tmode = (data[4] >> 6) & 1
this.ttype = (data[4] >> 7) & 1
this.audctl = data[5]
Expand Down Expand Up @@ -237,12 +237,13 @@ class RMTTune {
this.tpos = 0
this.is_repeating = false

this.tcnt = 0
this.tspd = this.instrument.tspd
this.vib_table = VIB_TABLE[instrument.vibrato]
this.vib_index = 0
this.shiftfrq = 0
this.filter = 1
this.pokey_idx = channel < 4 ? 0 : 1
this.table_note = this.instrument.table[this.tpos]
}

play(player) {
Expand Down Expand Up @@ -278,6 +279,7 @@ class RMTTune {

let vol = this.channel < 4 ? env_lvol : env_rvol
var audc = VOLUME_TAB[player.getChannelVolume(this.channel) << 4 | vol] | (env_dist << 4)

this.epos += 1
if(this.epos >= envelope.length / 3) {
this.epos = this.instrument.ego
Expand All @@ -292,6 +294,20 @@ class RMTTune {
this.eff_delay -= 1
}
}
if(this.tspd < 0) {
this.tspd = this.instrument.tspd
this.tpos += 1
if(this.tpos >= this.instrument.table.length) {
this.tpos = this.instrument.tgo
}
if(this.instrument.tmode) {
this.table_note = (this.table_note + this.instrument.table[this.tpos]) & 0xff
} else {
this.table_note = this.instrument.table[this.tpos]
}
} else {
this.tspd -= 1
}

var frqaddcmd2 = 0

Expand All @@ -317,11 +333,11 @@ class RMTTune {
// TODO portamento
if(this.instrument.ttype == 0) {
// cmd5a1
note = (this.note + this.instrument.table[this.tpos]) & 0xff
note = (this.note + this.table_note) & 0xff
if(note > 61) note = 63
portafrqc = freq_table[note]
} else {
portafrqc = (freq_table[this.note] + this.instrument.table[this.tpos]) & 0xff
portafrqc = (freq_table[this.note] + this.table_note) & 0xff
}
// cmd5ax
let portafrqa = !env_xy ? portafrqc : null
Expand Down Expand Up @@ -351,7 +367,7 @@ class RMTTune {
}
if(note != null) {
if(this.instrument.ttype == 0) { // notes
note = (note + this.instrument.table[this.tpos]) & 0xff
note = (note + this.table_note) & 0xff
if(note > 61) {
note = 63
audc = 0
Expand All @@ -363,7 +379,7 @@ class RMTTune {
note = 63
audc = 0
}
audf = (freq_table[note] + frqaddcmd2 + this.instrument.table[this.tpos] + this.shiftfrq) & 0xff
audf = (freq_table[note] + frqaddcmd2 + this.table_note + this.shiftfrq) & 0xff
}
}
let frq = player.portamento[this.channel].freq()
Expand All @@ -374,14 +390,6 @@ class RMTTune {
player.setPokeyAudf(this.channel, audf)
player.setPokeyAudc(this.channel, audc)
player.updatePokeyAudctl(this.pokey_idx, this.instrument.audctl)

this.tcnt = (this.tcnt + 1) % this.instrument.tspd
if(!this.tcnt) {
this.tpos += 1
if(this.tpos >= this.instrument.table.length) {
this.tpos = this.instrument.tgo
}
}
}

postPlay(player, prev_audctl) {
Expand Down

0 comments on commit 98ecde4

Please sign in to comment.