alienbreed3d2 icon indicating copy to clipboard operation
alienbreed3d2 copied to clipboard

Popping/crackling sound

Open mheyer32 opened this issue 2 years ago • 6 comments

The 8 channel stereo mixing seems to introduce a lot of popping/crackling sound.

One potential issue could be that the mixing routine is overrunning the sample's buffer when mixing. This happens in part here:

https://github.com/mheyer32/alienbreed3d2/blob/main/ab3d2_source/hires.s#L10816

				moveq	#0,d0
				moveq	#0,d1
				moveq	#0,d2
				moveq	#0,d3
				moveq	#0,d4
				moveq	#0,d5
				move.w	#49,d7
loop3:
				move.l	(a0)+,d0
				move.b	(a1)+,d1
				move.b	(a1)+,d2
				move.b	(a1)+,d3
				move.b	(a1)+,d4
				move.b	(a2,d3.w),d5
				swap	d5
				move.b	(a2,d1.w),d5
				asl.l	#8,d5
				move.b	(a2,d2.w),d5
				swap	d5
				move.b	(a2,d4.w),d5
				add.l	d5,d0
				move.l	d0,(a3)+
				dbra	d7,loop3

a0 and a1 point at two sample's data. To save on processing power, the mixing routine chooses the "louder" one of the samples at full volume (the channel's volume will be adjusted for it) in a0, while the other sample's data in a1 gets mixed in (multiplied via a volume table). This loop runs straight through 50*4 = 200 samples. But its causing "Accessing invalid memory" issues in WinUAE, hinting that it overruns the end of the sample occasionally. I think there are two options to solve this

  1. make the code handle the overrun or
  2. overallocate each sample memory by 200byte and fill them with the last byte in the sample (to avoid cklicks/pops)

mheyer32 avatar Sep 06 '22 06:09 mheyer32

We should close the other issue I raised for this same problem as this one has more information.

0xABADCAFE avatar Sep 06 '22 11:09 0xABADCAFE

Oh, darn. yes, I didn't pay attention and just opened a new one.

mheyer32 avatar Sep 06 '22 16:09 mheyer32

This is the better ticket though.

0xABADCAFE avatar Sep 06 '22 20:09 0xABADCAFE

I've seen some commits around this issue but haven't pulled any upstream stuff yet. Do we know how the audio parameters were chosen? The playback rate is around 8kHz. A packet of 200 samples is therefore about 25ms. At a refresh rate of 50Hz, that's 1.25 frames.

On an aside, it has always bothered me that the audio engine is so restricted. Software mixing of fixed rate samples shouldn't be too taxing for a faster 68K. I used to run OctaMED soundstudio at 56kHz with 16 channel 14-bit output on my 040 powered A1200 with RTG. I'm not saying it should be that rate but maybe 16kHz with full 8 bit sample resolution might be nice.

0xABADCAFE avatar Sep 11 '22 10:09 0xABADCAFE

I tried a workaround here: https://github.com/mheyer32/alienbreed3d2/commit/0a1fc4e60fbee7d849359035a6c0b1d674aa1328

But it didn't have the desired effect; the invalid-memory-accesses did not go away.

I guess I need to dig some further to understand the mixing code.

mheyer32 avatar Sep 12 '22 07:09 mheyer32

An update on this. I don't know if it impacted the original game, but my mod had a sample that was not a multiple of 200 bytes. I have corrected this but I still get what sounds like early truncation of some sound effects.

0xABADCAFE avatar Nov 22 '22 16:11 0xABADCAFE