Skip to content

Commit

Permalink
nullsound: vibrato FX for ADPCM-B channel
Browse files Browse the repository at this point in the history
  • Loading branch information
dciabrin committed Dec 14, 2024
1 parent 0fcea6b commit eb67caf
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
54 changes: 54 additions & 0 deletions nullsound/nss-adpcm-b.s
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ state_b_fx: .blkb 1 ; enabled FX for this channel
state_b_trigger: .blkb TRIGGER_SIZE
state_b_fx_vol_slide: .blkb VOL_SLIDE_SIZE
state_b_fx_slide: .blkb SLIDE_SIZE
state_b_fx_vibrato: .blkb VIBRATO_SIZE
;;; ADPCM-B-specific state
;;; Note
state_b_note:
Expand Down Expand Up @@ -157,6 +158,11 @@ run_adpcm_b_pipeline::
ld hl, #state_b_action_funcs
call eval_trigger_step
_b_post_fx_trigger:
bit BIT_FX_VIBRATO, FX(ix)
jr z, _b_post_fx_vibrato
call eval_b_vibrato_step
set BIT_LOAD_NOTE, PIPELINE(ix)
_b_post_fx_vibrato:
bit BIT_FX_SLIDE, FX(ix)
jr z, _b_post_fx_slide
ld hl, #NOTE_SEMITONE
Expand Down Expand Up @@ -410,6 +416,24 @@ adpcm_b_delta_n_half_distance::
;; C, C#, D, D#, E, F, F#, G, G#, A, A#, B
.db 0x60, 0x66, 0x6d, 0x73, 0x7a, 0x81, 0x89, 0x91, 0x99, 0xa3, 0xac, 0xb7


;;; Update the vibrato for the ADPCM-B channel
;;; ------
;;; ix: mirrored state of the ADPCM-B channel
eval_b_vibrato_step::
push hl
push de
push bc

call vibrato_eval_step

pop bc
pop de
pop hl

ret


;;; Update the slide for the current channel
;;; Slide moves up or down by 1/8 of semitone increments * slide depth.
;;; ------
Expand Down Expand Up @@ -805,3 +829,33 @@ adpcm_b_pan::

ld a, #1
ret


;;; ADPCM_B_VIBRATO
;;; Enable vibrato for the channel
;;; ------
;;; [ hl ]: speed (4bits) and depth (4bits)
adpcm_b_vibrato::
;; TODO: move this part to common vibrato_init

;; hl == 0 means disable vibrato
ld a, (hl)
cp #0
jr nz, _setup_b_vibrato

;; disable vibrato fx
res BIT_FX_VIBRATO, FX(ix)

;; reload configured note at the next pipeline run
set BIT_LOAD_NOTE, PIPELINE(ix)

inc hl
jr _post_b_vibrato_setup

_setup_b_vibrato:
call vibrato_init

_post_b_vibrato_setup:

ld a, #1
ret
2 changes: 1 addition & 1 deletion nullsound/nss-fm.s
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ fm_f_num_half_distance::

;;; Update the vibrato for the current FM channel
;;; ------
;;; hl: mirrored state of the current fm channel
;;; ix: mirrored state of the current fm channel
eval_fm_vibrato_step::
push hl
push de
Expand Down
1 change: 1 addition & 0 deletions nullsound/stream.s
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ nss_opcodes:
.nss_op adpcm_a_retrigger
.nss_op adpcm_a_pan
.nss_op adpcm_b_pan
.nss_op adpcm_b_vibrato



Expand Down
6 changes: 6 additions & 0 deletions tools/nsstool.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def register_nss_ops():
("a_retrigger", ["delay"]),
("a_pan", ["pan_mask"]),
("b_pan", ["pan_mask"]),
("b_vibrato", ["speed_depth"]),
# reserved opcodes
("nss_label", ["pat"])
)
Expand Down Expand Up @@ -583,7 +584,12 @@ def convert_b_row(row, channel):
elif fx in [0x08, 0x80]: # panning
pan_mask = convert_pan(fx, fxval)
opcodes.append(b_pan(pan_mask))
elif fx == 0x04: # vibrato
# fxval == -1 means disable vibrato
fxval = max(fxval, 0)
opcodes.append(b_vibrato(fxval))
else:
row_warn(row, "VIBRATO")
add_unknown_fx('ADPCM-B', fx)

# note
Expand Down

0 comments on commit eb67caf

Please sign in to comment.