ADSR refactoring.

This commit is contained in:
Bobbi Webber-Manners 2022-10-18 00:15:39 -04:00
parent 5c67403cb4
commit 2eb2bb82f9
2 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

@ -487,7 +487,7 @@ GETENVADDR LDA #<ENVBUF0 ; Copy ENVBUF0 to A1L,A1H
* Process pitch envelope * Process pitch envelope
* On entry: X is audio channel # * On entry: X is audio channel #
* X is preserved * X is preserved
PITCHENV LDA CHANENV,X ; Set envelope number PITCHENV LDA CHANENV,X ; Get envelope number
TAY TAY
JSR GETENVADDR ; Addr of envelope -> A1L,A1H JSR GETENVADDR ; Addr of envelope -> A1L,A1H
LDA PITCHSECT,X ; See what section we are in LDA PITCHSECT,X ; See what section we are in
@ -551,7 +551,7 @@ UPDPITCH STX OSCNUM
* Process amplitude envelope * Process amplitude envelope
* On entry: X is audio channel # * On entry: X is audio channel #
* X is preserved * X is preserved
ADSRENV LDA CHANENV,X ; Set envelope number ADSRENV LDA CHANENV,X ; Get envelope number
TAY TAY
JSR GETENVADDR ; Addr of envelope -> A1L,A1H JSR GETENVADDR ; Addr of envelope -> A1L,A1H
LDA AMPSECT,X ; See what section we are in LDA AMPSECT,X ; See what section we are in
@ -577,14 +577,14 @@ ADSRENV LDA CHANENV,X ; Set envelope number
LDY #ENVALD ; Parm: level at end of delay LDY #ENVALD ; Parm: level at end of delay
LDA (A1L),Y ; Get value of parm LDA (A1L),Y ; Get value of parm
PLY PLY
* JSR ADSRPHASE ; Generic ADSR phase handler JSR ADSRPHASE ; Generic ADSR phase handler
BCS :NEXTSECT ; Phase done -> sustain BCS :NEXTSECT ; Phase done -> sustain
RTS RTS
:SUSTAIN LDY #ENVAS ; Parm: delay change/step :SUSTAIN LDY #ENVAS ; Parm: delay change/step
LDA (A1L),Y ; Get value of parm LDA (A1L),Y ; Get value of parm
TAY TAY
LDA #$00 ; Target level zero LDA #$00 ; Target level zero
* JSR ADSRPHASE ; Generic ADSR phase handler JSR ADSRPHASE ; Generic ADSR phase handler
RTS RTS
:NEXTSECT INC AMPSECT,X ; Next section :NEXTSECT INC AMPSECT,X ; Next section
RTS RTS
@ -593,21 +593,28 @@ ADSRENV LDA CHANENV,X ; Set envelope number
* Handle any individual phase of the ADSR envelope. Called by ADSRENV. * Handle any individual phase of the ADSR envelope. Called by ADSRENV.
* On entry: A - level at end of phase, X - audio channel, Y - change/step * On entry: A - level at end of phase, X - audio channel, Y - change/step
* On return: CS if end of phase, CC otherwise. X preserved. * On return: CS if end of phase, CC otherwise. X preserved.
ADSRPHASE CMP CURRAMP,X ; Compare tgt with current level ADSRPHASE STX OSCNUM
STA :TARGET ; Stash target level for later
CPY #$00 ; Check sign of change/step
BMI :DESCEND ; Descending amplitude
:ASCEND CMP CURRAMP,X ; Compare tgt with current level
BNE :S1 ; Not equal to target, keep going BNE :S1 ; Not equal to target, keep going
SEC ; CS to indicate phase is done SEC ; CS to indicate phase is done
RTS RTS
:S1 STA :TARGET ; Target level :S1 TYA ; Change/step -> A
TYA ; Change/step -> A
CLC CLC
ADC CURRAMP,X ; Add change to current amp ADC CURRAMP,X ; Add change to current amp
BCS :CLAMP ; If wrapped, clamp to target
CPY #$00 ; Check sign of change/step
BMI :DESCEND ; Descending amplitude
CMP :TARGET ; Compare with target CMP :TARGET ; Compare with target
BCS :CLAMP ; If target < sum, clamp to target BCS :CLAMP ; If target < sum, clamp to target
BRA :UPDATE BRA :UPDATE
:DESCEND CMP :TARGET ; Compare with target :DESCEND CMP CURRAMP,X ; Compare tgt with current level
BNE :S2 ; Not equal to target, keep going
SEC ; CS to indicate phase is done
RTS
:S2 TYA ; Change/step -> A
CLC
ADC CURRAMP,X ; Add change to current amp
CMP :TARGET ; Compare with target
BCC :CLAMP ; If target >= sum, clamp to target BCC :CLAMP ; If target >= sum, clamp to target
BRA :UPDATE BRA :UPDATE
:CLAMP LDA :TARGET ; Recover target level :CLAMP LDA :TARGET ; Recover target level