| @@ -120,7 +120,7 @@ void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) · 119 unmodified lines |
| 120 | 120 | p->idx = 0.f; |
| 121 | 121 | p->inc = 1.f; |
| 122 | 122 | p->dir = 1; |
| 123 | | − p->flip = 0; |
| 123 | + p->flip = 1; |
| 124 | 124 | |
| 125 | 125 | p->mode = Normal; |
| 126 | 126 | |
| @@ -143,22 +143,30 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 16 unmodified lines |
| 143 | 143 | |
| 144 | 144 | float* buff = p->samp->buff; |
| 145 | 145 | |
| 146 | + int dir = p->dir * p->flip; |
| 147 | + |
| 146 | 148 | int idx = (int) p->idx; |
| 149 | + float alpha = p->idx - idx; |
| 150 | + |
| 151 | + uint32_t start = p->start, end = p->end; |
| 152 | + if (p->flip < 0) |
| 153 | + { |
| 154 | + start = p->end; |
| 155 | + end = p->start; |
| 156 | + } |
| 147 | 157 | |
| 148 | | − // Check dir (direction bit) to interpolate properly |
| 149 | | − if (p->dir > 0) |
| 158 | + // Check dir (direction) to interpolate properly |
| 159 | + if (dir > 0) |
| 150 | 160 | { |
| 151 | 161 | // FORWARD |
| 152 | | − float alpha = p->idx - idx; |
| 153 | | − |
| 154 | 162 | int i1 = idx-1; |
| 155 | 163 | int i3 = idx+1; |
| 156 | 164 | int i4 = idx+2; |
| 157 | 165 | |
| 158 | | − if (i1 < p->start) i1 += p->len; |
| 159 | | − if (i3 > p->end) i3 -= p->len; |
| 160 | | − if (i4 > p->end) i4 -= p->len; |
| 161 | | − |
| 166 | + if (i1 < start) i1 += p->len; |
| 167 | + if (i3 > end) i3 -= p->len; |
| 168 | + if (i4 > end) i4 -= p->len; |
| 169 | + |
| 162 | 170 | sample = LEAF_interpolate_hermite (buff[i1], |
| 163 | 171 | buff[idx], |
| 164 | 172 | buff[i3], |
| @@ -168,16 +176,14 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 3 unmodified lines |
| 168 | 176 | else |
| 169 | 177 | { |
| 170 | 178 | // REVERSE |
| 171 | | − float alpha = 1.0f - (p->idx - idx); |
| 172 | | − |
| 173 | 179 | int i1 = idx+1; |
| 174 | 180 | int i3 = idx-1; |
| 175 | 181 | int i4 = idx-2; |
| 176 | 182 | |
| 177 | | − if (i1 > p->start) i1 -= p->len; |
| 178 | | − if (i3 < p->end) i3 += p->len; |
| 179 | | − if (i4 < p->end) i4 += p->len; |
| 180 | | − |
| 183 | + if (i1 > end) i1 -= p->len; |
| 184 | + if (i3 < start) i3 += p->len; |
| 185 | + if (i4 < start) i4 += p->len; |
| 186 | + |
| 181 | 187 | sample = LEAF_interpolate_hermite (buff[i1], |
| 182 | 188 | buff[idx], |
| 183 | 189 | buff[i3], |
| @@ -185,60 +191,33 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 1 unmodified line |
| 185 | 191 | alpha); |
| 186 | 192 | } |
| 187 | 193 | |
| 188 | | − |
| 189 | | − p->idx += (p->dir * p->inc); |
| 194 | + p->idx += (dir * p->inc); |
| 190 | 195 | |
| 191 | 196 | if (p->mode != BackAndForth) |
| 192 | 197 | { |
| 193 | 198 | // Check flip bit to change loop test |
| 194 | | − if (p->flip > 0) |
| 199 | + if (idx <= start) |
| 195 | 200 | { |
| 196 | | − if (idx <= p->end) |
| 197 | | − { |
| 198 | | − p->idx += (float)(p->len); |
| 199 | | − p->cnt++; |
| 200 | | − } |
| 201 | | − else if (idx >= p->start) |
| 202 | | − { |
| 203 | | − p->idx -= (float)(p->len); |
| 204 | | − p->cnt++; |
| 205 | | − } |
| 201 | + // -inc |
| 202 | + p->idx += (float)(p->len); |
| 203 | + p->cnt++; |
| 206 | 204 | } |
| 207 | | − else |
| 205 | + else if (idx >= end) |
| 208 | 206 | { |
| 209 | | − if (idx <= p->start) |
| 210 | | − { |
| 211 | | − p->idx += (float)(p->len); |
| 212 | | − p->cnt++; |
| 213 | | − } |
| 214 | | − else if (idx >= p->end) |
| 215 | | − { |
| 216 | | − p->idx -= (float)(p->len); |
| 217 | | − p->cnt++; |
| 218 | | − } |
| 207 | + // +inc |
| 208 | + p->idx -= (float)(p->len); |
| 209 | + p->cnt++; |
| 219 | 210 | } |
| 211 | + |
| 220 | 212 | } |
| 221 | 213 | else // BackAndForth |
| 222 | 214 | { |
| 223 | | − if (p->flip > 0) |
| 215 | + if ((idx < start) || (idx > end)) |
| 224 | 216 | { |
| 225 | | − if ((idx < p->start) || (idx > p->end)) |
| 226 | | − { |
| 227 | | − p->dir = -p->dir; |
| 228 | | − p->idx += (2*p->inc); |
| 229 | | − p->cnt++; |
| 230 | | − } |
| 217 | + p->dir = -p->dir; |
| 218 | + p->idx += (2*p->inc); |
| 219 | + p->cnt++; |
| 231 | 220 | } |
| 232 | | − else |
| 233 | | − { |
| 234 | | − if ((idx > p->start) || (idx < p->end)) |
| 235 | | − { |
| 236 | | − p->dir = -p->dir; |
| 237 | | − p->idx += (2*p->inc); |
| 238 | | − p->cnt++; |
| 239 | | − } |
| 240 | | − } |
| 241 | | − |
| 242 | 221 | } |
| 243 | 222 | |
| 244 | 223 | |
| @@ -270,13 +249,11 @@ static void handleStartEndChange(tSamplePlayer* const p) · 25 unmodified lines |
| 270 | 249 | { |
| 271 | 250 | if (p->start > p->end) |
| 272 | 251 | { |
| 273 | | − p->dir = -1; |
| 274 | | − p->flip = 1; |
| 252 | + p->flip = -1; |
| 275 | 253 | } |
| 276 | 254 | else |
| 277 | 255 | { |
| 278 | | − p->dir = 1; |
| 279 | | − p->flip = 0; |
| 256 | + p->flip = 1; |
| 280 | 257 | } |
| 281 | 258 | } |
| 282 | 259 | |