Volume interpolation for sound effect overlay?

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Volume interpolation for sound effect overlay?

Post by GradualGames »

I've run into an odd artifact in my sound engine, which only seems to be noticeable in certain situations. I've got a volume envelope in the square 1 channel that gradually increases in volume. During this song, a sound effect may play and overlay on the same square 1 channel with a different envelope, with different volume settings. Right now, it is overlaid directly, frame by frame, so when the sound effect ends, the music stream will supply where it would have been in its own envelope, potentially making a rude transition from one volume setting sharply to another. This results in an unpleasant "hiccup." And, I am certain this is not the effect described in MetalSlime's sound tutorial over on NA:

"Crackling Sounds: Writing to the 4th port of the Square channels ($4003/$4007) has the side effect of resetting the sequencer. If we write here too often, we will get a nasty crackling sound out of our Squares. This is not good."

I already followed his advice for preventing this effect when I upload all my apu register data. I think what I'm experiencing is purely due to abrupt shifting of the volume setting. If I'm right, it makes me wonder if others here who have written sound engines have any scheme to quickly interpolate volume values when overlaying sound effects, over a couple of frame perhaps---to smooth out this problem.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Volume interpolation for sound effect overlay?

Post by dougeff »

Mine silences the channel after a sound effect, and waits for the next NEW note before triggering.
Also, I keep the main song note on Sq 1 and square sound fxs on Sq 2, so the song doesn't sound interrupted.

(I'm still trying to think of a better engine, my sound effects are awfully simple)
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Volume interpolation for sound effect overlay?

Post by rainwarrior »

The "crackling sound" refers to when you do $4003/7 it in the middle of a note, e.g. if you have vibrato near A-3 (see: Mega Man 2 ending).

Getting a single "pop" from the phase reset at the start of a new note or sound effect is normal, and shouldn't be a problem. There are many things that change all of a sudden (pitch, volume, duty) when you begin a new note or sound effect, so a interruption of phase via $4003/7 is more or less irrelevant. The "crackling" problem is when you are trying to have a smooth continuous sound, but get discontinuities because of the phase reset (like with the vibrato example I linked).

Usually the start of a sound effect interrupting something is not a problem; sound effects are supposed to sound like an interruption. They should stick out and notify the player that something has happened in the game. The usual problem area is what happens when the sound ends.

If you resume the music in the middle of a note, it doesn't sound very musical; it sounds like an interruption, like a sound effect. There are a number of ways to deal with this. My own approach is just to leave the channel silent after a sound effect ends, and only resume the music at the next note. That way I never hear a partial note out of place. (As a consequence of this, on channels that are to be interrupted by SFX, I try to compose with frequent notes instead of long sustained ones, so the period of silence isn't long and glaring.)

Other people do things like fade a playing note back in over several frames, or comparing the volume of SFX vs Music and just playing whichever was louder that frame. I'm not really a fan of these techniques, but they're an option if you like them.
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Re: Volume interpolation for sound effect overlay?

Post by GradualGames »

Thanks rainwarrior, that's quite helpful. I tend to use a lot of sustained notes in my own music...so I'm gonna try the fade-in-after-sfx-terminate idea and see how I like it.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Volume interpolation for sound effect overlay?

Post by tepples »

rainwarrior wrote:comparing the volume of SFX vs Music and just playing whichever was louder that frame
That's what I do, especially because in my engine, drums can interrupt the note on the triangle channel in the same way that sound effects interrupt a note. This behavior ensures that if a sound effect has a long, quiet tail, a louder note on the same channel can interrupt that when prudent. And even though the triangle has no real volume control, it still uses the volume as a priority value between music and sound effects. For example, if a triangle kick drum has its volume bits set low for the last few frames, it will get cut slightly sooner when a note is playing than when not. Thanks to the the auditory phenomena of simultaneous masking, illusory continuity, and illusory discontinuity, the net effect is almost like having a mixer.
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Re: Volume interpolation for sound effect overlay?

Post by GradualGames »

Alright...tried all three techniques. I'm not sure I did the sfx/music volume compare quite correctly. However, I was able to get fade-in-after-terminate to work and also silence-until-note. I think I prefer silence-until-note. This sounded the least disruptive of all, in the context of the music/sfx I was working with. Thanks guys!
Post Reply