Skip to content

Commit 043e72b

Browse files
committed
nullsound: note cut FX
Plus note delay FX for ADPCM-B which was missing from previous commits
1 parent de6ca2c commit 043e72b

File tree

7 files changed

+151
-19
lines changed

7 files changed

+151
-19
lines changed

nullsound/fx-trigger.s

+41
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ trigger_delay_init::
5050
ret
5151

5252

53+
;;; Enable delayed cut for the note currently playing
54+
;;; (note is stopped after a defined number of steps)
55+
;;; ------
56+
;;; ix : state for channel
57+
;;; [ hl ]: delay
58+
;;; [ hl modified ]
59+
trigger_cut_init::
60+
;; a: delay
61+
ld a, (hl)
62+
inc a
63+
inc hl
64+
65+
;; configure trigger FX for delay
66+
ld TRIGGER_CUT(ix), a
67+
xor a
68+
set BIT_TRIGGER_ACTION_CUT, a
69+
ld TRIGGER_ACTION(ix), a
70+
set BIT_FX_TRIGGER, FX(ix)
71+
72+
ret
73+
74+
5375
;;; Call an function from the action lookup table
5476
;;; ------
5577
;;; hl: function lookup table
@@ -89,6 +111,15 @@ eval_trigger_step::
89111
jr nz, _trigger_end
90112
jr _trigger_load_and_clear
91113
_trigger_post_delay:
114+
115+
;; is the trigger a cut?
116+
bit BIT_TRIGGER_ACTION_CUT, TRIGGER_ACTION(ix)
117+
jr z, _trigger_post_cut
118+
;; check whether delay is reached
119+
dec TRIGGER_CUT(ix)
120+
jr nz, _trigger_end
121+
jr _trigger_cut_note
122+
_trigger_post_cut:
92123
_trigger_end:
93124
ret
94125

@@ -115,3 +146,13 @@ _trigger_post_load_vol:
115146
res BIT_FX_TRIGGER, FX(ix)
116147

117148
ret
149+
150+
_trigger_cut_note:
151+
ld bc, #TRIGGER_STOP_NOTE_FUNC
152+
call trigger_action_function
153+
xor a
154+
ld TRIGGER_ACTION(ix), a
155+
res BIT_FX_TRIGGER, FX(ix)
156+
157+
ret
158+

nullsound/nss-adpcm-a.s

+23-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ _state_adpcm_end:
103103
state_a_action_funcs::
104104
.dw adpcm_a_configure_on
105105
.dw adpcm_a_configure_vol
106+
.dw adpcm_a_stop_playback
106107

107108

108109
;;; Reset ADPCM playback state.
@@ -456,10 +457,9 @@ _a_on_end:
456457
ret
457458

458459

459-
;;; ADPCM_A_OFF
460-
;;; Stop the playback on a ADPCM-A channel
460+
;;; Release the note on a ADPCM-A channel and update the pipeline state
461461
;;; ------
462-
adpcm_a_off::
462+
adpcm_a_stop_playback:
463463
push bc
464464
push de
465465

@@ -485,6 +485,15 @@ _off_bit:
485485
pop de
486486
pop bc
487487

488+
ret
489+
490+
491+
;;; ADPCM_A_OFF
492+
;;; Stop the playback on a ADPCM-A channel
493+
;;; ------
494+
adpcm_a_off::
495+
call adpcm_a_stop_playback
496+
488497
;; ADPCM-A context will now target the next channel
489498
ld a, (state_adpcm_a_channel)
490499
inc a
@@ -585,3 +594,14 @@ adpcm_a_delay::
585594

586595
ld a, #1
587596
ret
597+
598+
599+
;;; ADPCM_A_CUT
600+
;;; Record that the note being played must be stopped after some steps
601+
;;; ------
602+
;;; [ hl ]: delay
603+
adpcm_a_cut::
604+
call trigger_cut_init
605+
606+
ld a, #1
607+
ret

nullsound/nss-adpcm-b.s

+24
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ _state_adpcm_b_end:
101101
state_b_action_funcs::
102102
.dw adpcm_b_configure_note_on
103103
.dw adpcm_b_configure_vol
104+
.dw adpcm_b_note_off
104105

105106

106107
;;; Reset ADPCM playback state.
@@ -755,3 +756,26 @@ adpcm_b_portamento::
755756

756757
ld a, #1
757758
ret
759+
760+
761+
;;; ADPCM_B_DELAY
762+
;;; Enable delayed trigger for the next note and volume
763+
;;; (note and volume and played after a number of ticks)
764+
;;; ------
765+
;;; [ hl ]: delay
766+
adpcm_b_delay::
767+
call trigger_delay_init
768+
769+
ld a, #1
770+
ret
771+
772+
773+
;;; ADPCM_B_CUT
774+
;;; Record that the note being played must be stopped after some steps
775+
;;; ------
776+
;;; [ hl ]: delay
777+
adpcm_b_cut::
778+
call trigger_cut_init
779+
780+
ld a, #1
781+
ret

nullsound/nss-fm.s

+29-9
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ _state_fm_end:
157157
state_fm_action_funcs:
158158
.dw fm_configure_note_on
159159
.dw fm_configure_vol
160+
.dw fm_stop_playback
160161

161162

