| @@ -105,6 +105,8 @@ void tSample_clear (tSample* const s) · 104 unmodified lines |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | //============================================================================== |
| 108 | + |
| 109 | +#define CFX 50 |
| 108 | 110 | |
| 109 | 111 | void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) |
| 110 | 112 | { |
| @@ -124,7 +126,8 @@ void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) · 13 unmodified lines |
| 124 | 126 | |
| 125 | 127 | p->mode = Normal; |
| 126 | 128 | |
| 127 | | − p->gain = 1.; |
| 129 | + p->g1 = 1.f; |
| 130 | + p->g2 = 0.f; |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | 133 | void tSamplePlayer_free (tSamplePlayer* const p) |
| @@ -140,6 +143,7 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 9 unmodified lines |
| 140 | 143 | if (p->active == 0 || (p->len < 4)) return 0.f; |
| 141 | 144 | |
| 142 | 145 | float sample = 0.f; |
| 146 | + float cfxsample = 0.f; |
| 143 | 147 | |
| 144 | 148 | float* buff = p->samp->buff; |
| 145 | 149 | |
| @@ -148,17 +152,20 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 2 unmodified lines |
| 148 | 152 | int idx = (int) p->idx; |
| 149 | 153 | float alpha = p->idx - idx; |
| 150 | 154 | |
| 151 | | − uint32_t start = p->start, end = p->end; |
| 155 | + int32_t start = p->start, end = p->end; |
| 152 | 156 | if (p->flip < 0) |
| 153 | 157 | { |
| 154 | 158 | start = p->end; |
| 155 | 159 | end = p->start; |
| 156 | 160 | } |
| 157 | 161 | |
| 162 | + p->g1 = 1.f; |
| 163 | + p->g2 = 0.f; |
| 164 | + |
| 158 | 165 | // Check dir (direction) to interpolate properly |
| 159 | 166 | if (dir > 0) |
| 160 | 167 | { |
| 161 | | − // FORWARD |
| 168 | + // FORWARD NORMAL SAMPLE |
| 162 | 169 | int i1 = idx-1; |
| 163 | 170 | int i3 = idx+1; |
| 164 | 171 | int i4 = idx+2; |
| @@ -172,6 +179,24 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 7 unmodified lines |
| 172 | 179 | buff[i3], |
| 173 | 180 | buff[i4], |
| 174 | 181 | alpha); |
| 182 | + if ((end - idx) <= CFX) |
| 183 | + { |
| 184 | + // CROSSFADE SAMPLE |
| 185 | + int cdx = idx - p->len; |
| 186 | + |
| 187 | + i1 = cdx-1; |
| 188 | + i3 = cdx+1; |
| 189 | + i4 = cdx+2; |
| 190 | + |
| 191 | + cfxsample = LEAF_interpolate_hermite (buff[i1], |
| 192 | + buff[idx], |
| 193 | + buff[i3], |
| 194 | + buff[i4], |
| 195 | + alpha); |
| 196 | + |
| 197 | + p->g2 = (float) (CFX - (end - idx - 1)) / (float) CFX; |
| 198 | + p->g1 = 1.f - p->g2; |
| 199 | + } |
| 175 | 200 | } |
| 176 | 201 | else |
| 177 | 202 | { |
| @@ -188,40 +213,53 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 10 unmodified lines |
| 188 | 213 | buff[idx], |
| 189 | 214 | buff[i3], |
| 190 | 215 | buff[i4], |
| 191 | | − alpha); |
| 216 | + 1.0f-alpha); |
| 217 | + |
| 218 | + if ((idx - start) <= CFX) |
| 219 | + { |
| 220 | + // CROSSFADE SAMPLE |
| 221 | + int cdx = idx + p->len; |
| 222 | + |
| 223 | + i1 = cdx+1; |
| 224 | + i3 = cdx-1; |
| 225 | + i4 = cdx-2; |
| 226 | + |
| 227 | + cfxsample = LEAF_interpolate_hermite (buff[i1], |
| 228 | + buff[idx], |
| 229 | + buff[i3], |
| 230 | + buff[i4], |
| 231 | + alpha); |
| 232 | + |
| 233 | + p->g2 = (float) (CFX - (idx - start - 1)) / (float) CFX; |
| 234 | + p->g1 = 1.f - p->g2; |
| 235 | + } |
| 192 | 236 | } |
| 193 | 237 | |
| 194 | 238 | p->idx += (dir * p->inc); |
| 195 | 239 | |
| 196 | | − if (p->mode != BackAndForth) |
| 240 | + if (p->mode != BackAndForth ) // == Normal or Loop |
| 197 | 241 | { |
| 198 | | − // Check flip bit to change loop test |
| 199 | 242 | if (idx <= start) |
| 200 | 243 | { |
| 201 | | − // -inc |
| 202 | 244 | p->idx += (float)(p->len); |
| 203 | 245 | p->cnt++; |
| 204 | 246 | } |
| 205 | 247 | else if (idx >= end) |
| 206 | 248 | { |
| 207 | | − // +inc |
| 208 | 249 | p->idx -= (float)(p->len); |
| 209 | 250 | p->cnt++; |
| 210 | 251 | } |
| 211 | | − |
| 212 | 252 | } |
| 213 | | − else // BackAndForth |
| 253 | + else // == BackAndForth |
| 214 | 254 | { |
| 215 | | − if ((idx < start) || (idx > end)) |
| 255 | + if ((idx <= start) || (idx >= end)) |
| 216 | 256 | { |
| 217 | 257 | p->dir = -p->dir; |
| 218 | | − p->idx += (2*p->inc); |
| 219 | 258 | p->cnt++; |
| 220 | 259 | } |
| 221 | 260 | } |
| 222 | 261 | |
| 223 | | − |
| 224 | | − return sample * p->gain; |
| 262 | + return sample * p->g1 + cfxsample * p->g2; |
| 225 | 263 | } |
| 226 | 264 | |
| 227 | 265 | void tSamplePlayer_setSample (tSamplePlayer* const p, tSample* s) |
| @@ -238,6 +276,17 @@ void tSamplePlayer_play (tSamplePlayer* const p) · 10 unmodified lines |
| 238 | 276 | { |
| 239 | 277 | p->active = 1; |
| 240 | 278 | p->cnt = 0; |
| 279 | + |
| 280 | + if (p->dir > 0) |
| 281 | + { |
| 282 | + if (p->flip > 0) p->idx = p->start; |
| 283 | + else p->idx = p->end; |
| 284 | + } |
| 285 | + else |
| 286 | + { |
| 287 | + if (p->flip > 0) p->idx = p->end; |
| 288 | + else p->idx = p->start; |
| 289 | + } |
| 241 | 290 | } |
| 242 | 291 | |
| 243 | 292 | void tSamplePlayer_stop (tSamplePlayer* const p) |