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