| @@ -1010,7 +1010,6 @@ void tRosenbergGlottalPulse_setOpenLengthAndPulseLength (tRosenbergG · 1009 unmodified lines |
| 1010 | 1010 | /***************** static function declarations *******************************/ |
| 1011 | 1011 | /******************************************************************************/ |
| 1012 | 1012 | |
| 1013 | | −static void solad_init(_tSOLAD *w); |
| 1014 | 1013 | static inline float read_sample(_tSOLAD *w, float floatindex); |
| 1015 | 1014 | static void pitchdown(_tSOLAD *w, float *out); |
| 1016 | 1015 | static void pitchup(_tSOLAD *w, float *out); |
| @@ -1032,9 +1031,13 @@ void tSOLAD_initToPool (tSOLAD* const wp, tMempool* const mp) · 15 unmodified lines |
| 1032 | 1031 | w->mempool = m; |
| 1033 | 1032 | |
| 1034 | 1033 | w->pitchfactor = 1.; |
| 1035 | | − w->delaybuf = (float*) mpool_calloc(sizeof(float) * (LOOPSIZE+16), m); |
| 1034 | + w->delaybuf = (float*) mpool_calloc(sizeof(float) * LOOPSIZE, m); |
| 1036 | 1035 | |
| 1037 | | − solad_init(w); |
| 1036 | + w->timeindex = 0; |
| 1037 | + w->xfadevalue = -1; |
| 1038 | + w->period = INITPERIOD; |
| 1039 | + w->readlag = INITPERIOD; |
| 1040 | + w->blocksize = INITPERIOD; |
| 1038 | 1041 | } |
| 1039 | 1042 | |
| 1040 | 1043 | void tSOLAD_free (tSOLAD* const wp) |
| @@ -1077,7 +1080,10 @@ void tSOLAD_setPitchFactor(tSOLAD* const wp, float pitchfactor) · 36 unmodified lines |
| 1077 | 1080 | { |
| 1078 | 1081 | _tSOLAD* w = *wp; |
| 1079 | 1082 | |
| 1080 | | − if (pitchfactor <= 0.0f) return; |
| 1083 | + if (pitchfactor <= 0.0f || pitchfactor > 1000.0f) |
| 1084 | + { |
| 1085 | + return; |
| 1086 | + } |
| 1081 | 1087 | w->pitchfactor = pitchfactor; |
| 1082 | 1088 | } |
| 1083 | 1089 | |
| @@ -1101,11 +1107,16 @@ void tSOLAD_resetState(tSOLAD* const wp) · 17 unmodified lines |
| 1101 | 1107 | { |
| 1102 | 1108 | _tSOLAD* w = *wp; |
| 1103 | 1109 | |
| 1104 | | − int n = LOOPSIZE + 1; |
| 1110 | + int n = LOOPSIZE; |
| 1105 | 1111 | float *buf = w->delaybuf; |
| 1106 | 1112 | |
| 1107 | 1113 | while(n--) *buf++ = 0; |
| 1108 | | − solad_init(w); |
| 1114 | + |
| 1115 | + w->timeindex = 0; |
| 1116 | + w->xfadevalue = -1; |
| 1117 | + w->period = INITPERIOD; |
| 1118 | + w->readlag = INITPERIOD; |
| 1119 | + w->blocksize = INITPERIOD; |
| 1109 | 1120 | } |
| 1110 | 1121 | |
| 1111 | 1122 | /******************************************************************************/ |
| @@ -1182,7 +1193,7 @@ static void pitchdown(_tSOLAD* const w, float *out) · 70 unmodified lines |
| 1182 | 1193 | xfadevalue -= xfadestep; |
| 1183 | 1194 | } |
| 1184 | 1195 | |
| 1185 | | − *out++ = outputsample; |
| 1196 | + *out++ += outputsample; |
| 1186 | 1197 | refindex += 1; |
| 1187 | 1198 | readlag += readlagstep; |
| 1188 | 1199 | } |
| @@ -1312,7 +1323,7 @@ static void pitchup(_tSOLAD* const w, float *out) · 123 unmodified lines |
| 1312 | 1323 | xfadevalue -= xfadestep; |
| 1313 | 1324 | } |
| 1314 | 1325 | |
| 1315 | | − *out++ = outputsample; |
| 1326 | + *out++ += outputsample; |
| 1316 | 1327 | refindex += 1; |
| 1317 | 1328 | readlag -= readlagstep; |
| 1318 | 1329 | } |
| @@ -1334,77 +1345,55 @@ static inline float read_sample(_tSOLAD* const w, float floatindex) · 15 unmodified lines |
| 1334 | 1345 | return (buf[index] + (fraction * (buf[index+1] - buf[index]))); |
| 1335 | 1346 | } |
| 1336 | 1347 | |
| 1337 | | −static void solad_init(_tSOLAD* const w) |
| 1338 | | −{ |
| 1339 | | − w->timeindex = 0; |
| 1340 | | − w->xfadevalue = -1; |
| 1341 | | − w->period = INITPERIOD; |
| 1342 | | − w->readlag = INITPERIOD; |
| 1343 | | − w->blocksize = INITPERIOD; |
| 1344 | | −} |
| 1345 | | − |
| 1346 | 1348 | //============================================================================================================ |
| 1347 | 1349 | // PITCHSHIFT |
| 1348 | 1350 | //============================================================================================================ |
| 1349 | 1351 | |
| 1350 | 1352 | static int pitchshift_attackdetect(_tPitchShift* ps) |
| 1351 | 1353 | { |
| 1352 | | − float envout; |
| 1353 | | − |
| 1354 | | − _tPeriodDetection* p = *ps->p; |
| 1355 | | − |
| 1356 | | − envout = tEnvPD_tick(&p->env); |
| 1357 | | − |
| 1358 | | − if (envout >= 1.0f) |
| 1359 | | − { |
| 1360 | | − p->lastmax = p->max; |
| 1361 | | − if (envout > p->max) |
| 1362 | | − { |
| 1363 | | − p->max = envout; |
| 1364 | | − } |
| 1365 | | − else |
| 1366 | | − { |
| 1367 | | − p->deltamax = envout - p->max; |
| 1368 | | − p->max = p->max * ps->radius; |
| 1369 | | − } |
| 1370 | | − p->deltamax = p->max - p->lastmax; |
| 1371 | | − } |
| 1372 | | − |
| 1373 | | − p->fba = p->fba ? (p->fba - 1) : 0; |
| 1374 | | − |
| 1375 | | − return (p->fba == 0 && (p->max > 60 && p->deltamax > 6)) ? 1 : 0; |
| 1354 | +// float envout; |
| 1355 | +// |
| 1356 | +// _tPeriodDetection* p = *ps->p; |
| 1357 | +// |
| 1358 | +// envout = tEnvPD_tick(&p->env); |
| 1359 | +// |
| 1360 | +// if (envout >= 1.0f) |
| 1361 | +// { |
| 1362 | +// p->lastmax = p->max; |
| 1363 | +// if (envout > p->max) |
| 1364 | +// { |
| 1365 | +// p->max = envout; |
| 1366 | +// } |
| 1367 | +// else |
| 1368 | +// { |
| 1369 | +// p->deltamax = envout - p->max; |
| 1370 | +// p->max = p->max * ps->radius; |
| 1371 | +// } |
| 1372 | +// p->deltamax = p->max - p->lastmax; |
| 1373 | +// } |
| 1374 | +// |
| 1375 | +// p->fba = p->fba ? (p->fba - 1) : 0; |
| 1376 | +// |
| 1377 | +// return (p->fba == 0 && (p->max > 60 && p->deltamax > 6)) ? 1 : 0; |
| 1376 | 1378 | } |
| 1377 | 1379 | |
| 1378 | | −void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* const pd, tDualPitchDetector* const dp, float* out, int bufSize, LEAF* const leaf) |
| 1380 | +void tPitchShift_init (tPitchShift* const psr, tDualPitchDetector* const dpd, LEAF* const leaf) |
| 1379 | 1381 | { |
| 1380 | | − tPitchShift_initToPool(psr, pd, dp, out, bufSize, &leaf->mempool); |
| 1382 | + tPitchShift_initToPool(psr, dpd, &leaf->mempool); |
| 1381 | 1383 | } |
| 1382 | 1384 | |
| 1383 | | −void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, tDualPitchDetector* const dp, float* out, int bufSize, tMempool* const mp) |
| 1385 | +void tPitchShift_initToPool (tPitchShift* const psr, tDualPitchDetector* const dpd, tMempool* const mp) |
| 1384 | 1386 | { |
| 1385 | 1387 | _tMempool* m = *mp; |
| 1386 | 1388 | _tPitchShift* ps = *psr = (_tPitchShift*) mpool_calloc(sizeof(_tPitchShift), m); |
| 1387 | 1389 | ps->mempool = m; |
| 1388 | 1390 | |
| 1389 | | − _tPeriodDetection* p = *pd; |
| 1390 | | − |
| 1391 | | − ps->p = pd; |
| 1392 | | − |
| 1393 | | − ps->outBuffer = out; |
| 1394 | | − ps->bufSize = bufSize; |
| 1395 | | − ps->frameSize = p->frameSize; |
| 1396 | | − ps->framesPerBuffer = ps->bufSize / ps->frameSize; |
| 1397 | | − ps->curBlock = 1; |
| 1398 | | − ps->lastBlock = 0; |
| 1399 | | − ps->index = 0; |
| 1400 | | − ps->pitchFactor = 1.0f; |
| 1401 | | − ps->dp = *dp; |
| 1391 | + ps->pd = *dpd; |
| 1402 | 1392 | |
| 1403 | 1393 | tSOLAD_initToPool(&ps->sola, mp); |
| 1394 | + tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO); |
| 1404 | 1395 | |
| 1405 | 1396 | tHighpass_initToPool(&ps->hp, HPFREQ, mp); |
| 1406 | | − |
| 1407 | | − tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO); |
| 1408 | 1397 | } |
| 1409 | 1398 | |
| 1410 | 1399 | void tPitchShift_free (tPitchShift* const psr) |
| @@ -1416,168 +1405,63 @@ void tPitchShift_free (tPitchShift* const psr) · 5 unmodified lines |
| 1416 | 1405 | mpool_free((char*)ps, ps->mempool); |
| 1417 | 1406 | } |
| 1418 | 1407 | |
| 1419 | | −void tPitchShift_setPitchFactor(tPitchShift* psr, float pf) |
| 1408 | +void tPitchShift_shiftBy (tPitchShift* const psr, float factor, float* in, float* out, int bufSize) |
| 1420 | 1409 | { |
| 1421 | 1410 | _tPitchShift* ps = *psr; |
| 1422 | | − |
| 1423 | | − ps->pitchFactor = pf; |
| 1424 | | −} |
| 1425 | | − |
| 1426 | | −float tPitchShift_shift (tPitchShift* psr) |
| 1427 | | −{ |
| 1428 | | − _tPitchShift* ps = *psr; |
| 1429 | | − _tPeriodDetection* p = *ps->p; |
| 1430 | | − |
| 1431 | | − float period, out; |
| 1432 | | − int i, iLast; |
| 1433 | | − |
| 1434 | | − i = p->i; |
| 1435 | | − iLast = p->iLast; |
| 1436 | | − |
| 1437 | | − out = tHighpass_tick(&ps->hp, ps->outBuffer[iLast]); |
| 1438 | | − |
| 1439 | | − if (p->indexstore >= ps->frameSize) |
| 1440 | | − { |
| 1441 | | −// period = tPeriodDetection_getPeriod(&p); |
| 1442 | | − period = 1.0f / tDualPitchDetector_getFrequency(&ps->dp); |
| 1443 | | − |
| 1444 | | − if(pitchshift_attackdetect(ps) == 1) |
| 1445 | | − { |
| 1446 | | − p->fba = 5; |
| 1447 | | − tSOLAD_setReadLag(&ps->sola, p->windowSize); |
| 1448 | | − } |
| 1449 | | − |
| 1450 | | − tSOLAD_setPeriod(&ps->sola, period); |
| 1451 | | − tSOLAD_setPitchFactor(&ps->sola, ps->pitchFactor); |
| 1452 | | − |
| 1453 | | − tSOLAD_ioSamples(&ps->sola, &(p->inBuffer[i]), &(ps->outBuffer[i]), ps->frameSize); |
| 1454 | | − } |
| 1455 | | − |
| 1456 | | − return out; |
| 1457 | | −} |
| 1458 | | − |
| 1459 | | −float tPitchShift_shiftToFreq (tPitchShift* psr, float freq) |
| 1460 | | −{ |
| 1461 | | − _tPitchShift* ps = *psr; |
| 1462 | | − _tPeriodDetection* p = *ps->p; |
| 1463 | 1411 | LEAF* leaf = ps->mempool->leaf; |
| 1464 | 1412 | |
| 1465 | | − float period = 0; |
| 1466 | | − float out; |
| 1467 | | − int i, iLast; |
| 1413 | + float period = leaf->sampleRate / tDualPitchDetector_getFrequency(&ps->pd); |
| 1414 | + tSOLAD_setPeriod(&ps->sola, period); |
| 1415 | + tSOLAD_setPitchFactor(&ps->sola, factor); |
| 1468 | 1416 | |
| 1469 | | − i = p->i; |
| 1470 | | − iLast = p->iLast; |
| 1471 | | − |
| 1472 | | − out = tHighpass_tick(&ps->hp, ps->outBuffer[iLast]); |
| 1473 | | − |
| 1474 | | − if (p->indexstore >= ps->frameSize) |
| 1475 | | − { |
| 1476 | | −// period = tPeriodDetection_getPeriod(&p); |
| 1477 | | − float f = tDualPitchDetector_getFrequency(&ps->dp); |
| 1478 | | − if (f > 0) period = 1.0f / f; |
| 1479 | | − |
| 1480 | | − if(pitchshift_attackdetect(ps) == 1) |
| 1481 | | − { |
| 1482 | | − p->fba = 5; |
| 1483 | | − tSOLAD_setReadLag(&ps->sola, p->windowSize); |
| 1484 | | − } |
| 1485 | | − |
| 1486 | | − tSOLAD_setPeriod(&ps->sola, period * leaf->sampleRate); |
| 1487 | | − |
| 1488 | | − if (period != 0) ps->pitchFactor = freq * period; |
| 1489 | | − else ps->pitchFactor = 1.0f; |
| 1490 | | − |
| 1491 | | − tSOLAD_setPitchFactor(&ps->sola, ps->pitchFactor); |
| 1492 | | − |
| 1493 | | − tSOLAD_ioSamples(&ps->sola, &(p->inBuffer[i]), &(ps->outBuffer[i]), ps->frameSize); |
| 1494 | | − } |
| 1495 | | − return out; |
| 1417 | + tSOLAD_ioSamples(&ps->sola, in, out, bufSize); |
| 1496 | 1418 | } |
| 1497 | 1419 | |
| 1498 | | −float tPitchShift_shiftToFunc (tPitchShift* psr, float (*fun)(float)) |
| 1420 | +void tPitchShift_shiftTo (tPitchShift* const psr, float freq, float* in, float* out, int bufSize) |
| 1499 | 1421 | { |
| 1500 | 1422 | _tPitchShift* ps = *psr; |
| 1501 | | − _tPeriodDetection* p = *ps->p; |
| 1502 | | − |
| 1503 | | − float period, out; |
| 1504 | | − int i, iLast; |
| 1505 | | − |
| 1506 | | − i = p->i; |
| 1507 | | − iLast = p->iLast; |
| 1508 | | − |
| 1509 | | − out = tHighpass_tick(&ps->hp, ps->outBuffer[iLast]); |
| 1423 | + LEAF* leaf = ps->mempool->leaf; |
| 1510 | 1424 | |
| 1511 | | − if (p->indexstore >= ps->frameSize) |
| 1512 | | − { |
| 1513 | | −// period = tPeriodDetection_getPeriod(&p); |
| 1514 | | − period = 1.0f / tDualPitchDetector_getFrequency(&ps->dp); |
| 1515 | | − |
| 1516 | | − if(pitchshift_attackdetect(ps) == 1) |
| 1517 | | − { |
| 1518 | | − p->fba = 5; |
| 1519 | | − tSOLAD_setReadLag(&ps->sola, p->windowSize); |
| 1520 | | − } |
| 1521 | | − |
| 1522 | | − tSOLAD_setPeriod(&ps->sola, period); |
| 1523 | | − |
| 1524 | | − ps->pitchFactor = period/fun(period); |
| 1525 | | − tSOLAD_setPitchFactor(&ps->sola, ps->pitchFactor); |
| 1526 | | − |
| 1527 | | − tSOLAD_ioSamples(&ps->sola, &(p->inBuffer[i]), &(ps->outBuffer[i]), ps->frameSize); |
| 1528 | | − |
| 1529 | | − ps->curBlock++; |
| 1530 | | − if (ps->curBlock >= p->framesPerBuffer) ps->curBlock = 0; |
| 1531 | | − ps->lastBlock++; |
| 1532 | | − if (ps->lastBlock >= ps->framesPerBuffer) ps->lastBlock = 0; |
| 1533 | | − } |
| 1425 | + float period = 1.0f / tDualPitchDetector_getFrequency(&ps->pd); |
| 1426 | + float factor = freq * period; |
| 1427 | + tSOLAD_setPeriod(&ps->sola, leaf->sampleRate * period); |
| 1428 | + tSOLAD_setPitchFactor(&ps->sola, factor); |
| 1534 | 1429 | |
| 1535 | | − return out; |
| 1430 | + tSOLAD_ioSamples(&ps->sola, in, out, bufSize); |
| 1536 | 1431 | } |
| 1537 | 1432 | |
| 1538 | 1433 | //============================================================================================================ |
| 1539 | 1434 | // RETUNE |
| 1540 | 1435 | //============================================================================================================ |
| 1541 | 1436 | |
| 1542 | | −void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize, LEAF* const leaf) |
| 1437 | +void tRetune_init(tRetune* const rt, int numVoices, int bufSize, LEAF* const leaf) |
| 1543 | 1438 | { |
| 1544 | | − tRetune_initToPool(rt, numVoices, bufSize, frameSize, &leaf->mempool); |
| 1439 | + tRetune_initToPool(rt, numVoices, bufSize, &leaf->mempool); |
| 1545 | 1440 | } |
| 1546 | 1441 | |
| 1547 | | −void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp) |
| 1442 | +void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, tMempool* const mp) |
| 1548 | 1443 | { |
| 1549 | 1444 | _tMempool* m = *mp; |
| 1550 | 1445 | _tRetune* r = *rt = (_tRetune*) mpool_alloc(sizeof(_tRetune), m); |
| 1551 | 1446 | r->mempool = *mp; |
| 1552 | 1447 | |
| 1553 | 1448 | r->bufSize = bufSize; |
| 1554 | | − r->frameSize = frameSize; |
| 1555 | 1449 | r->numVoices = numVoices; |
| 1556 | 1450 | |
| 1557 | 1451 | r->inBuffer = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1558 | | − r->outBuffers = (float**) mpool_calloc(sizeof(float*) * r->numVoices, m); |
| 1559 | | − |
| 1560 | | − r->hopSize = DEFHOPSIZE; |
| 1561 | | − r->windowSize = DEFWINDOWSIZE; |
| 1562 | | − r->fba = FBA; |
| 1563 | | − tRetune_setTimeConstant(rt, DEFTIMECONSTANT); |
| 1452 | + r->outBuffer = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1453 | + r->lastOutBuffer = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1564 | 1454 | |
| 1565 | | − r->inputPeriod = 0.0f; |
| 1455 | + r->index = 0; |
| 1566 | 1456 | |
| 1567 | 1457 | r->ps = (tPitchShift*) mpool_calloc(sizeof(tPitchShift) * r->numVoices, m); |
| 1568 | | − r->pitchFactor = (float*) mpool_calloc(sizeof(float) * r->numVoices, m); |
| 1569 | | − r->tickOutput = (float*) mpool_calloc(sizeof(float) * r->numVoices, m); |
| 1570 | | − for (int i = 0; i < r->numVoices; ++i) |
| 1571 | | − { |
| 1572 | | − r->outBuffers[i] = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1573 | | − } |
| 1458 | + r->pitchFactors = (float*) mpool_calloc(sizeof(float) * r->numVoices, m); |
| 1574 | 1459 | |
| 1575 | 1460 | tDualPitchDetector_initToPool(&r->dp, mtof(48), mtof(72), mp); |
| 1576 | | − tPeriodDetection_initToPool(&r->pd, r->inBuffer, r->outBuffers[0], r->bufSize, r->frameSize, mp); |
| 1577 | 1461 | |
| 1578 | 1462 | for (int i = 0; i < r->numVoices; ++i) |
| 1579 | 1463 | { |
| 1580 | | − tPitchShift_initToPool(&r->ps[i], &r->pd, &r->dp, r->outBuffers[i], r->bufSize, mp); |
| 1464 | + tPitchShift_initToPool(&r->ps[i], &r->dp, mp); |
| 1581 | 1465 | } |
| 1582 | 1466 | } |
| 1583 | 1467 | |
| @@ -1590,30 +1474,34 @@ void tRetune_free (tRetune* const rt) · 6 unmodified lines |
| 1590 | 1474 | for (int i = 0; i < r->numVoices; ++i) |
| 1591 | 1475 | { |
| 1592 | 1476 | tPitchShift_free(&r->ps[i]); |
| 1593 | | − mpool_free((char*)r->outBuffers[i], r->mempool); |
| 1594 | 1477 | } |
| 1595 | | − mpool_free((char*)r->tickOutput, r->mempool); |
| 1596 | | − mpool_free((char*)r->pitchFactor, r->mempool); |
| 1478 | + mpool_free((char*)r->pitchFactors, r->mempool); |
| 1597 | 1479 | mpool_free((char*)r->ps, r->mempool); |
| 1598 | 1480 | mpool_free((char*)r->inBuffer, r->mempool); |
| 1599 | | − mpool_free((char*)r->outBuffers, r->mempool); |
| 1481 | + mpool_free((char*)r->outBuffer, r->mempool); |
| 1600 | 1482 | mpool_free((char*)r, r->mempool); |
| 1601 | 1483 | } |
| 1602 | 1484 | |
| 1603 | | −float* tRetune_tick(tRetune* const rt, float sample) |
| 1485 | +float tRetune_tick(tRetune* const rt, float sample) |
| 1604 | 1486 | { |
| 1605 | 1487 | _tRetune* r = *rt; |
| 1606 | 1488 | |
| 1607 | | − tPeriodDetection_tick(&r->pd, sample); |
| 1608 | 1489 | tDualPitchDetector_tick(&r->dp, sample); |
| 1609 | | − r->inputPeriod = 1.0f / tDualPitchDetector_getFrequency(&r->dp); |
| 1610 | 1490 | |
| 1611 | | − for (int v = 0; v < r->numVoices; ++v) |
| 1491 | + r->inBuffer[r->index] = sample; |
| 1492 | + float out = r->outBuffer[r->index]; |
| 1493 | + r->outBuffer[r->index++] = 0.0f; |
| 1494 | + |
| 1495 | + if (r->index >= r->bufSize) |
| 1612 | 1496 | { |
| 1613 | | − r->tickOutput[v] = tPitchShift_shift(&r->ps[v]); |
| 1497 | + for (int i = 0; i < r->numVoices; ++i) |
| 1498 | + { |
| 1499 | + tPitchShift_shiftBy(&r->ps[i], r->pitchFactors[i], r->inBuffer, r->outBuffer, r->bufSize); |
| 1500 | + } |
| 1501 | + r->index = 0; |
| 1614 | 1502 | } |
| 1615 | 1503 | |
| 1616 | | − return r->tickOutput; |
| 1504 | + return out; |
| 1617 | 1505 | } |
| 1618 | 1506 | |
| 1619 | 1507 | void tRetune_setNumVoices(tRetune* const rt, int numVoices) |
| @@ -1621,11 +1509,10 @@ void tRetune_setNumVoices(tRetune* const rt, int numVoices) · 1 unmodified line |
| 1621 | 1509 | _tRetune* r = *rt; |
| 1622 | 1510 | |
| 1623 | 1511 | int bufSize = r->bufSize; |
| 1624 | | − int frameSize = r->frameSize; |
| 1625 | 1512 | tMempool mempool = r->mempool; |
| 1626 | 1513 | |
| 1627 | 1514 | tRetune_free(rt); |
| 1628 | | − tRetune_initToPool(rt, numVoices, bufSize, frameSize, &mempool); |
| 1515 | + tRetune_initToPool(rt, numVoices, bufSize, &mempool); |
| 1629 | 1516 | } |
| 1630 | 1517 | |
| 1631 | 1518 | void tRetune_setPitchFactors(tRetune* const rt, float pf) |
| @@ -1634,8 +1521,7 @@ void tRetune_setPitchFactors(tRetune* const rt, float pf) · 2 unmodified lines |
| 1634 | 1521 | |
| 1635 | 1522 | for (int i = 0; i < r->numVoices; ++i) |
| 1636 | 1523 | { |
| 1637 | | − r->pitchFactor[i] = pf; |
| 1638 | | − tPitchShift_setPitchFactor(&r->ps[i], r->pitchFactor[i]); |
| 1524 | + r->pitchFactors[i] = pf; |
| 1639 | 1525 | } |
| 1640 | 1526 | } |
| 1641 | 1527 | |
| @@ -1643,142 +1529,81 @@ void tRetune_setPitchFactor(tRetune* const rt, float pf, int voice) · 1 unmodified line |
| 1643 | 1529 | { |
| 1644 | 1530 | _tRetune* r = *rt; |
| 1645 | 1531 | |
| 1646 | | − r->pitchFactor[voice] = pf; |
| 1647 | | − tPitchShift_setPitchFactor(&r->ps[voice], r->pitchFactor[voice]); |
| 1648 | | −} |
| 1649 | | − |
| 1650 | | −void tRetune_setTimeConstant(tRetune* const rt, float tc) |
| 1651 | | −{ |
| 1652 | | − _tRetune* r = *rt; |
| 1653 | | − LEAF* leaf = r->mempool->leaf; |
| 1654 | | − |
| 1655 | | − r->timeConstant = tc; |
| 1656 | | − r->radius = expf(-1000.0f * r->hopSize * leaf->invSampleRate / r->timeConstant); |
| 1657 | | −} |
| 1658 | | − |
| 1659 | | −void tRetune_setHopSize(tRetune* const rt, int hs) |
| 1660 | | −{ |
| 1661 | | − _tRetune* r = *rt; |
| 1662 | | − |
| 1663 | | − r->hopSize = hs; |
| 1664 | | − tPeriodDetection_setHopSize(&r->pd, r->hopSize); |
| 1665 | | −} |
| 1666 | | − |
| 1667 | | −void tRetune_setWindowSize(tRetune* const rt, int ws) |
| 1668 | | −{ |
| 1669 | | − _tRetune* r = *rt; |
| 1670 | | − |
| 1671 | | − r->windowSize = ws; |
| 1672 | | − tPeriodDetection_setWindowSize(&r->pd, r->windowSize); |
| 1673 | | −} |
| 1674 | | − |
| 1675 | | −void tRetune_setFidelityThreshold(tRetune* const rt, float threshold) |
| 1676 | | −{ |
| 1677 | | − _tRetune* r = *rt; |
| 1678 | | − |
| 1679 | | − tPeriodDetection_setFidelityThreshold(&r->pd, threshold); |
| 1680 | | −} |
| 1681 | | − |
| 1682 | | −float tRetune_getInputPeriod(tRetune* const rt) |
| 1683 | | −{ |
| 1684 | | − _tRetune* r = *rt; |
| 1685 | | − LEAF* leaf = r->mempool->leaf; |
| 1686 | | − |
| 1687 | | − return (r->inputPeriod * leaf->invSampleRate); |
| 1688 | | −} |
| 1689 | | − |
| 1690 | | −float tRetune_getInputFreq(tRetune* const rt) |
| 1691 | | −{ |
| 1692 | | − _tRetune* r = *rt; |
| 1693 | | − LEAF* leaf = r->mempool->leaf; |
| 1694 | | − |
| 1695 | | − return 1.0f/(r->inputPeriod * leaf->invSampleRate); |
| 1532 | + r->pitchFactors[voice] = pf; |
| 1696 | 1533 | } |
| 1697 | 1534 | |
| 1698 | 1535 | //============================================================================================================ |
| 1699 | 1536 | // AUTOTUNE |
| 1700 | 1537 | //============================================================================================================ |
| 1701 | 1538 | |
| 1702 | | −void tAutotune_init (tAutotune* const rt, int numVoices, int bufSize, int frameSize, LEAF* const leaf) |
| 1539 | +void tAutotune_init (tAutotune* const rt, int numVoices, int bufSize, LEAF* const leaf) |
| 1703 | 1540 | { |
| 1704 | | − tAutotune_initToPool(rt, numVoices, bufSize, frameSize, &leaf->mempool); |
| 1541 | + tAutotune_initToPool(rt, numVoices, bufSize, &leaf->mempool); |
| 1705 | 1542 | } |
| 1706 | 1543 | |
| 1707 | | −void tAutotune_initToPool (tAutotune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp) |
| 1544 | +void tAutotune_initToPool (tAutotune* const rt, int numVoices, int bufSize, tMempool* const mp) |
| 1708 | 1545 | { |
| 1709 | 1546 | _tMempool* m = *mp; |
| 1710 | 1547 | _tAutotune* r = *rt = (_tAutotune*) mpool_alloc(sizeof(_tAutotune), m); |
| 1711 | 1548 | r->mempool = *mp; |
| 1712 | 1549 | |
| 1713 | 1550 | r->bufSize = bufSize; |
| 1714 | | − r->frameSize = frameSize; |
| 1715 | 1551 | r->numVoices = numVoices; |
| 1716 | 1552 | |
| 1717 | | − r->inBuffer = (float*) mpool_alloc(sizeof(float) * r->bufSize, m); |
| 1718 | | − r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, m); |
| 1553 | + r->inBuffer = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1554 | + r->outBuffer = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1555 | + r->lastOutBuffer = (float*) mpool_calloc(sizeof(float) * r->bufSize, m); |
| 1719 | 1556 | |
| 1720 | | − r->hopSize = DEFHOPSIZE; |
| 1721 | | − r->windowSize = DEFWINDOWSIZE; |
| 1722 | | − r->fba = FBA; |
| 1723 | | − tAutotune_setTimeConstant(rt, DEFTIMECONSTANT); |
| 1557 | + r->index = 0; |
| 1724 | 1558 | |
| 1725 | | − r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, m); |
| 1726 | | − r->freq = (float*) mpool_alloc(sizeof(float) * r->numVoices, m); |
| 1727 | | − r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, m); |
| 1728 | | − for (int i = 0; i < r->numVoices; ++i) |
| 1729 | | − { |
| 1730 | | − r->outBuffers[i] = (float*) mpool_alloc(sizeof(float) * r->bufSize, m); |
| 1731 | | − } |
| 1559 | + r->ps = (tPitchShift*) mpool_calloc(sizeof(tPitchShift) * r->numVoices, m); |
| 1560 | + r->freqs = (float*) mpool_calloc(sizeof(float) * r->numVoices, m); |
| 1732 | 1561 | |
| 1733 | 1562 | tDualPitchDetector_initToPool(&r->dp, mtof(48), mtof(72), mp); |
| 1734 | | − tPeriodDetection_initToPool(&r->pd, r->inBuffer, r->outBuffers[0], r->bufSize, r->frameSize, mp); |
| 1735 | | − |
| 1563 | + |
| 1736 | 1564 | for (int i = 0; i < r->numVoices; ++i) |
| 1737 | 1565 | { |
| 1738 | | − tPitchShift_initToPool(&r->ps[i], &r->pd, &r->dp, r->outBuffers[i], r->bufSize, mp); |
| 1566 | + tPitchShift_initToPool(&r->ps[i], &r->dp, mp); |
| 1739 | 1567 | } |
| 1740 | | − |
| 1741 | | − r->inputPeriod = 0.0f; |
| 1742 | | − r->shiftOn = 0; |
| 1743 | 1568 | } |
| 1744 | 1569 | |
| 1745 | 1570 | void tAutotune_free (tAutotune* const rt) |
| 1746 | 1571 | { |
| 1747 | 1572 | _tAutotune* r = *rt; |
| 1748 | 1573 | |
| 1574 | + tDualPitchDetector_free(&r->dp); |
| 1749 | 1575 | tPeriodDetection_free(&r->pd); |
| 1750 | 1576 | for (int i = 0; i < r->numVoices; ++i) |
| 1751 | 1577 | { |
| 1752 | 1578 | tPitchShift_free(&r->ps[i]); |
| 1753 | | − mpool_free((char*)r->outBuffers[i], r->mempool); |
| 1754 | 1579 | } |
| 1755 | | − mpool_free((char*)r->tickOutput, r->mempool); |
| 1756 | | − mpool_free((char*)r->freq, r->mempool); |
| 1580 | + mpool_free((char*)r->freqs, r->mempool); |
| 1757 | 1581 | mpool_free((char*)r->ps, r->mempool); |
| 1758 | 1582 | mpool_free((char*)r->inBuffer, r->mempool); |
| 1759 | | − mpool_free((char*)r->outBuffers, r->mempool); |
| 1583 | + mpool_free((char*)r->outBuffer, r->mempool); |
| 1760 | 1584 | mpool_free((char*)r, r->mempool); |
| 1761 | 1585 | } |
| 1762 | 1586 | |
| 1763 | | −float* tAutotune_tick(tAutotune* const rt, float sample) |
| 1587 | +float tAutotune_tick(tAutotune* const rt, float sample) |
| 1764 | 1588 | { |
| 1765 | 1589 | _tAutotune* r = *rt; |
| 1766 | 1590 | |
| 1767 | | − tPeriodDetection_tick(&r->pd, sample); |
| 1768 | 1591 | tDualPitchDetector_tick(&r->dp, sample); |
| 1769 | | − r->inputPeriod = 1.0f / tDualPitchDetector_getFrequency(&r->dp); |
| 1770 | 1592 | |
| 1771 | | −// if (tempPeriod < 1000.0f) //to avoid trying to follow consonants JS |
| 1772 | | −// { |
| 1773 | | −// r->inputPeriod = tempPeriod; |
| 1774 | | −// } |
| 1775 | | − |
| 1776 | | − for (int v = 0; v < r->numVoices; ++v) |
| 1593 | + r->inBuffer[r->index] = sample; |
| 1594 | + float out = r->outBuffer[r->index]; |
| 1595 | + r->outBuffer[r->index++] = 0.0f; |
| 1596 | + |
| 1597 | + if (r->index >= r->bufSize) |
| 1777 | 1598 | { |
| 1778 | | − r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]); |
| 1599 | + for (int i = 0; i < r->numVoices; ++i) |
| 1600 | + { |
| 1601 | + tPitchShift_shiftTo(&r->ps[i], r->freqs[i], r->inBuffer, r->outBuffer, r->bufSize); |
| 1602 | + } |
| 1603 | + r->index = 0; |
| 1779 | 1604 | } |
| 1780 | | − |
| 1781 | | − return r->tickOutput; |
| 1605 | + |
| 1606 | + return out; |
| 1782 | 1607 | } |
| 1783 | 1608 | |
| 1784 | 1609 | void tAutotune_setNumVoices(tAutotune* const rt, int numVoices) |
| @@ -1786,11 +1611,10 @@ void tAutotune_setNumVoices(tAutotune* const rt, int numVoices) · 1 unmodified line |
| 1786 | 1611 | _tAutotune* r = *rt; |
| 1787 | 1612 | |
| 1788 | 1613 | int bufSize = r->bufSize; |
| 1789 | | − int frameSize = r->frameSize; |
| 1790 | 1614 | tMempool mempool = r->mempool; |
| 1791 | 1615 | |
| 1792 | 1616 | tAutotune_free(rt); |
| 1793 | | − tAutotune_initToPool(rt, numVoices, bufSize, frameSize, &mempool); |
| 1617 | + tAutotune_initToPool(rt, numVoices, bufSize, &mempool); |
| 1794 | 1618 | } |
| 1795 | 1619 | |
| 1796 | 1620 | void tAutotune_setFreqs(tAutotune* const rt, float f) |
| @@ -1799,7 +1623,7 @@ void tAutotune_setFreqs(tAutotune* const rt, float f) · 2 unmodified lines |
| 1799 | 1623 | |
| 1800 | 1624 | for (int i = 0; i < r->numVoices; ++i) |
| 1801 | 1625 | { |
| 1802 | | − r->freq[i] = f; |
| 1626 | + r->freqs[i] = f; |
| 1803 | 1627 | } |
| 1804 | 1628 | } |
| 1805 | 1629 | |
| @@ -1807,65 +1631,7 @@ void tAutotune_setFreq(tAutotune* const rt, float f, int voice) · 1 unmodified line |
| 1807 | 1631 | { |
| 1808 | 1632 | _tAutotune* r = *rt; |
| 1809 | 1633 | |
| 1810 | | − r->freq[voice] = f; |
| 1811 | | −} |
| 1812 | | − |
| 1813 | | −void tAutotune_setTimeConstant(tAutotune* const rt, float tc) |
| 1814 | | −{ |
| 1815 | | − _tAutotune* r = *rt; |
| 1816 | | − LEAF* leaf = r->mempool->leaf; |
| 1817 | | − |
| 1818 | | − r->timeConstant = tc; |
| 1819 | | − r->radius = expf(-1000.0f * r->hopSize * leaf->invSampleRate / r->timeConstant); |
| 1820 | | −} |
| 1821 | | − |
| 1822 | | −void tAutotune_setHopSize(tAutotune* const rt, int hs) |
| 1823 | | −{ |
| 1824 | | − _tAutotune* r = *rt; |
| 1825 | | − |
| 1826 | | − r->hopSize = hs; |
| 1827 | | − tPeriodDetection_setHopSize(&r->pd, r->hopSize); |
| 1828 | | −} |
| 1829 | | − |
| 1830 | | −void tAutotune_setWindowSize(tAutotune* const rt, int ws) |
| 1831 | | −{ |
| 1832 | | − _tAutotune* r = *rt; |
| 1833 | | − |
| 1834 | | − r->windowSize = ws; |
| 1835 | | − tPeriodDetection_setWindowSize(&r->pd, r->windowSize); |
| 1836 | | −} |
| 1837 | | − |
| 1838 | | −void tAutotune_setFidelityThreshold(tAutotune* const rt, float threshold) |
| 1839 | | −{ |
| 1840 | | − _tAutotune* r = *rt; |
| 1841 | | − |
| 1842 | | − tPeriodDetection_setFidelityThreshold(&r->pd, threshold); |
| 1843 | | −} |
| 1844 | | − |
| 1845 | | −void tAutotune_setAlpha (tAutotune* rt, float alpha) |
| 1846 | | −{ |
| 1847 | | − _tAutotune* r = *rt; |
| 1848 | | − tPeriodDetection_setAlpha(&r->pd, alpha); |
| 1849 | | −} |
| 1850 | | − |
| 1851 | | −void tAutotune_setTolerance (tAutotune* rt, float tolerance) |
| 1852 | | −{ |
| 1853 | | − _tAutotune* r = *rt; |
| 1854 | | − tPeriodDetection_setTolerance(&r->pd, tolerance); |
| 1855 | | −} |
| 1856 | | − |
| 1857 | | −float tAutotune_getInputPeriod(tAutotune* const rt) |
| 1858 | | −{ |
| 1859 | | − _tAutotune* r = *rt; |
| 1860 | | − |
| 1861 | | − return r->inputPeriod; |
| 1862 | | −} |
| 1863 | | − |
| 1864 | | −float tAutotune_getInputFreq(tAutotune* const rt) |
| 1865 | | −{ |
| 1866 | | − _tAutotune* r = *rt; |
| 1867 | | − |
| 1868 | | − return 1.0f/r->inputPeriod; |
| 1634 | + r->freqs[voice] = f; |
| 1869 | 1635 | } |
| 1870 | 1636 | |
| 1871 | 1637 | //============================================================================================================ |