Skip to content

Commit

Permalink
Fix static sounds due to bad sample memory access in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielOaks committed Jan 9, 2015
1 parent 467d312 commit f24bcab
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/play.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Author: Romain "Artefact2" Dalmaso <artefact2@gmail.com> */
/* Contributor: Daniel Oaks <daniel@danieloaks.net> */

/* This program is free software. It comes without any warranty, to the
* extent permitted by applicable law. You can redistribute it and/or
Expand Down Expand Up @@ -1209,6 +1210,9 @@ static float xm_next_of_sample(xm_channel_context_t* ch) {
}
return .0f;
}
if(ch->sample->length == 0) {
return .0f;
}

float u, v, t;
uint32_t a, b;
Expand Down Expand Up @@ -1262,6 +1266,11 @@ static float xm_next_of_sample(xm_channel_context_t* ch) {
ch->ping = false;
ch->sample_position = (ch->sample->loop_end << 1) - ch->sample_position;
}
/* sanity checking */
if(ch->sample_position >= ch->sample->length) {
ch->ping = false;
ch->sample_position -= ch->sample->length - 1;
}
} else {
if(XM_LINEAR_INTERPOLATION) {
v = u;
Expand All @@ -1271,6 +1280,11 @@ static float xm_next_of_sample(xm_channel_context_t* ch) {
ch->ping = true;
ch->sample_position = (ch->sample->loop_start << 1) - ch->sample_position;
}
/* sanity checking */
if(ch->sample_position <= .0f) {
ch->ping = true;
ch->sample_position = .0f;
}
}
break;

Expand Down

0 comments on commit f24bcab

Please sign in to comment.