162163
;;; Reset FM playback state.
@@ -1086,13 +1087,11 @@ _fm_note_on_end:
10861087
ret
10871088

10881089

1089-
;;; FM_NOTE_OFF
1090-
;;; Release the note on an FM channel. The sound will decay according
1091-
;;; to the current configuration of the FM channel's operators.
1090+
;;; Release the note on an FM channel and update the pipeline state
10921091
;;; ------
1093-
fm_note_off::
1094-
push bc
1092+
fm_stop_playback:
10951093
;; stop all OPs of FM channel
1094+
push bc
10961095
ld a, (state_fm_ym2610_channel)
10971096
ld c, a
10981097
ld b, #REG_FM_KEY_ON_OFF_OPS
@@ -1103,15 +1102,25 @@ fm_note_off::
11031102
;; will get cleaned during the next pipeline run
11041103
res BIT_PLAYING, PIPELINE(ix)
11051104

1105+
;; record that playback is stopped
1106+
xor a
1107+
res BIT_NOTE_STARTED, PIPELINE(ix)
1108+
1109+
ret
1110+
1111+
1112+
;;; FM_NOTE_OFF
1113+
;;; Release the note on an FM channel. The sound will decay according
1114+
;;; to the current configuration of the FM channel's operators.
1115+
;;; ------
1116+
fm_note_off::
1117+
call fm_stop_playback
1118+
11061119
;; FM context will now target the next channel
11071120
ld a, (state_fm_channel)
11081121
inc a
11091122
call fm_ctx_set_current
11101123

1111-
;; record that playback is stopped
1112-
xor a
1113-
res BIT_NOTE_STARTED, PIPELINE(ix)
1114-
11151124
ld a, #1
11161125
ret
11171126

@@ -1339,3 +1348,14 @@ fm_delay::
13391348

13401349
ld a, #1
13411350
ret
1351+
1352+
1353+
;;; FM_CUT
1354+
;;; Record that the note being played must be stopped after some steps
1355+
;;; ------
1356+
;;; [ hl ]: delay
1357+
fm_cut::
1358+
call trigger_cut_init
1359+
1360+
ld a, #1
1361+
ret

nullsound/nss-ssg.s

+27-7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ _state_ssg_end:
134134
state_ssg_action_funcs:
135135
.dw ssg_configure_note_on
136136
.dw ssg_configure_vol
137+
.dw ssg_stop_playback
137138

138139

139140
;;; Reset SSG playback state.
@@ -713,10 +714,9 @@ _end_ssg_slide_step:
713714
ret
714715

715716

716-
;;; SSG_NOTE_OFF
717-
;;; Release (stop) the note on the current SSG channel.
717+
;;; Release the note on a SSG channel and update the pipeline state
718718
;;; ------
719-
ssg_note_off::
719+
ssg_stop_playback:
720720
push bc
721721

722722
;; c: disable mask (shifted for channel)
@@ -747,15 +747,24 @@ ssg_note_off::
747747
;; will get cleaned during the next pipeline run
748748
res BIT_PLAYING, PIPELINE(ix)
749749

750+
;; record that playback is stopped
751+
xor a
752+
res BIT_NOTE_STARTED, PIPELINE(ix)
753+
754+
ret
755+
756+
757+
;;; SSG_NOTE_OFF
758+
;;; Release (stop) the note on the current SSG channel.
759+
;;; ------
760+
ssg_note_off::
761+
call ssg_stop_playback
762+
750763
;; SSG context will now target the next channel
751764
ld a, (state_ssg_channel)
752765
inc a
753766
call fm_ctx_set_current
754767

755-
;; record that playback is stopped
756-
xor a
757-
res BIT_NOTE_STARTED, PIPELINE(ix)
758-
759768
ld a, #1
760769
ret
761770

@@ -1044,3 +1053,14 @@ ssg_pitch::
10441053
pop bc
10451054
ld a, #1
10461055
ret
1056+
1057+
1058+
;;; SSG_CUT
1059+
;;; Record that the note being played must be stopped after some steps
1060+
;;; ------
1061+
;;; [ hl ]: delay
1062+
ssg_cut::
1063+
call trigger_cut_init
1064+
1065+
ld a, #1
1066+
ret

nullsound/stream.s

+5
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ nss_opcodes:
520520
.nss_op adpcm_b_portamento
521521
.nss_op ssg_pitch_slide_down
522522
.nss_op ssg_portamento
523+
.nss_op fm_cut
524+
.nss_op ssg_cut
525+
.nss_op adpcm_a_cut
526+
.nss_op adpcm_b_cut
527+
.nss_op adpcm_b_delay
523528

524529

525530

nullsound/struct-fx.inc

+2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ _vibrato_size:
105105

106106
.lclequ TRIGGER_LOAD_NOTE_FUNC, 0
107107
.lclequ TRIGGER_LOAD_VOL_FUNC, 2
108+
.lclequ TRIGGER_STOP_NOTE_FUNC, 4
108109

109110
.lclequ BIT_TRIGGER_ACTION_DELAY, 0
111+
.lclequ BIT_TRIGGER_ACTION_CUT, 1
110112
.lclequ BIT_TRIGGER_LOAD_NOTE, 4
111113
.lclequ BIT_TRIGGER_LOAD_VOL, 5

0 commit comments

Comments
 (0)