Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popping/crackling sound #24

Open
mheyer32 opened this issue Sep 6, 2022 · 6 comments
Open

Popping/crackling sound #24

mheyer32 opened this issue Sep 6, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@mheyer32
Copy link
Owner

mheyer32 commented Sep 6, 2022

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)
@0xABADCAFE
Copy link
Collaborator

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

@mheyer32
Copy link
Owner Author

mheyer32 commented Sep 6, 2022

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

@mheyer32 mheyer32 added the bug Something isn't working label Sep 6, 2022
@0xABADCAFE
Copy link
Collaborator

This is the better ticket though.

@0xABADCAFE
Copy link
Collaborator

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.

@mheyer32
Copy link
Owner Author

I tried a workaround here: 0a1fc4e

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.

@0xABADCAFE
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants