Fixes values spiking due to bad sample memory accesses #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the clicks and staticy noises in the modules in #1. That is, the ones that make these messages:
There are two things that cause this problem in the
xm_next_of_sample(xm_channel_context_t* ch)
function – either the sample length is 0, and when it grabsu = ch->sample->data[a];
it reads into memory that does not belong to it, so we have that if at the start to check the sample length is more than zero.What can also happen is that the 'loop end point' extends past the actual end of the sample. Just by one tick, so
ch->sample_position
was getting set to 132 at the end of a sample that was only 132 long, resulting in the same sort of read into memory that does not belong to it.Anyways, this fixes both of those issues and the clipping. I'm fairly sure Milkytracker handles this in the same way, clamping the loop end to the sample length.
edit: I'm not sure whether this sort of fix should also be applied to the other loop types. I had to quickly type this up a few minutes before running to work, but otherwise I'll look into it when I get home.