From b805349bf07780b85c621b5622d915872bfb85ba Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Tue, 22 Aug 2023 22:32:51 +0200 Subject: [PATCH] Noise wave generation code optimized. --- README.md | 7 ++-- binaries/raspberry_casket.bin | Bin 5760 -> 5732 bytes src/raspberry_casket.asm | 4 +- src/raspberry_casket_wavegen.asm | 65 +++++++++++++++---------------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 91c84bf..17e0716 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Raspberry Casket A fast and small open source Pretracker replayer -## Raspberry Casket Player V2.x (10-Aug-2023) +## Raspberry Casket Player V2.x (22-Aug-2023) Provided by Chris 'platon42' Hodges @@ -101,7 +101,7 @@ The original code compressed with *Blueberry's* Shrinkler goes from 18052 bytes down to 9023 bytes. Raspberry Casket, depending on the features compiled in, is about -5784 bytes and shrinkles down to ~4118 bytes (in isolation). +5732 bytes and shrinkles down to ~4084 bytes (in isolation). So this means that the optimization is not just "on the outside". @@ -168,8 +168,9 @@ solve this problem. - Bugfix: Songend detection for back-jumps was broken since at least V1.1. - Optimized some more wave selection code. - Nosync/sync wave selection optimized. +- Optimized wave generation a bit more (noise generator). - Added Presto player draft. -- Drop-in replacement code size: 5784 bytes. +- Drop-in replacement code size: 5732 bytes. ### V1.x (unreleased) - Fixed a bug regarding the copper output mode with looping waves having a loop-offset. diff --git a/binaries/raspberry_casket.bin b/binaries/raspberry_casket.bin index 3ad90c0cc7b757856f9cf5792103a5e2e230e79d..458a838892bd82a14289735c672c3f410aaccbbb 100644 GIT binary patch delta 226 zcmZqBeWJs|z`y{+j8zN_TxJt_w3s+QOth$G^qIKjD&xG#U5uKHJ(IUEu4YV`oWL}d z(P;8Frcg$k$v(`fjAtfqVooy>SM1J@3)zKVt&HIsu_V}Vv~V3lTU z+I)u9gOO_=Sgx*NU(IAW_6uAaz}$j{4K!9(G%MEMqeVGfl+MNpZfp# zhY}e6=S;3)*}%o)0#aYmz~eI6j5SuasX*d@HiKrmh!S7AfR~QGVj7oa4FjXTLIT6z zw9Ok>Js7!o+(A0(8hG3%GqGRb;&A|R3mSMFCf{K{hs@o=p@qzS!Lg80Z*v#tEgk@& CC|!^M diff --git a/src/raspberry_casket.asm b/src/raspberry_casket.asm index 01ddbee..cbc6542 100755 --- a/src/raspberry_casket.asm +++ b/src/raspberry_casket.asm @@ -1,5 +1,5 @@ ;-------------------------------------------------------------------- -; Raspberry Casket Player V2.x (20-Aug-2023) +; Raspberry Casket Player V2.x (22-Aug-2023) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Provided by Chris 'platon42' Hodges @@ -96,7 +96,7 @@ ; 18052 bytes down to 9023 bytes. ; ; Raspberry Casket, depending on the features compiled in, is about -; 5784 bytes and shrinkles down to ~4118 bytes (in isolation). +; 5732 bytes and shrinkles down to ~4084 bytes (in isolation). ; ; So this means that the optimization is not just "on the outside". ; diff --git a/src/raspberry_casket_wavegen.asm b/src/raspberry_casket_wavegen.asm index 747fe26..aadca9c 100644 --- a/src/raspberry_casket_wavegen.asm +++ b/src/raspberry_casket_wavegen.asm @@ -1,25 +1,25 @@ CLIPTO8BIT MACRO - cmpi.w #-$80,\1 + cmp.w #-$80,\1 bge.s .nominclip\@ moveq.l #-$80,\1 .nominclip\@ - cmpi.w #$7F,\1 + cmp.w #$7f,\1 ble.s .nomaxclip\@ - moveq.l #$7F,\1 + moveq.l #$7f,\1 .nomaxclip\@ ENDM CLIPORTRUNC8BIT MACRO beq.s .unboosted\@ - asr.l #6,\1 - cmpi.w #-$80,\1 + asr.l #6,\1 + cmp.w #-$80,\1 bge.s .nominclip\@ moveq.l #-$80,\1 .nominclip\@ - cmpi.w #$7F,\1 + cmp.w #$7f,\1 ble.s .nomaxclip\@ - moveq.l #$7F,\1 + moveq.l #$7f,\1 bra.s .nomaxclip\@ .unboosted\@ asr.l #8,\1 @@ -254,8 +254,10 @@ pre_WaveGen: bne .no_noise ; ---------------------------------------- +; d0 = scratch ; d1 = octave ; d2 = pitch ramping value +; d4 = scratch ; a2 = base note .gen_noise IFNE PRETRACKER_PARANOIA_MODE @@ -307,6 +309,8 @@ pre_WaveGen: move.b wi_chord_shift_b(a3),d1 add.w d1,d0 addq.w #1,d0 + + ; sum of phase min and shift are used as root for noise movea.l d5,a1 movea.l pv_wg_curr_sample_ptr(a4),a0 @@ -330,30 +334,26 @@ pre_WaveGen: lsl.w #7,d1 eor.w d1,d0 - cmpa.l #$8000,a5 ; if symmetrical - beq.s .gen_noise_centered - ; FIXME what does this do? d4 = (a5 - $8000) d1 = (a5 + $7fff)&$ffff8000 -> d4 - d1 == ((a5 - $8000) - ((a5 + $7fff)&$ffff8000) - move.l a5,d4 - addi.l #$FFFF8000,d4 - move.l a5,d1 - addi.l #$FFFF7FFF,d1 - andi.w #$8000,d1 - movea.l d4,a5 - suba.l d1,a5 -.gen_noise_centered - - move.b d0,d1 + move.b d0,d1 ; take the random seed ext.w d1 - move.w d3,d4 - muls d1,d4 - move.l d4,d1 - asr.l #7,d1 + muls d3,d1 ; multiply by gain + asr.w #7,d1 CLIPTO8BIT d1 add.b (a0),d1 + move.w a5,d4 + subq.w #1,d4 + and.w #$7fff,d4 + move.w d4,a5 + addq.w #1,a5 + .gen_noise_innerloop move.b d1,(a0)+ + cmpa.l pv_wg_curr_samend_ptr(a4),a0 + beq .wave_gen_tone_done + adda.l a1,a5 + tst.l d2 beq.s .gen_noise_no_pitch_ramping add.l d2,d6 @@ -365,22 +365,21 @@ pre_WaveGen: btst #4,wi_flags_b(a3) ; pitch linear flag beq.s .noise_nonlinear_pitch - move.l d2,d4 + move.l d2,d4 ; filter pitch speed asr.l #7,d4 sub.l d4,d2 .noise_nonlinear_pitch - cmpa.w #$1FF,a1 - bgt.s .gen_noise_no_pitch_ramping - moveq.l #0,d2 + cmpa.w #$1ff,a1 + bgt.s .gen_noise_no_end_of_pitch_ramp + moveq.l #0,d2 ; stop pitch ramping move.l d2,a5 - ;suba.l a5,a5 movea.w #$200,a1 +.gen_noise_no_end_of_pitch_ramp .gen_noise_no_pitch_ramping - cmpa.l pv_wg_curr_samend_ptr(a4),a0 - beq .wave_gen_tone_done - cmpa.w #$7FFF,a5 - ble.s .gen_noise_innerloop + cmpa.w a5,a5 + beq.s .gen_noise_innerloop + bra .gen_noise_outerloop ; ----------------------------------------