History

Fix XFade bug on 16-bit pingpong samples

This bug was accidentally ported over from the original FT2 code.

Olav Sørensen committed 6 years ago

Commit 4e1aaeb1 parent f8c0ccf4 files · +47 −37Browse files

Showing the changes to src (4 of 4 files). Show all

Unified · Split

4 files
  1. src/ft2_header.h +1 −1
  2. src/ft2_sample_ed.c +41 −31
  3. src/ft2_sample_ed.h +2 −2
  4. src/ft2_sample_ed_features.c +3 −3
src/ft2_header.h+1−1
@@ -12,7 +12,7 @@ · 11 unmodified lines
12#endif12#endif
13#include "ft2_replayer.h"13#include "ft2_replayer.h"
14 14
15#define PROG_VER_STR "1.24"15#define PROG_VER_STR "1.25"
16 16
17// do NOT change these! It will only mess things up...17// do NOT change these! It will only mess things up...
18 18
src/ft2_sample_ed.c+41−31
@@ -254,7 +254,7 @@ void restoreSample(sampleTyp *s) · 253 unmodified lines
254 }254 }
255}255}
256 256
257inline int16_t getSampleValueNr(int8_t *ptr, uint8_t typ, int32_t pos)257inline int16_t getSampleValue(int8_t *ptr, uint8_t typ, int32_t pos)
258{258{
259 assert(pos >= 0);259 assert(pos >= 0);
260 if (ptr == NULL)260 if (ptr == NULL)
@@ -271,7 +271,7 @@ inline int16_t getSampleValueNr(int8_t *ptr, uint8_t typ, int32_t pos) · 10 unmodified lines
271 }271 }
272}272}
273 273
274inline void putSampleValueNr(int8_t *ptr, uint8_t typ, int32_t pos, int16_t val)274inline void putSampleValue(int8_t *ptr, uint8_t typ, int32_t pos, int16_t val)
275{275{
276 assert(pos >= 0);276 assert(pos >= 0);
277 if (ptr == NULL)277 if (ptr == NULL)
@@ -2178,7 +2178,7 @@ void sampXFade(void) · 1900 unmodified lines
2178 2178
2179 if (x2 <= y1 || x2 >= s->repS+s->repL)2179 if (x2 <= y1 || x2 >= s->repS+s->repL)
2180 {2180 {
2181 okBox(0, "System message", "Not enough sample data outside loop!");2181 okBox(0, "System message", "Invalid range!");
2182 return;2182 return;
2183 }2183 }
2184 2184
@@ -2189,21 +2189,25 @@ void sampXFade(void) · 4 unmodified lines
2189 d2 = y1 - x1;2189 d2 = y1 - x1;
2190 d3 = x2 - y1;2190 d3 = x2 - y1;
2191 2191
2192 if (d1 < 1 || d2 < 1 || d3 < 1)2192 if (d1 < 2 || d2 < 2 || d3 < 2)
2193 {2193 {
2194 okBox(0, "System message", "Not enough sample data outside loop!");2194 okBox(0, "System message", "Invalid range!");
2195 return;2195 return;
2196 }2196 }
2197 2197
2198 if (y1-d1 < 0 || y1+d1 >= s->len)2198 if (y1-d1 < 0 || y1+d1 >= s->len)
2199 {2199 {
2200 okBox(0, "System message", "Invalid range!");2200 okBox(0, "System message", "Not enough sample data outside loop!");
2201 return;2201 return;
2202 }2202 }
2203 2203
2204 dist = 1;
2205 if (is16Bit)2204 if (is16Bit)
2206 dist++;2205 {
2206 y1 >>= 1;
2207 d1 >>= 1;
2208 d2 >>= 1;
2209 d3 >>= 1;
2210 }
2207 2211
2208 pauseAudio();2212 pauseAudio();
2209 restoreSample(s);2213 restoreSample(s);
@@ -2211,8 +2215,8 @@ void sampXFade(void) · 1 unmodified line
2211 i = 0;2215 i = 0;
2212 while (i < d1)2216 while (i < d1)
2213 {2217 {
2214 a = getSampleValueNr(s->pek, t, y1 + dist * (-i - 1));2218 a = getSampleValue(s->pek, t, (y1 - i - 1) << is16Bit);
2215 b = getSampleValueNr(s->pek, t, y1 + dist * i);2219 b = getSampleValue(s->pek, t, (y1 + i) << is16Bit);
2216 2220
2217 dS1 = 1.0 - i / (double)d2; dS2 = 2.0 - dS1;2221 dS1 = 1.0 - i / (double)d2; dS2 = 2.0 - dS1;
2218 dS3 = 1.0 - i / (double)d3; dS4 = 2.0 - dS3;2222 dS3 = 1.0 - i / (double)d3; dS4 = 2.0 - dS3;
@@ -2223,10 +2227,10 @@ void sampXFade(void) · 4 unmodified lines
2223 tmp32 = (int32_t)round((b * dS4 + a * dS3) / (dS3 + dS4));2227 tmp32 = (int32_t)round((b * dS4 + a * dS3) / (dS3 + dS4));
2224 d = (int16_t)tmp32;2228 d = (int16_t)tmp32;
2225 2229
2226 if (i < d2) putSampleValueNr(s->pek, t, y1 + dist * (-i - 1), c);2230 if (i < d2) putSampleValue(s->pek, t, (y1 - i - 1) << is16Bit, c);
2227 if (i < d3) putSampleValueNr(s->pek, t, y1 + dist * i, d);2231 if (i < d3) putSampleValue(s->pek, t, (y1 + i) << is16Bit, d);
2228 2232
2229 i += dist;2233 i++;
2230 }2234 }
2231 2235
2232 fixSample(s);2236 fixSample(s);
@@ -2239,7 +2243,7 @@ void sampXFade(void) · 6 unmodified lines
2239 y1 += s->repL;2243 y1 += s->repL;
2240 if (x1 >= y1 || x2 <= y1 || x2 >= s->len)2244 if (x1 >= y1 || x2 <= y1 || x2 >= s->len)
2241 {2245 {
2242 okBox(0, "System message", "Not enough sample data outside loop!");2246 okBox(0, "System message", "Invalid range!");
2243 return;2247 return;
2244 }2248 }
2245 2249
@@ -2250,19 +2254,25 @@ void sampXFade(void) · 4 unmodified lines
2250 d2 = y1 - x1;2254 d2 = y1 - x1;
2251 d3 = x2 - y1;2255 d3 = x2 - y1;
2252 2256
2253 if (d1 < 1 || d2 < 1 || d3 < 1)2257 if (d1 < 2 || d2 < 2 || d3 < 2)
2254 {2258 {
2255 okBox(0, "System message", "Not enough sample data outside loop!");2259 okBox(0, "System message", "Invalid range!");
2256 return;2260 return;
2257 }2261 }
2258 2262
2259 if (y1-d1 < 0 || y1+d1 >= s->len)2263 if (y1-d1 < 0 || y1+d1 >= s->len)
2260 {2264 {
2261 okBox(0, "System message", "Invalid range!");2265 okBox(0, "System message", "Not enough sample data outside loop!");
2262 return;2266 return;
2263 }2267 }
2264 2268
2265 dist = is16Bit ? 2 : 1;2269 if (is16Bit)
2270 {
2271 y1 >>= 1;
2272 d1 >>= 1;
2273 d2 >>= 1;
2274 d3 >>= 1;
2275 }
2266 2276
2267 pauseAudio();2277 pauseAudio();
2268 restoreSample(s);2278 restoreSample(s);
@@ -2270,8 +2280,8 @@ void sampXFade(void) · 1 unmodified line
2270 i = 0;2280 i = 0;
2271 while (i < d1)2281 while (i < d1)
2272 {2282 {
2273 a = getSampleValueNr(s->pek, t, y1 - i - dist);2283 a = getSampleValue(s->pek, t, (y1 - i - 1) << is16Bit);
2274 b = getSampleValueNr(s->pek, t, y1 + i);2284 b = getSampleValue(s->pek, t, (y1 + i) << is16Bit);
2275 2285
2276 dS1 = 1.0 - i / (double)d2; dS2 = 2.0 - dS1;2286 dS1 = 1.0 - i / (double)d2; dS2 = 2.0 - dS1;
2277 dS3 = 1.0 - i / (double)d3; dS4 = 2.0 - dS3;2287 dS3 = 1.0 - i / (double)d3; dS4 = 2.0 - dS3;
@@ -2282,10 +2292,10 @@ void sampXFade(void) · 4 unmodified lines
2282 tmp32 = (int32_t)round((b * dS4 + a * dS3) / (dS3 + dS4));2292 tmp32 = (int32_t)round((b * dS4 + a * dS3) / (dS3 + dS4));
2283 d = (int16_t)tmp32;2293 d = (int16_t)tmp32;
2284 2294
2285 if (i < d2) putSampleValueNr(s->pek, t, y1 - i - dist, c);2295 if (i < d2) putSampleValue(s->pek, t, (y1 - i - 1) << is16Bit, c);
2286 if (i < d3) putSampleValueNr(s->pek, t, y1 + i, d);2296 if (i < d3) putSampleValue(s->pek, t, (y1 + i) << is16Bit, d);
2287 2297
2288 i += dist;2298 i++;
2289 }2299 }
2290 2300
2291 fixSample(s);2301 fixSample(s);
@@ -2304,11 +2314,11 @@ void sampXFade(void) · 12 unmodified lines
2304 2314
2305 if (x1 < 0 || x2 <= x1 || x2 >= s->len)2315 if (x1 < 0 || x2 <= x1 || x2 >= s->len)
2306 {2316 {
2307 okBox(0, "System message", "Not enough sample data outside loop!");2317 okBox(0, "System message", "Invalid range!");
2308 return;2318 return;
2309 }2319 }
2310 2320
2311 i = (x2 - x1 + 1) / 2;2321 i = (x2 - x1 + 1) >> 1;
2312 y1 = s->repS - i;2322 y1 = s->repS - i;
2313 y2 = s->repS + s->repL - i;2323 y2 = s->repS + s->repL - i;
2314 2324
@@ -2320,7 +2330,7 @@ void sampXFade(void) · 5 unmodified lines
2320 2330
2321 if (y1 < 0 || y2+(x2-x1) >= s->len)2331 if (y1 < 0 || y2+(x2-x1) >= s->len)
2322 {2332 {
2323 okBox(0, "System message", "Invalid range!");2333 okBox(0, "System message", "Not enough sample data outside loop!");
2324 return;2334 return;
2325 }2335 }
2326 2336
@@ -2330,7 +2340,7 @@ void sampXFade(void) · 3 unmodified lines
2330 2340
2331 if (y1+(x2-x1) <= s->repS || d1 == 0 || d3 == 0 || d1 > s->repL)2341 if (y1+(x2-x1) <= s->repS || d1 == 0 || d3 == 0 || d1 > s->repL)
2332 {2342 {
2333 okBox(0, "System message", "Not enough sample data outside loop!");2343 okBox(0, "System message", "Invalid range!");
2334 return;2344 return;
2335 }2345 }
2336 2346
@@ -2343,8 +2353,8 @@ void sampXFade(void) · 6 unmodified lines
2343 i = 0;2353 i = 0;
2344 while (i < x2-x1)2354 while (i < x2-x1)
2345 {2355 {
2346 a = getSampleValueNr(s->pek, t, y1 + i);2356 a = getSampleValue(s->pek, t, y1 + i);
2347 b = getSampleValueNr(s->pek, t, y2 + i);2357 b = getSampleValue(s->pek, t, y2 + i);
2348 2358
2349 dS2 = i / (double)d1;2359 dS2 = i / (double)d1;
2350 dS1 = 1.0 - dS2;2360 dS1 = 1.0 - dS2;
@@ -2372,8 +2382,8 @@ void sampXFade(void) · 21 unmodified lines
2372 d = (int16_t)tmp32;2382 d = (int16_t)tmp32;
2373 }2383 }
2374 2384
2375 putSampleValueNr(s->pek, t, y1 + i, c);2385 putSampleValue(s->pek, t, y1 + i, c);
2376 putSampleValueNr(s->pek, t, y2 + i, d);2386 putSampleValue(s->pek, t, y2 + i, d);
2377 2387
2378 i += dist;2388 i += dist;
2379 }2389 }
src/ft2_sample_ed.h+2−2
@@ -48,8 +48,8 @@ void sampRepeatUp(void); · 47 unmodified lines
48void sampRepeatDown(void);48void sampRepeatDown(void);
49void sampReplenUp(void);49void sampReplenUp(void);
50void sampReplenDown(void);50void sampReplenDown(void);
51int16_t getSampleValueNr(int8_t *ptr, uint8_t typ, int32_t pos);51int16_t getSampleValue(int8_t *ptr, uint8_t typ, int32_t pos);
52void putSampleValueNr(int8_t *ptr, uint8_t typ, int32_t pos, int16_t val);52void putSampleValue(int8_t *ptr, uint8_t typ, int32_t pos, int16_t val);
53void writeSample(bool forceSmpRedraw);53void writeSample(bool forceSmpRedraw);
54void handleSampleDataMouseDown(bool mouseButtonHeld);54void handleSampleDataMouseDown(bool mouseButtonHeld);
55void updateSampleEditorSample(void);55void updateSampleEditorSample(void);
src/ft2_sample_ed_features.c+3−3
@@ -987,8 +987,8 @@ static int32_t SDLCALL mixThread(void *ptr) · 986 unmodified lines
987 {987 {
988 int32_t index16 = i << 1;988 int32_t index16 = i << 1;
989 989
990 x1 = (i >= mix8Size) ? 0 : getSampleValueNr(mixPtr, mixTyp, src16Bits ? index16 : i);990 x1 = (i >= mix8Size) ? 0 : getSampleValue(mixPtr, mixTyp, src16Bits ? index16 : i);
991 x2 = (i >= dest8Size) ? 0 : getSampleValueNr(destPtr, destTyp, dst16Bits ? index16 : i);991 x2 = (i >= dest8Size) ? 0 : getSampleValue(destPtr, destTyp, dst16Bits ? index16 : i);
992 992
993 if (!src16Bits) x1 <<= 8;993 if (!src16Bits) x1 <<= 8;
994 if (!dst16Bits) x2 <<= 8;994 if (!dst16Bits) x2 <<= 8;
@@ -999,7 +999,7 @@ static int32_t SDLCALL mixThread(void *ptr) · 4 unmodified lines
999 if (!dst16Bits)999 if (!dst16Bits)
1000 smp32 >>= 8;1000 smp32 >>= 8;
1001 1001
1002 putSampleValueNr(destPek, destTyp, dst16Bits ? index16 : i, (int16_t)smp32);1002 putSampleValue(destPek, destTyp, dst16Bits ? index16 : i, (int16_t)smp32);
1003 }1003 }
1004 1004
1005 if (instr[destIns]->samp[destSmp].origPek != NULL)1005 if (instr[destIns]->samp[destSmp].origPek != NULL)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t