From 87a3e4e7205dbea03ed3fba750b07039b16ca0f6 Mon Sep 17 00:00:00 2001 From: The With Commands <67952504+TheWithCommands@users.noreply.github.com> Date: Sun, 21 Apr 2024 16:24:06 +0800 Subject: [PATCH 1/5] Sound effect(s): Change from similar overlap mode to one of two mode When playing high priority sound effects, force to stop the mode of playing low priority sound effects, or overlay and blend mode from beginning to end for each sound effect. --- SoundEngine/famistudio_asm6.asm | 108 ++++++++++++++++++++++++------ SoundEngine/famistudio_ca65.s | 108 ++++++++++++++++++++++++------ SoundEngine/famistudio_nesasm.asm | 108 ++++++++++++++++++++++++------ 3 files changed, 261 insertions(+), 63 deletions(-) diff --git a/SoundEngine/famistudio_asm6.asm b/SoundEngine/famistudio_asm6.asm index 28108c636..798d9d801 100644 --- a/SoundEngine/famistudio_asm6.asm +++ b/SoundEngine/famistudio_asm6.asm @@ -1,6 +1,6 @@ ;====================================================================================================================== -; FAMISTUDIO SOUND ENGINE (4.1.0) -; Copyright (c) 2019-2023 Mathieu Gauthier +; FAMISTUDIO SOUND ENGINE (4.2.0) +; Copyright (c) 2019-2024 Mathieu Gauthier ; ; Copying and distribution of this file, with or without ; modification, are permitted in any medium without royalty provided @@ -145,6 +145,9 @@ FAMISTUDIO_CFG_NTSC_SUPPORT = 1 ; FAMISTUDIO_CFG_SFX_SUPPORT = 1 ; FAMISTUDIO_CFG_SFX_STREAMS = 2 +; Multiple sound effects are overlaid from beginning to end, mixed and played back. For reused channels, some sound effects may sound strange. +; FAMISTUDIO_CFG_SFX_MIXED = 1 + ; Blaarg's smooth vibrato technique. Eliminates phase resets ("pops") on square channels. ; FAMISTUDIO_CFG_SMOOTH_VIBRATO = 1 @@ -346,12 +349,17 @@ FAMISTUDIO_USE_ARPEGGIO = 1 .ifndef FAMISTUDIO_CFG_SFX_SUPPORT FAMISTUDIO_CFG_SFX_SUPPORT = 0 FAMISTUDIO_CFG_SFX_STREAMS = 0 + FAMISTUDIO_CFG_SFX_MIXED = 0 .endif .ifndef FAMISTUDIO_CFG_SFX_STREAMS FAMISTUDIO_CFG_SFX_STREAMS = 1 .endif +.ifndef FAMISTUDIO_CFG_SFX_MIXED + FAMISTUDIO_CFG_SFX_MIXED = 0 +.endif + .ifndef FAMISTUDIO_CFG_C_BINDINGS FAMISTUDIO_CFG_C_BINDINGS = 0 .endif @@ -6532,6 +6540,37 @@ famistudio_sfx_play: asl a tay +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS = 4 ; Check if the high priority sound effects is playing + cpx #FAMISTUDIO_SFX_CH3 + beq @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS = 3 + cpx #FAMISTUDIO_SFX_CH2 + beq @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS = 2 + cpx #FAMISTUDIO_SFX_CH1 + beq @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne @ignore_channel + .endif +.endif + +@write_channel: jsr famistudio_sfx_clear_channel ; Stops the effect if it plays lda famistudio_sfx_addr_lo @@ -6545,6 +6584,7 @@ famistudio_sfx_play: lda (effect_data_ptr),y sta famistudio_sfx_ptr_hi,x ; This write enables the effect +@ignore_channel: rts ;====================================================================================================================== @@ -6567,12 +6607,50 @@ famistudio_sfx_update: bne @update_buf ; Just mix with output buffer @no_repeat: +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + stx tmp + .endif +.endif lda famistudio_sfx_ptr_hi,x ; Check if MSB of the pointer is not zero - bne @sfx_active + bne @clear_other_channel rts ; Return otherwise, no active effect +@clear_other_channel: +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + cpx #FAMISTUDIO_SFX_CH0 + beq @sfx_active + + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx tmp + cpx #FAMISTUDIO_SFX_CH1 + beq @sfx_active + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx tmp + cpx #FAMISTUDIO_SFX_CH2 + beq @sfx_active + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + .endif +.endif + @sfx_active: - sta effect_data_ptr+1 ;load effect pointer into temp +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + ldx tmp ;load effect pointer into temp + lda famistudio_sfx_ptr_hi,x + .endif +.endif + sta effect_data_ptr+1 lda famistudio_sfx_ptr_lo,x sta effect_data_ptr+0 ldy famistudio_sfx_offset,x @@ -6615,13 +6693,9 @@ famistudio_sfx_update: sta famistudio_sfx_ptr_hi,x ; Mark channel as inactive @update_buf: - lda famistudio_output_buf ; Compare effect output buffer with main output buffer - and #$0f ; If volume of pulse 1 of effect is higher than that of the main buffer, overwrite the main buffer value with the new one - sta tmp - lda famistudio_sfx_buffer+0,x + lda famistudio_sfx_buffer+0,x ; Overwrite pulse 1 of main output buffer if it is active and #$0f - cmp tmp - bcc @no_pulse1 + beq @no_pulse1 lda famistudio_sfx_buffer+0,x sta famistudio_output_buf+0 lda famistudio_sfx_buffer+1,x @@ -6630,13 +6704,9 @@ famistudio_sfx_update: sta famistudio_output_buf+2 @no_pulse1: - lda famistudio_output_buf+3 - and #$0f - sta tmp lda famistudio_sfx_buffer+3,x and #$0f - cmp tmp - bcc @no_pulse2 + beq @no_pulse2 lda famistudio_sfx_buffer+3,x sta famistudio_output_buf+3 lda famistudio_sfx_buffer+4,x @@ -6645,7 +6715,7 @@ famistudio_sfx_update: sta famistudio_output_buf+5 @no_pulse2: - lda famistudio_sfx_buffer+6,x ; Overwrite triangle of main output buffer if it is active + lda famistudio_sfx_buffer+6,x beq @no_triangle sta famistudio_output_buf+6 lda famistudio_sfx_buffer+7,x @@ -6654,13 +6724,9 @@ famistudio_sfx_update: sta famistudio_output_buf+8 @no_triangle: - lda famistudio_output_buf+9 - and #$0f - sta tmp lda famistudio_sfx_buffer+9,x and #$0f - cmp tmp - bcc @no_noise + beq @no_noise lda famistudio_sfx_buffer+9,x sta famistudio_output_buf+9 lda famistudio_sfx_buffer+10,x diff --git a/SoundEngine/famistudio_ca65.s b/SoundEngine/famistudio_ca65.s index 088c7450d..d24efd74e 100644 --- a/SoundEngine/famistudio_ca65.s +++ b/SoundEngine/famistudio_ca65.s @@ -1,6 +1,6 @@ ;====================================================================================================================== -; FAMISTUDIO SOUND ENGINE (4.1.0) -; Copyright (c) 2019-2023 Mathieu Gauthier +; FAMISTUDIO SOUND ENGINE (4.2.0) +; Copyright (c) 2019-2024 Mathieu Gauthier ; ; Copying and distribution of this file, with or without ; modification, are permitted in any medium without royalty provided @@ -146,6 +146,9 @@ FAMISTUDIO_CFG_NTSC_SUPPORT = 1 ; FAMISTUDIO_CFG_SFX_SUPPORT = 1 ; FAMISTUDIO_CFG_SFX_STREAMS = 2 +; Multiple sound effects are overlaid from beginning to end, mixed and played back. For reused channels, some sound effects may sound strange. +; FAMISTUDIO_CFG_SFX_MIXED = 1 + ; Blaarg's smooth vibrato technique. Eliminates phase resets ("pops") on square channels. ; FAMISTUDIO_CFG_SMOOTH_VIBRATO = 1 @@ -347,12 +350,17 @@ FAMISTUDIO_USE_ARPEGGIO = 1 .ifndef FAMISTUDIO_CFG_SFX_SUPPORT FAMISTUDIO_CFG_SFX_SUPPORT = 0 FAMISTUDIO_CFG_SFX_STREAMS = 0 + FAMISTUDIO_CFG_SFX_MIXED = 0 .endif .ifndef FAMISTUDIO_CFG_SFX_STREAMS FAMISTUDIO_CFG_SFX_STREAMS = 1 .endif +.ifndef FAMISTUDIO_CFG_SFX_MIXED + FAMISTUDIO_CFG_SFX_MIXED = 0 +.endif + .ifndef FAMISTUDIO_CFG_C_BINDINGS FAMISTUDIO_CFG_C_BINDINGS = 0 .endif @@ -6578,6 +6586,37 @@ famistudio_sfx_play: asl a tay +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS = 4 ; Check if the high priority sound effects is playing + cpx #FAMISTUDIO_SFX_CH3 + beq @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS = 3 + cpx #FAMISTUDIO_SFX_CH2 + beq @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS = 2 + cpx #FAMISTUDIO_SFX_CH1 + beq @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne @ignore_channel + .endif +.endif + +@write_channel: jsr famistudio_sfx_clear_channel ; Stops the effect if it plays lda famistudio_sfx_addr_lo @@ -6591,6 +6630,7 @@ famistudio_sfx_play: lda (@effect_data_ptr),y sta famistudio_sfx_ptr_hi,x ; This write enables the effect +@ignore_channel: rts ;====================================================================================================================== @@ -6613,12 +6653,50 @@ famistudio_sfx_update: bne @update_buf ; Just mix with output buffer @no_repeat: +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + stx @tmp + .endif +.endif lda famistudio_sfx_ptr_hi,x ; Check if MSB of the pointer is not zero - bne @sfx_active + bne @clear_other_channel rts ; Return otherwise, no active effect +@clear_other_channel: +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + cpx #FAMISTUDIO_SFX_CH0 + beq @sfx_active + + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx @tmp + cpx #FAMISTUDIO_SFX_CH1 + beq @sfx_active + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx @tmp + cpx #FAMISTUDIO_SFX_CH2 + beq @sfx_active + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + .endif +.endif + @sfx_active: - sta @effect_data_ptr+1 ;load effect pointer into temp +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + ldx @tmp ;load effect pointer into temp + lda famistudio_sfx_ptr_hi,x + .endif +.endif + sta @effect_data_ptr+1 lda famistudio_sfx_ptr_lo,x sta @effect_data_ptr+0 ldy famistudio_sfx_offset,x @@ -6661,13 +6739,9 @@ famistudio_sfx_update: sta famistudio_sfx_ptr_hi,x ; Mark channel as inactive @update_buf: - lda famistudio_output_buf ; Compare effect output buffer with main output buffer - and #$0f ; If volume of pulse 1 of effect is higher than that of the main buffer, overwrite the main buffer value with the new one - sta @tmp - lda famistudio_sfx_buffer+0,x + lda famistudio_sfx_buffer+0,x ; Overwrite pulse 1 of main output buffer if it is active and #$0f - cmp @tmp - bcc @no_pulse1 + beq @no_pulse1 lda famistudio_sfx_buffer+0,x sta famistudio_output_buf+0 lda famistudio_sfx_buffer+1,x @@ -6676,13 +6750,9 @@ famistudio_sfx_update: sta famistudio_output_buf+2 @no_pulse1: - lda famistudio_output_buf+3 - and #$0f - sta @tmp lda famistudio_sfx_buffer+3,x and #$0f - cmp @tmp - bcc @no_pulse2 + beq @no_pulse2 lda famistudio_sfx_buffer+3,x sta famistudio_output_buf+3 lda famistudio_sfx_buffer+4,x @@ -6691,7 +6761,7 @@ famistudio_sfx_update: sta famistudio_output_buf+5 @no_pulse2: - lda famistudio_sfx_buffer+6,x ; Overwrite triangle of main output buffer if it is active + lda famistudio_sfx_buffer+6,x beq @no_triangle sta famistudio_output_buf+6 lda famistudio_sfx_buffer+7,x @@ -6700,13 +6770,9 @@ famistudio_sfx_update: sta famistudio_output_buf+8 @no_triangle: - lda famistudio_output_buf+9 - and #$0f - sta @tmp lda famistudio_sfx_buffer+9,x and #$0f - cmp @tmp - bcc @no_noise + beq @no_noise lda famistudio_sfx_buffer+9,x sta famistudio_output_buf+9 lda famistudio_sfx_buffer+10,x diff --git a/SoundEngine/famistudio_nesasm.asm b/SoundEngine/famistudio_nesasm.asm index b3029cb5b..530dc9791 100644 --- a/SoundEngine/famistudio_nesasm.asm +++ b/SoundEngine/famistudio_nesasm.asm @@ -1,6 +1,6 @@ ;====================================================================================================================== -; FAMISTUDIO SOUND ENGINE (4.1.0) -; Copyright (c) 2019-2023 Mathieu Gauthier +; FAMISTUDIO SOUND ENGINE (4.2.0) +; Copyright (c) 2019-2024 Mathieu Gauthier ; ; Copying and distribution of this file, with or without ; modification, are permitted in any medium without royalty provided @@ -164,6 +164,9 @@ FAMISTUDIO_CFG_NTSC_SUPPORT = 1 ; FAMISTUDIO_CFG_SFX_SUPPORT = 1 ; FAMISTUDIO_CFG_SFX_STREAMS = 2 +; Multiple sound effects are overlaid from beginning to end, mixed and played back. For reused channels, some sound effects may sound strange. +; FAMISTUDIO_CFG_SFX_MIXED = 1 + ; Blaarg's smooth vibrato technique. Eliminates phase resets ("pops") on square channels. ; FAMISTUDIO_CFG_SMOOTH_VIBRATO = 1 @@ -362,12 +365,17 @@ FAMISTUDIO_DUAL_SUPPORT = 0 .ifndef FAMISTUDIO_CFG_SFX_SUPPORT FAMISTUDIO_CFG_SFX_SUPPORT = 0 FAMISTUDIO_CFG_SFX_STREAMS = 0 +FAMISTUDIO_CFG_SFX_MIXED = 0 .endif .ifndef FAMISTUDIO_CFG_SFX_STREAMS FAMISTUDIO_CFG_SFX_STREAMS = 1 .endif + .ifndef FAMISTUDIO_CFG_SFX_MIXED +FAMISTUDIO_CFG_SFX_MIXED = 0 + .endif + .ifndef FAMISTUDIO_CFG_SMOOTH_VIBRATO FAMISTUDIO_CFG_SMOOTH_VIBRATO = 0 .endif @@ -6591,6 +6599,37 @@ famistudio_sfx_play: asl a tay + .if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS = 4 ; Check if the high priority sound effects is playing + cpx #FAMISTUDIO_SFX_CH3 + beq .write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS = 3 + cpx #FAMISTUDIO_SFX_CH2 + beq .write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS = 2 + cpx #FAMISTUDIO_SFX_CH1 + beq .write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne .ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne .ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne .ignore_channel + .endif + .endif + +.write_channel: jsr famistudio_sfx_clear_channel ; Stops the effect if it plays lda famistudio_sfx_addr_lo @@ -6604,6 +6643,7 @@ famistudio_sfx_play: lda [.effect_data_ptr],y sta famistudio_sfx_ptr_hi,x ; This write enables the effect +.ignore_channel: rts ;====================================================================================================================== @@ -6626,12 +6666,50 @@ famistudio_sfx_update: bne .update_buf ; Just mix with output buffer .no_repeat: + .if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + stx tmp + .endif + .endif lda famistudio_sfx_ptr_hi,x ; Check if MSB of the pointer is not zero - bne .sfx_active + bne .clear_other_channel rts ; Return otherwise, no active effect +.clear_other_channel: +.if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + cpx #FAMISTUDIO_SFX_CH0 + beq .sfx_active + + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx tmp + cpx #FAMISTUDIO_SFX_CH1 + beq .sfx_active + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx tmp + cpx #FAMISTUDIO_SFX_CH2 + beq .sfx_active + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + .endif +.endif + .sfx_active: - sta <.effect_data_ptr+1 ;load effect pointer into temp + .if FAMISTUDIO_CFG_SFX_MIXED = 0 + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + ldx tmp ;load effect pointer into temp + lda famistudio_sfx_ptr_hi,x + .endif + .endif + sta <.effect_data_ptr+1 lda famistudio_sfx_ptr_lo,x sta <.effect_data_ptr+0 ldy famistudio_sfx_offset,x @@ -6674,13 +6752,9 @@ famistudio_sfx_update: sta famistudio_sfx_ptr_hi,x ; Mark channel as inactive .update_buf: - lda famistudio_output_buf ; Compare effect output buffer with main output buffer - and #$0f ; If volume of pulse 1 of effect is higher than that of the main buffer, overwrite the main buffer value with the new one - sta <.tmp - lda famistudio_sfx_buffer+0,x + lda famistudio_sfx_buffer+0,x ; Overwrite pulse 1 of main output buffer if it is active and #$0f - cmp <.tmp - bcc .no_pulse1 + beq .no_pulse1 lda famistudio_sfx_buffer+0,x sta famistudio_output_buf+0 lda famistudio_sfx_buffer+1,x @@ -6689,13 +6763,9 @@ famistudio_sfx_update: sta famistudio_output_buf+2 .no_pulse1: - lda famistudio_output_buf+3 - and #$0f - sta <.tmp lda famistudio_sfx_buffer+3,x and #$0f - cmp <.tmp - bcc .no_pulse2 + beq .no_pulse2 lda famistudio_sfx_buffer+3,x sta famistudio_output_buf+3 lda famistudio_sfx_buffer+4,x @@ -6704,7 +6774,7 @@ famistudio_sfx_update: sta famistudio_output_buf+5 .no_pulse2: - lda famistudio_sfx_buffer+6,x ; Overwrite triangle of main output buffer if it is active + lda famistudio_sfx_buffer+6,x beq .no_triangle sta famistudio_output_buf+6 lda famistudio_sfx_buffer+7,x @@ -6713,13 +6783,9 @@ famistudio_sfx_update: sta famistudio_output_buf+8 .no_triangle: - lda famistudio_output_buf+9 - and #$0f - sta <.tmp lda famistudio_sfx_buffer+9,x and #$0f - cmp <.tmp - bcc .no_noise + beq .no_noise lda famistudio_sfx_buffer+9,x sta famistudio_output_buf+9 lda famistudio_sfx_buffer+10,x From a070b17c1ba19edf38bdb86e9d69e16754423cdd Mon Sep 17 00:00:00 2001 From: The With Commands <67952504+TheWithCommands@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:51:01 +0800 Subject: [PATCH 2/5] Changed the location of "ldx tmp" to avoid reuse --- SoundEngine/famistudio_asm6.asm | 4 ++-- SoundEngine/famistudio_ca65.s | 4 ++-- SoundEngine/famistudio_nesasm.asm | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SoundEngine/famistudio_asm6.asm b/SoundEngine/famistudio_asm6.asm index 798d9d801..e768768e7 100644 --- a/SoundEngine/famistudio_asm6.asm +++ b/SoundEngine/famistudio_asm6.asm @@ -6640,14 +6640,14 @@ famistudio_sfx_update: .if FAMISTUDIO_CFG_SFX_STREAMS > 3 ldx #FAMISTUDIO_SFX_CH2 jsr famistudio_sfx_clear_channel + ldx tmp .endif .endif @sfx_active: .if FAMISTUDIO_CFG_SFX_MIXED = 0 .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - ldx tmp ;load effect pointer into temp - lda famistudio_sfx_ptr_hi,x + lda famistudio_sfx_ptr_hi,x ; Load effect pointer into temp .endif .endif sta effect_data_ptr+1 diff --git a/SoundEngine/famistudio_ca65.s b/SoundEngine/famistudio_ca65.s index d24efd74e..d29611c2c 100644 --- a/SoundEngine/famistudio_ca65.s +++ b/SoundEngine/famistudio_ca65.s @@ -6686,14 +6686,14 @@ famistudio_sfx_update: .if FAMISTUDIO_CFG_SFX_STREAMS > 3 ldx #FAMISTUDIO_SFX_CH2 jsr famistudio_sfx_clear_channel + ldx @tmp .endif .endif @sfx_active: .if FAMISTUDIO_CFG_SFX_MIXED = 0 .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - ldx @tmp ;load effect pointer into temp - lda famistudio_sfx_ptr_hi,x + lda famistudio_sfx_ptr_hi,x ; Load effect pointer into temp .endif .endif sta @effect_data_ptr+1 diff --git a/SoundEngine/famistudio_nesasm.asm b/SoundEngine/famistudio_nesasm.asm index 530dc9791..7372d76f4 100644 --- a/SoundEngine/famistudio_nesasm.asm +++ b/SoundEngine/famistudio_nesasm.asm @@ -6699,14 +6699,14 @@ famistudio_sfx_update: .if FAMISTUDIO_CFG_SFX_STREAMS > 3 ldx #FAMISTUDIO_SFX_CH2 jsr famistudio_sfx_clear_channel + ldx tmp .endif .endif .sfx_active: .if FAMISTUDIO_CFG_SFX_MIXED = 0 .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - ldx tmp ;load effect pointer into temp - lda famistudio_sfx_ptr_hi,x + lda famistudio_sfx_ptr_hi,x ; Load effect pointer into temp .endif .endif sta <.effect_data_ptr+1 From 9382c1b5cdf94b82904247de714681b8da1be435 Mon Sep 17 00:00:00 2001 From: The With Commands <67952504+TheWithCommands@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:14:42 +0800 Subject: [PATCH 3/5] Moved to "famistudio_sfx_play" The relevant modifications were almost completely moved to "famistudio_sfx_play" to reduce the burden on "famistudio_update" and correct playback check issue. --- SoundEngine/famistudio_asm6.asm | 122 +++++++++++++---------------- SoundEngine/famistudio_ca65.s | 122 +++++++++++++---------------- SoundEngine/famistudio_nesasm.asm | 124 +++++++++++++----------------- 3 files changed, 163 insertions(+), 205 deletions(-) diff --git a/SoundEngine/famistudio_asm6.asm b/SoundEngine/famistudio_asm6.asm index e768768e7..7e4d9d9da 100644 --- a/SoundEngine/famistudio_asm6.asm +++ b/SoundEngine/famistudio_asm6.asm @@ -6540,39 +6540,63 @@ famistudio_sfx_play: asl a tay -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS = 4 ; Check if the high priority sound effects is playing - cpx #FAMISTUDIO_SFX_CH3 - beq @write_channel - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS = 3 - cpx #FAMISTUDIO_SFX_CH2 - beq @write_channel - .endif +.if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays + cpx #FAMISTUDIO_SFX_CH3 + bcs @write_ch3 + cpx #FAMISTUDIO_SFX_CH2 + bcs @write_ch2 + cpx #FAMISTUDIO_SFX_CH1 + bcs @write_ch1 + cpx #FAMISTUDIO_SFX_CH0 + bcs @write_ch0 + +@write_ch3: + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH3 + jsr famistudio_sfx_clear_channel + jmp @write_channel - .if FAMISTUDIO_CFG_SFX_STREAMS = 2 - cpx #FAMISTUDIO_SFX_CH1 - beq @write_channel - .endif +@write_ch2: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + jmp @write_channel - .if FAMISTUDIO_CFG_SFX_STREAMS > 3 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - .endif - .if FAMISTUDIO_CFG_SFX_STREAMS > 2 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne @ignore_channel - .endif - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 - bne @ignore_channel - .endif +@write_ch1: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + jmp @write_channel + +@write_ch0: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne @ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel +.else + jsr famistudio_sfx_clear_channel ; Stops the effect if it plays .endif @write_channel: - jsr famistudio_sfx_clear_channel ; Stops the effect if it plays - lda famistudio_sfx_addr_lo sta effect_data_ptr+0 lda famistudio_sfx_addr_hi @@ -6607,50 +6631,12 @@ famistudio_sfx_update: bne @update_buf ; Just mix with output buffer @no_repeat: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - stx tmp - .endif -.endif lda famistudio_sfx_ptr_hi,x ; Check if MSB of the pointer is not zero - bne @clear_other_channel + bne @sfx_active rts ; Return otherwise, no active effect -@clear_other_channel: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - cpx #FAMISTUDIO_SFX_CH0 - beq @sfx_active - - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx tmp - cpx #FAMISTUDIO_SFX_CH1 - beq @sfx_active - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS > 2 - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx tmp - cpx #FAMISTUDIO_SFX_CH2 - beq @sfx_active - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS > 3 - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - ldx tmp - .endif -.endif - @sfx_active: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - lda famistudio_sfx_ptr_hi,x ; Load effect pointer into temp - .endif -.endif - sta effect_data_ptr+1 + sta effect_data_ptr+1 ;load effect pointer into temp lda famistudio_sfx_ptr_lo,x sta effect_data_ptr+0 ldy famistudio_sfx_offset,x diff --git a/SoundEngine/famistudio_ca65.s b/SoundEngine/famistudio_ca65.s index d29611c2c..16ab8eab8 100644 --- a/SoundEngine/famistudio_ca65.s +++ b/SoundEngine/famistudio_ca65.s @@ -6586,39 +6586,63 @@ famistudio_sfx_play: asl a tay -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS = 4 ; Check if the high priority sound effects is playing - cpx #FAMISTUDIO_SFX_CH3 - beq @write_channel - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS = 3 - cpx #FAMISTUDIO_SFX_CH2 - beq @write_channel - .endif +.if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays + cpx #FAMISTUDIO_SFX_CH3 + bcs @write_ch3 + cpx #FAMISTUDIO_SFX_CH2 + bcs @write_ch2 + cpx #FAMISTUDIO_SFX_CH1 + bcs @write_ch1 + cpx #FAMISTUDIO_SFX_CH0 + bcs @write_ch0 + +@write_ch3: + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH3 + jsr famistudio_sfx_clear_channel + jmp @write_channel - .if FAMISTUDIO_CFG_SFX_STREAMS = 2 - cpx #FAMISTUDIO_SFX_CH1 - beq @write_channel - .endif +@write_ch2: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + jmp @write_channel - .if FAMISTUDIO_CFG_SFX_STREAMS > 3 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - .endif - .if FAMISTUDIO_CFG_SFX_STREAMS > 2 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne @ignore_channel - .endif - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 - bne @ignore_channel - .endif +@write_ch1: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + jmp @write_channel + +@write_ch0: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne @ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel +.else + jsr famistudio_sfx_clear_channel ; Stops the effect if it plays .endif @write_channel: - jsr famistudio_sfx_clear_channel ; Stops the effect if it plays - lda famistudio_sfx_addr_lo sta @effect_data_ptr+0 lda famistudio_sfx_addr_hi @@ -6653,50 +6677,12 @@ famistudio_sfx_update: bne @update_buf ; Just mix with output buffer @no_repeat: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - stx @tmp - .endif -.endif lda famistudio_sfx_ptr_hi,x ; Check if MSB of the pointer is not zero - bne @clear_other_channel + bne @sfx_active rts ; Return otherwise, no active effect -@clear_other_channel: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - cpx #FAMISTUDIO_SFX_CH0 - beq @sfx_active - - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx @tmp - cpx #FAMISTUDIO_SFX_CH1 - beq @sfx_active - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS > 2 - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx @tmp - cpx #FAMISTUDIO_SFX_CH2 - beq @sfx_active - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS > 3 - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - ldx @tmp - .endif -.endif - @sfx_active: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - lda famistudio_sfx_ptr_hi,x ; Load effect pointer into temp - .endif -.endif - sta @effect_data_ptr+1 + sta @effect_data_ptr+1 ;load effect pointer into temp lda famistudio_sfx_ptr_lo,x sta @effect_data_ptr+0 ldy famistudio_sfx_offset,x diff --git a/SoundEngine/famistudio_nesasm.asm b/SoundEngine/famistudio_nesasm.asm index 7372d76f4..c329b009a 100644 --- a/SoundEngine/famistudio_nesasm.asm +++ b/SoundEngine/famistudio_nesasm.asm @@ -6599,39 +6599,63 @@ famistudio_sfx_play: asl a tay - .if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS = 4 ; Check if the high priority sound effects is playing - cpx #FAMISTUDIO_SFX_CH3 - beq .write_channel - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS = 3 - cpx #FAMISTUDIO_SFX_CH2 - beq .write_channel - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS = 2 - cpx #FAMISTUDIO_SFX_CH1 - beq .write_channel - .endif +.if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays + cpx #FAMISTUDIO_SFX_CH3 + bcs .write_ch3 + cpx #FAMISTUDIO_SFX_CH2 + bcs .write_ch2 + cpx #FAMISTUDIO_SFX_CH1 + bcs .write_ch1 + cpx #FAMISTUDIO_SFX_CH0 + bcs .write_ch0 + +.write_ch3: + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH3 + jsr famistudio_sfx_clear_channel + jmp .write_channel - .if FAMISTUDIO_CFG_SFX_STREAMS > 3 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne .ignore_channel - .endif - .if FAMISTUDIO_CFG_SFX_STREAMS > 2 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne .ignore_channel - .endif - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 - bne .ignore_channel - .endif - .endif +.write_ch2: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne .ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + jmp .write_channel -.write_channel: +.write_ch1: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne .ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne .ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + jmp .write_channel + +.write_ch0: + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne .ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne .ignore_channel + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne .ignore_channel + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel +.else jsr famistudio_sfx_clear_channel ; Stops the effect if it plays +.endif +.write_channel: lda famistudio_sfx_addr_lo sta <.effect_data_ptr+0 lda famistudio_sfx_addr_hi @@ -6666,50 +6690,12 @@ famistudio_sfx_update: bne .update_buf ; Just mix with output buffer .no_repeat: - .if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - stx tmp - .endif - .endif lda famistudio_sfx_ptr_hi,x ; Check if MSB of the pointer is not zero - bne .clear_other_channel + bne .sfx_active rts ; Return otherwise, no active effect -.clear_other_channel: -.if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - cpx #FAMISTUDIO_SFX_CH0 - beq .sfx_active - - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx tmp - cpx #FAMISTUDIO_SFX_CH1 - beq .sfx_active - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS > 2 - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx tmp - cpx #FAMISTUDIO_SFX_CH2 - beq .sfx_active - .endif - - .if FAMISTUDIO_CFG_SFX_STREAMS > 3 - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - ldx tmp - .endif -.endif - .sfx_active: - .if FAMISTUDIO_CFG_SFX_MIXED = 0 - .if FAMISTUDIO_CFG_SFX_STREAMS > 1 - lda famistudio_sfx_ptr_hi,x ; Load effect pointer into temp - .endif - .endif - sta <.effect_data_ptr+1 + sta <.effect_data_ptr+1 ;load effect pointer into temp lda famistudio_sfx_ptr_lo,x sta <.effect_data_ptr+0 ldy famistudio_sfx_offset,x From 9b2eb19378dab7e6de6fca6435ba13c6a9b23a56 Mon Sep 17 00:00:00 2001 From: The With Commands <67952504+TheWithCommands@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:43:30 +0800 Subject: [PATCH 4/5] Decide which code is available by FAMISTUDIO_CFG_SFX_STREAMS --- SoundEngine/famistudio_asm6.asm | 125 ++++++++++++++++++------------ SoundEngine/famistudio_ca65.s | 125 ++++++++++++++++++------------ SoundEngine/famistudio_nesasm.asm | 125 ++++++++++++++++++------------ 3 files changed, 228 insertions(+), 147 deletions(-) diff --git a/SoundEngine/famistudio_asm6.asm b/SoundEngine/famistudio_asm6.asm index 7e4d9d9da..febdb18dc 100644 --- a/SoundEngine/famistudio_asm6.asm +++ b/SoundEngine/famistudio_asm6.asm @@ -6541,57 +6541,84 @@ famistudio_sfx_play: tay .if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays - cpx #FAMISTUDIO_SFX_CH3 - bcs @write_ch3 - cpx #FAMISTUDIO_SFX_CH2 - bcs @write_ch2 - cpx #FAMISTUDIO_SFX_CH1 - bcs @write_ch1 - cpx #FAMISTUDIO_SFX_CH0 - bcs @write_ch0 - -@write_ch3: - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH3 - jsr famistudio_sfx_clear_channel - jmp @write_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + cpx #FAMISTUDIO_SFX_CH3 + bcs @write_ch3 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + cpx #FAMISTUDIO_SFX_CH2 + bcs @write_ch2 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + cpx #FAMISTUDIO_SFX_CH1 + bcs @write_ch1 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 0 + jmp @write_ch0 + .endif -@write_ch2: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - jmp @write_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + @write_ch3: + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH3 + jsr famistudio_sfx_clear_channel + jmp @write_channel + .endif -@write_ch1: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne @ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - jmp @write_channel - -@write_ch0: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne @ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 - bne @ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + @write_ch2: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 ; Check if the high priority sound effect stream(s) is playing, ignore if it is playing + bne @ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + jmp @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + @write_ch1: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + jmp @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 0 + @write_ch0: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne @ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + .endif .else jsr famistudio_sfx_clear_channel ; Stops the effect if it plays .endif diff --git a/SoundEngine/famistudio_ca65.s b/SoundEngine/famistudio_ca65.s index 16ab8eab8..f2a20185b 100644 --- a/SoundEngine/famistudio_ca65.s +++ b/SoundEngine/famistudio_ca65.s @@ -6587,57 +6587,84 @@ famistudio_sfx_play: tay .if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays - cpx #FAMISTUDIO_SFX_CH3 - bcs @write_ch3 - cpx #FAMISTUDIO_SFX_CH2 - bcs @write_ch2 - cpx #FAMISTUDIO_SFX_CH1 - bcs @write_ch1 - cpx #FAMISTUDIO_SFX_CH0 - bcs @write_ch0 - -@write_ch3: - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH3 - jsr famistudio_sfx_clear_channel - jmp @write_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + cpx #FAMISTUDIO_SFX_CH3 + bcs @write_ch3 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + cpx #FAMISTUDIO_SFX_CH2 + bcs @write_ch2 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + cpx #FAMISTUDIO_SFX_CH1 + bcs @write_ch1 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 0 + jmp @write_ch0 + .endif -@write_ch2: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - jmp @write_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + @write_ch3: + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH3 + jsr famistudio_sfx_clear_channel + jmp @write_channel + .endif -@write_ch1: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne @ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - jmp @write_channel - -@write_ch0: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne @ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne @ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 - bne @ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + @write_ch2: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 ; Check if the high priority sound effect stream(s) is playing, ignore if it is playing + bne @ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + jmp @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + @write_ch1: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + jmp @write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 0 + @write_ch0: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne @ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne @ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + .endif .else jsr famistudio_sfx_clear_channel ; Stops the effect if it plays .endif diff --git a/SoundEngine/famistudio_nesasm.asm b/SoundEngine/famistudio_nesasm.asm index c329b009a..4814f4534 100644 --- a/SoundEngine/famistudio_nesasm.asm +++ b/SoundEngine/famistudio_nesasm.asm @@ -6600,57 +6600,84 @@ famistudio_sfx_play: tay .if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays - cpx #FAMISTUDIO_SFX_CH3 - bcs .write_ch3 - cpx #FAMISTUDIO_SFX_CH2 - bcs .write_ch2 - cpx #FAMISTUDIO_SFX_CH1 - bcs .write_ch1 - cpx #FAMISTUDIO_SFX_CH0 - bcs .write_ch0 - -.write_ch3: - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH3 - jsr famistudio_sfx_clear_channel - jmp .write_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + cpx #FAMISTUDIO_SFX_CH3 + bcs .write_ch3 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + cpx #FAMISTUDIO_SFX_CH2 + bcs .write_ch2 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + cpx #FAMISTUDIO_SFX_CH1 + bcs .write_ch1 + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 0 + jmp .write_ch0 + .endif -.write_ch2: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne .ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH2 - jsr famistudio_sfx_clear_channel - jmp .write_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + .write_ch3: + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH3 + jsr famistudio_sfx_clear_channel + jmp .write_channel + .endif -.write_ch1: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne .ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne .ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel - ldx #FAMISTUDIO_SFX_CH1 - jsr famistudio_sfx_clear_channel - jmp .write_channel - -.write_ch0: - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 - bne .ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 - bne .ignore_channel - lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 - bne .ignore_channel - ldx #FAMISTUDIO_SFX_CH0 - jsr famistudio_sfx_clear_channel + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + .write_ch2: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 ; Check if the high priority sound effect stream(s) is playing, ignore if it is playing + bne .ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH2 + jsr famistudio_sfx_clear_channel + jmp .write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + .write_ch1: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne .ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne .ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + ldx #FAMISTUDIO_SFX_CH1 + jsr famistudio_sfx_clear_channel + jmp .write_channel + .endif + + .if FAMISTUDIO_CFG_SFX_STREAMS > 0 + .write_ch0: + .if FAMISTUDIO_CFG_SFX_STREAMS > 3 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH3 + bne .ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 2 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH2 + bne .ignore_channel + .endif + .if FAMISTUDIO_CFG_SFX_STREAMS > 1 + lda famistudio_sfx_ptr_hi+FAMISTUDIO_SFX_CH1 + bne .ignore_channel + .endif + ldx #FAMISTUDIO_SFX_CH0 + jsr famistudio_sfx_clear_channel + .endif .else jsr famistudio_sfx_clear_channel ; Stops the effect if it plays .endif From 930768e699fe9b1f9cfa56c2428d2e08dbde25ab Mon Sep 17 00:00:00 2001 From: The With Commands <67952504+TheWithCommands@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:56:06 +0800 Subject: [PATCH 5/5] If there is only one channel, FAMISTUDIO_CFG_SFX_MIXED is meaningless --- SoundEngine/famistudio_asm6.asm | 2 +- SoundEngine/famistudio_ca65.s | 2 +- SoundEngine/famistudio_nesasm.asm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SoundEngine/famistudio_asm6.asm b/SoundEngine/famistudio_asm6.asm index febdb18dc..3a6c19dbb 100644 --- a/SoundEngine/famistudio_asm6.asm +++ b/SoundEngine/famistudio_asm6.asm @@ -6540,7 +6540,7 @@ famistudio_sfx_play: asl a tay -.if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays +.if (FAMISTUDIO_CFG_SFX_MIXED = 0) && (FAMISTUDIO_CFG_SFX_STREAMS > 1) ; Stop being selected and its preceding effects during plays .if FAMISTUDIO_CFG_SFX_STREAMS > 3 cpx #FAMISTUDIO_SFX_CH3 bcs @write_ch3 diff --git a/SoundEngine/famistudio_ca65.s b/SoundEngine/famistudio_ca65.s index f2a20185b..2be7a3eb0 100644 --- a/SoundEngine/famistudio_ca65.s +++ b/SoundEngine/famistudio_ca65.s @@ -6586,7 +6586,7 @@ famistudio_sfx_play: asl a tay -.if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays +.if (FAMISTUDIO_CFG_SFX_MIXED = 0) && (FAMISTUDIO_CFG_SFX_STREAMS > 1) ; Stop being selected and its preceding effects during plays .if FAMISTUDIO_CFG_SFX_STREAMS > 3 cpx #FAMISTUDIO_SFX_CH3 bcs @write_ch3 diff --git a/SoundEngine/famistudio_nesasm.asm b/SoundEngine/famistudio_nesasm.asm index 4814f4534..6cb0d5494 100644 --- a/SoundEngine/famistudio_nesasm.asm +++ b/SoundEngine/famistudio_nesasm.asm @@ -6599,7 +6599,7 @@ famistudio_sfx_play: asl a tay -.if FAMISTUDIO_CFG_SFX_MIXED = 0 ; Stop being selected and its preceding effects during plays +.if (FAMISTUDIO_CFG_SFX_MIXED = 0) & (FAMISTUDIO_CFG_SFX_STREAMS > 1) ; Stop being selected and its preceding effects during plays .if FAMISTUDIO_CFG_SFX_STREAMS > 3 cpx #FAMISTUDIO_SFX_CH3 bcs .write_ch3