Unified · Split
| @@ -106,7 +106,7 @@ void tSample_clear (tSample* const s) · 105 unmodified lines | ||
| 106 | 106 | |
| 107 | 107 | //============================================================================== |
| 108 | 108 | |
| 109 | −#define CFX 30 | |
| 109 | +#define CFX 300 | |
| 110 | 110 | |
| 111 | 111 | void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) |
| 112 | 112 | { |
| @@ -144,15 +144,25 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 31 unmodified lines | ||
| 144 | 144 | |
| 145 | 145 | float sample = 0.f; |
| 146 | 146 | float cfxsample = 0.f; |
| 147 | − int cfx = CFX; | |
| 147 | + int cfx = CFX; // make this part of class | |
| 148 | 148 | |
| 149 | 149 | float* buff = p->samp->buff; |
| 150 | 150 | |
| 151 | 151 | int dir = p->dir * p->flip; |
| 152 | 152 | |
| 153 | − int idx = (int) p->idx; | |
| 154 | − float alpha = p->idx - idx; | |
| 155 | − float idxx; | |
| 153 | + int idx; | |
| 154 | + float alpha; | |
| 155 | + | |
| 156 | + if (dir > 0) | |
| 157 | + { | |
| 158 | + idx = (int) p->idx; | |
| 159 | + alpha = p->idx - idx; | |
| 160 | + } | |
| 161 | + else | |
| 162 | + { | |
| 163 | + idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards | |
| 164 | + alpha = (p->idx+1.f) - idx; | |
| 165 | + } | |
| 156 | 166 | |
| 157 | 167 | int32_t start = p->start, end = p->end; |
| 158 | 168 | if (p->flip < 0) |
| @@ -179,16 +189,13 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 20 unmodified lines | ||
| 179 | 189 | buff[i4], |
| 180 | 190 | alpha); |
| 181 | 191 | |
| 182 | − //printf("cidx: %d\n", idx); | |
| 183 | − | |
| 184 | − cfx = (end - idx) / p->inc; | |
| 185 | − | |
| 192 | + cfx = (end - idx) / p->inc; // num samples to end of loop, use inverse increment | |
| 193 | + | |
| 186 | 194 | if (cfx <= CFX) |
| 187 | 195 | { |
| 188 | 196 | // CROSSFADE SAMPLE |
| 189 | − idxx = p->idx - p->len; | |
| 197 | + float idxx = p->idx - p->len; | |
| 190 | 198 | int cdx = (int)(idxx); |
| 191 | − float alpha = idxx - cdx; | |
| 192 | 199 | |
| 193 | 200 | i1 = cdx-1; |
| 194 | 201 | i3 = cdx+1; |
| @@ -213,7 +220,7 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 18 unmodified lines | ||
| 213 | 220 | |
| 214 | 221 | if (i1 > end) i1 -= p->len; |
| 215 | 222 | if (i3 < start) i3 += p->len; |
| 216 | − if (i4 < start) i4 += p->len; | |
| 223 | + if (i4 < start) i4 += p->len; | |
| 217 | 224 | |
| 218 | 225 | sample = LEAF_interpolate_hermite (buff[i1], |
| 219 | 226 | buff[idx], |
| @@ -226,9 +233,9 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 6 unmodified lines | ||
| 226 | 233 | if (cfx <= CFX) |
| 227 | 234 | { |
| 228 | 235 | // CROSSFADE SAMPLE |
| 229 | − idxx = p->idx + p->len; | |
| 236 | + float idxx = p->idx + p->len + 1.f; | |
| 230 | 237 | int cdx = (int)(idxx); |
| 231 | − float alpha = idxx - cdx; | |
| 238 | + alpha = idxx - cdx; | |
| 232 | 239 | |
| 233 | 240 | i1 = cdx+1; |
| 234 | 241 | i3 = cdx-1; |
| @@ -238,7 +245,7 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 3 unmodified lines | ||
| 238 | 245 | buff[cdx], |
| 239 | 246 | buff[i3], |
| 240 | 247 | buff[i4], |
| 241 | − alpha); | |
| 248 | + 1.f-alpha); | |
| 242 | 249 | } |
| 243 | 250 | else cfx = CFX; |
| 244 | 251 | } |