| 21 | } |
| 22 | |
| 23 | void MorphInteractor::controlPointsChanged(Array<float> controlPoints) { |
| 24 | m_morphPointsChanged = false; |
| 25 | |
| 26 | const auto fftSize = this->getFftSize() / 2; // we are only mapping the real components so ignoring imaginary |
| 27 | const auto controlPointsSize = controlPoints.size(); |
| 28 | |
| 29 | if(fftSize == 0 || controlPointsSize == 0) { return; } |
| 30 | if(fftSize == controlPointsSize) { |
| 31 | |
| 32 | Array<int> fftRangedControlPoints; |
| 33 | for(int i=0; i < controlPointsSize; ++i) { |
| 34 | fftRangedControlPoints.add(static_cast<int>(controlPoints[i] * static_cast<float>(fftSize))); |
| 35 | } |
| 36 | |
| 37 | *pWriteArray = fftRangedControlPoints; |
| 38 | } |
| 39 | else if(fftSize < controlPointsSize) { |
| 40 | const auto skip = fftSize / controlPointsSize; |
| 41 | |
| 42 | Array<int> compactedOutput; |
| 43 | for(int i=0; i<controlPointsSize; i += skip) { |
| 44 | const float value = controlPoints[i]; |
| 45 | compactedOutput.add(static_cast<int>(value * static_cast<float>(fftSize))); |
| 46 | } |
| 47 | |
| 48 | *pWriteArray = compactedOutput; |
| 49 | } |
| 50 | else /* fftSize > controlPointSize */ { |
| 51 | |
| 52 | Array<int> expandedOutput; |
| 53 | const auto indexScale = static_cast<float>(controlPointsSize) / static_cast<float>(fftSize); |
| 54 | |
| 55 | for(int i=0; i<fftSize; ++i) { |
| 56 | const float controlPointIndex = static_cast<float>(i) * indexScale; |
| 57 | const int indA = static_cast<int>(controlPointIndex); |
| 58 | const int indB = indA + 1; |
| 59 | |
| 60 | const float aValue = controlPoints[indA]; |
| 61 | if(indB >= controlPointsSize) { |
| 62 | expandedOutput.add(static_cast<int>(aValue * static_cast<float>(fftSize))); |
| 63 | } else { |
| 64 | const float bValue = controlPoints[indB]; |
| 65 | const float value = utilities::interp_lin(aValue, bValue, controlPointIndex); |
| 66 | expandedOutput.add(static_cast<int>(value * static_cast<float>(fftSize))); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | *pWriteArray = expandedOutput; |
| 71 | } |
| 72 | |
| 73 | m_morphPointsChanged = true; |
| 74 | } |
no test coverage detected