Code Monkey home page Code Monkey logo

psf-drivers's People

Contributors

loveemu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

psf-drivers's Issues

SNES music slowdown (N-SPC etc., caused by octave calculation)

Some songs of Super Mario World SNSF has a slowdown at the beginning of song. They don't in usual gameplay, of course.

  • Castle (Level #8)
  • World Clear (Level #19)
  • Bowser's Castle Emerges (Overworld #8)

Why does it happen?

TL;DR: The problem is caused by octave calculation routine and uninitialized note number. Apparently, it can be fixed by patching the octave routine. Many SNES games based on N-SPC driver have the kind of the same problem.

N-SPC sequences, which enables vibrato at the beginning of song and starts with a "rest" event, may cause notable slowdown.

  1. N-SPC handles vibrato and tremolo, even though the channel does not utter a sound.
  2. If the first note is a rest with vibrato, the driver will try to calculate the pitch from uninitialized note number (usually 0). It often makes the note number out of range (e.g. negative number).
  3. At last, octave correction routine will cause slowdown. It repeats right-shifting the pitch value ridiculously.
; Get pitch from note number in A (with octave correction) to YA
sub_getPitch:
    mov   y,#$00
    asl   a
    mov   x,#$18
    div   ya,x
    mov   x,a
    mov   a,$12da+y
    mov   $16,a
    mov   a,$12d9+y
    bra   loc_octaveLoop

loc_decOctave:
    lsr   $16
    ror   a
    inc   x

loc_octaveLoop:
    cmp   x,#$06
    bne   loc_decOctave     ; Causes redundant repeat for unexpected note!

    mov   y,$16
    ret

Workaround (and side-effects)

I can provide a simple workaround for this.

loc_octaveLoop:
    cmp   x,#$06
    bcc   loc_decOctave
    ; bne (d0h) ==> bcc (90h)

Pros

  • Rest with vibrato will no longer slows down the music.
  • The patch size is only 1 byte. Surprisingly portable.

Cons

  • Broken note issue: If a music sequence has an illegal note that its note number is below 0, the engine will play the note unexpected pitch (formerly it stops the sound instead). Unfortunately, that's not very rare mistake. I had seen the same error again and again.
    • You would want to replace those illegal notes to rest events.

I would recommend to make a separate patch as the secondary snsflib, then let only the problematic minisnsf to load the patch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.