Skip to content

Commit

Permalink
Disable pulse sweep correctly for sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Nov 19, 2024
1 parent c5c5c08 commit 8a74df4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
19 changes: 16 additions & 3 deletions src/apu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,29 @@ Hw_Channels_sChanRegs_arr5 = $4000

;;;=========================================================================;;;

.SCOPE bSweep
Enable = %10000000
PeriodMask = %01110000
Negate = %00001000
ShiftMask = %00000111
.ENDSCOPE

;;; Constructs a frequency sweep byte for a pulse channel from a shift value
;;; (which must range from -7 to 7) and a period value (which must range from 0
;;; to 7).
.LINECONT +
.DEFINE pulse_sweep(SHIFT, PERIOD) (((SHIFT) <> 0) * \
($80 | ((PERIOD) << 4) | \
.DEFINE pulse_sweep(SHIFT, PERIOD) \
(((SHIFT) <> 0) * (bSweep::Enable | ((PERIOD) << 4) | \
(((SHIFT) < 0) * ($0f & (SHIFT)) + \
((SHIFT) > 0) * (8 - (SHIFT)))))
((SHIFT) >= 0) * (8 - (SHIFT)))))
.LINECONT -

;;; The frequency sweep byte to set for pulse channel to disable the sweep
;;; unit. Note that a value of $00 only *mostly* disables the sweep unit, as
;;; it will disable sweep but still effectively mute tones with a timer value
;;; of $400 or more (see https://www.nesdev.org/wiki/APU_Sweep#Muting).
kNoSweep = bSweep::Negate

;;;=========================================================================;;;

;;; Volume envelope control for the noise channel.
Expand Down
2 changes: 1 addition & 1 deletion src/sounds/flower.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

;;; SFX data for the "pick up flower" sound effect.
.PROC Data_PickUpFlower_sSfx
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 3, 0, $00d2
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 3, kNoSweep, $00d2
sfx_Wait 3
sfx_SetTimer $00a9
sfx_Wait 3
Expand Down
8 changes: 4 additions & 4 deletions src/sounds/machine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

;;; SFX data for the "machine end" sound effect.
.PROC Data_MachineEnd_sSfx
sfx_SetAll bEnvelope::Duty12 | bEnvelope::NoLength | 3, 0, $0120
sfx_SetAll bEnvelope::Duty12 | bEnvelope::NoLength | 3, kNoSweep, $0120
sfx_Wait 8
sfx_SetTimerHi $01
sfx_Wait 16
Expand All @@ -38,7 +38,7 @@

;;; SFX data for the "machine error" sound effect.
.PROC Data_MachineError_sSfx
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 4, 0, $0340
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 4, kNoSweep, $0340
sfx_Wait 8
sfx_SetEnvTimerHi bEnvelope::Duty18 | bEnvelope::NoLength | 4, $03
sfx_Wait 8
Expand All @@ -49,9 +49,9 @@

;;; SFX data for the "machine sync" sound effect.
.PROC Data_MachineSync_sSfx
sfx_SetAll bEnvelope::Duty18 | bEnvelope::NoLength | 3, 0, $0120
sfx_SetAll bEnvelope::Duty18 | bEnvelope::NoLength | 3, kNoSweep, $0120
sfx_Wait 5
sfx_SetEnvTimer bEnvelope::Duty14 | bEnvelope::NoLength | 3, $00e0
sfx_SetEnvTimer bEnvelope::Duty14 | bEnvelope::NoLength | 3, $00e0
sfx_Wait 10
sfx_End
.ENDPROC
Expand Down
6 changes: 3 additions & 3 deletions src/sounds/menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

;;; SFX sequence data for the "menu cancel" sound effect.
.PROC Data_MenuCancel_sSfx
sfx_SetAll bEnvelope::Duty18 | bEnvelope::NoLength | 1, 0, $0180
sfx_SetAll bEnvelope::Duty18 | bEnvelope::NoLength | 1, kNoSweep, $0180
sfx_Wait 5
sfx_SetEnvTimer bEnvelope::Duty14 | bEnvelope::NoLength | 1, $01e0
sfx_Wait 5
Expand All @@ -38,7 +38,7 @@

;;; SFX sequence data for the "menu confirm" sound effect.
.PROC Data_MenuConfirm_sSfx
sfx_SetAll bEnvelope::Duty12 | bEnvelope::NoLength | 1, 0, $0180
sfx_SetAll bEnvelope::Duty12 | bEnvelope::NoLength | 1, kNoSweep, $0180
sfx_Wait 5
sfx_SetEnvTimer bEnvelope::Duty14 | bEnvelope::NoLength | 1, $0120
sfx_Wait 5
Expand All @@ -47,7 +47,7 @@

;;; SFX data for the "menu move" sound effect.
.PROC Data_MenuMove_sSfx
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 0, 0, $01a0
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 0, kNoSweep, $01a0
sfx_Wait 3
sfx_End
.ENDPROC
Expand Down
4 changes: 2 additions & 2 deletions src/sounds/metal.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

;;; SFX data for the "metallic clang" sound effect.
.PROC Data_MetallicClang_sSfx
sfx_SetAll bEnvelope::Duty18 | bEnvelope::NoLength | 7, 0, $00f7
sfx_SetAll bEnvelope::Duty18 | bEnvelope::NoLength | 7, kNoSweep, $00f7
sfx_Wait 4
sfx_SetEnvTimer bEnvelope::Duty14 | bEnvelope::NoLength | 9, $00f5
sfx_SetEnvTimer bEnvelope::Duty14 | bEnvelope::NoLength | 9, $00f5
sfx_Wait 40
sfx_End
.ENDPROC
Expand Down
2 changes: 1 addition & 1 deletion src/sounds/quest.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

;;; SFX data for the "quest marker" sound effect.
.PROC Data_QuestMarker_sSfx
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 4, 0, $011c
sfx_SetAll bEnvelope::Duty14 | bEnvelope::NoLength | 4, kNoSweep, $011c
sfx_Wait 5
sfx_SetTimer $0152
sfx_Wait 5
Expand Down
2 changes: 1 addition & 1 deletion src/sounds/window.asm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
.linecont +
sfx_SetAll (bEnvelope::Duty14 | bEnvelope::NoLength | \
bEnvelope::ConstVol | 5), \
(pulse_sweep -2, 0), $03ff
(pulse_sweep -2, 0), $0400
sfx_Wait 15
sfx_End
.linecont -
Expand Down

0 comments on commit 8a74df4

Please sign in to comment.