Skip to content

NSS: tremolo FX implementation - #182

Draft
dciabrin wants to merge 3 commits into
masterfrom
nss-tremolo
Draft

dciabrin wants to merge 3 commits into
masterfrom
nss-tremolo

Conversation

@dciabrin

Copy link
Copy Markdown
Owner

NSS: tremolo FX implementation

Comment thread nullsound/buffers.s
;;; [-pi..pi], encoded as [0..0.6[. This serves as a base 8-bit fixed point
;;; displacement for the tremolo FX (whose force is configured from [1..16]
.bndry 128
volsine::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's what I wanted to see! How did you decide to use (cos(x)+1)/2 ? And did you decide to not go above 0.6 to not break the sound?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the exact formula is not carved in stone yet (especially for the 0.6), it's no longer that. But here's the gist of it.

The driver has an internal representation of volume (not the same as the ym2610), from 0 (quietest/nosound) to loudest (0x7f for FM, 0xf for SSG...).
The tremolo is modeled as volume to be substracted from the nullsound volume, with bounds like:

  • 0: no volume reduction.

  • 1: biggest volume reduction.
    We have a sine-like wave, but from [0..1] instead of [-1..1], so I lift it +1, and divide the result by 2.

  • There are 128 elements in the precalc to match Furnace, so a full sine wave is done with f(x) = sin(2pix/128)

  • But the volume reduction must start from 0, so I found it convenient to use a shifted cos, like e.g. f(x) = cos(2pix/128)-pi

  • apply the translation and scaling above to get f(x) in the range of [0..1]

  • What's left to do is to scale it (it's 0.23 in this version of the PR), and map it to a single byte as a fractional number.

The 0.23 scaling is just a (bad) guess right now, I need to figure out either the real value from Furnace source, or a value that fit nicely once applied on the various channel types.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread nullsound/fx-vibrato.s
jp vibrato_init


;;; Disable trmolo for the current channel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Comment thread nullsound/fx-vibrato.s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call it fx-oscillation.s because it does both vibrato and tremolo

Comment thread nullsound/nss-fm.s Outdated
fm2_op4_instr::
push iy
ld iy, #state_op4_pipeline
ld iy, #state_op2_pipeline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a WIP right this is not going to end in the final driver ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Comment thread nullsound/buffers.s
;;; fixed-point volume sine precalc
;;; ------
;;; a 128 entries (128bytes) fixed point precalc of (cos(x)+1)/2 for x in
;;; [-pi..pi], encoded as [0..0.6[. This serves as a base 8-bit fixed point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[-pi..pi[

Comment thread nullsound/adpcm.s
;;; ------
;;; ix: sample play config
;;; [a modified - other registers saved]
;;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general comment the comments in this WIP are distracting the reader from the code that really changed. I'd say the comment change should land in its own PR

Comment thread nullsound/buffers.s
.db 0x29, 0x2a, 0x2c, 0x2d, 0x2e, 0x2f, 0x31, 0x32
.db 0x33, 0x34, 0x35, 0x36, 0x36, 0x37, 0x38, 0x39
.db 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b
.db 0x3c, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3a, 0x3a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x3c should not be part of the list according to your comments

Comment thread nullsound/nss-fm.s Outdated
fm2_op3_vol::
push ix
ld ix, #state_op3_pipeline
ld ix, #state_op2_pipeline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a mistake ?

Comment thread nullsound/nss-fm.s Outdated
fm2_op4_vol::
push ix
ld ix, #state_op4_pipeline
ld ix, #state_op2_pipeline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment thread nullsound/buffers.s

@dogruis dogruis Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be called something like precalc-tables.s or just data-tables.s

Comment thread nullsound/fx-vibrato.s
jr nc, _t_post_bit1
add hl, bc
_t_post_bit1:
;; this 16bit shift might overflow now if the precalc is one full

@dogruis dogruis Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is copied from the vibrato. Which is a 2 bytes table.
The calculation here is different because the volume table is one byte. So the calculation in this section might be wrong and overflow looks impossible on paper.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, this is a bad copy'n'paste from the other function.
There is no overflow in this path, as the precalc is only 8bit.
The contract is that:

  • when the scaling factor is maximum (=0x10, or 0xf in Furnace), the full precalc value flows in register H.
  • when the scaling factor is lower (between 0x1 and 0x9), i multiply the fractional part (bits ...XXXXXXXX.... of BC), and keep the integer part of the result (register H).

The overflow is valid in the case of the note vibrato, because the highest pitch of the vibrato (0xf) must go oscillate exactly 1 semitone above and below the current note.

The semantics of the tremolo seems to be different. I need to double check that. Right now, I'm assuming the rightmost bound is excluded, so by construction there is no overflow.

I might be wrong though, I need to double check what Furnace is doing (though right now, the effect sounds pretty convincing to me).

Comment thread nullsound/nss-fm.s Outdated
;;; FM3 state tracker
;;; { ...

.blkb 0x28

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should go in align.inc because it is padding for fm3

Comment thread nullsound/stream.s Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any padding of this sort should go in align.inc

The sound driver assumes various memory area lands in specific memory
location to speed up 16-bit operations.

Right now, any update to the driver's global variables is asserted
with check-bounds.py, but it's not easy to have a graphical
representation of the allocated memory.

Add a new tool build-layout.py to generate a SVG view of the allocated
memory, to ease padding management.
@dogruis

dogruis commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

The ram map looks much healthier than before and you have 3 spare pages for the stack which should account for a more stable driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants