| Re: [hatari-devel] DSP bug found (and maybe solved) | 
[ Thread Index | 
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
] 
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] DSP bug found (and maybe solved)
- From: Andreas Grabher <andreas_g86@xxxxxxxxxx>
- Date: Mon, 15 Apr 2024 11:50:01 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com;	s=1a1hai; t=1713174616;	bh=FzXNRWBgtWFRA1mnHJgKRwmpWbsZJafzb1xZOQhO48Q=;	h=Content-Type:From:Mime-Version:Subject:Date:Message-Id:To;	b=VT98bZKGyVaoPrPEJiTiDm88hR1h5Ph9l5572bCDsKhOYCKlF1RCcj7yhiHmu9J0M	 OhsNGvGAwLfbOa1kjlufJTFjmT4ABOTrytm/5GEGaFwG9qPuoNUGuCeu0yhiWnW/S3	 PhLBnZqkzwZsBARFdTlMf0P9FtsTw6hHNZ1OvU9FLsXvdk9XMG/R6r841zjX9lPEjq	 2eLM3Pv9Li+ZBIYEU4TseHIAyd4UJaLmvUCgVvaOm4MYa/BH3xYQwB9+hZgFkjOdnx	 KVYYnDfk8HkmpVOM+fgLG1EMPy4TKU/VWCnwu483H9wMUAa6rUs6vdujM+JgOcxJiA	 DOw0F/a6aAq7Q==
> Am 14.04.2024 um 23:48 schrieb Laurent Sallafranque <laurent.sallafranque@xxxxxxx>:
> 
> Hi all,
> 
> 
> I've spent the last 2 weeks tracing Audio Fun Machine to find the bug when the equalizer is ON (sound becomes noisy).
> 
> 
> I've isolated the bug : it's about Rn + Nn + Mn updating.
> An example :
>             move    #>0,r0                     ; R0 = 0
>             movec    #$01,m0                ; modulo 2
>             move    #$02,n0                   ; incrementor = 2
> 
>             move    #>1,a
>             move    #>1,b
>             move    a,x:(r0)+                 ; r0 = 1
>             nop
>             nop
>             move    b,x:(r0)+                 ; r0 = 0  (because of the modulo)
>             nop
>             nop
>             move    (r0)+n0                   ; R0 = 0 (should be 2)
>             nop
>             nop
>             move    a,x:(r0)+                 ; R0 = 1 (should be 3)
> 
> 
> I suggest the following fix in the function :
> static void dsp_update_rn_modulo(uint32_t numreg, int16_t modifier)
> 
> Line 1694 :
> replace
>     if (abs_modifier>modulo) {
> by
>     if (abs_modifier>modulo-1) {
> 
> 
> In line 1673, modulo is added +1 for buffer boundaries computing.
> But I think modulo should be -1 when tested with modifier.
> 
> At least, Audio Fun Machine sound becomes good with this patch, but DSP programs should be tested for non regression.
> I've tested 2 or 3 of them, but not all of them.
> 
> @eero, could you test my patch and tell me if AFM works well for you ?
> 
> 
> Regards
> 
> Laurent
> 
Great discovery! Obviously the special case where abs_modifier equals modulo was not handled. I think the more logical solution would be
if (abs_modifier>=modulo)