| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 if (!curveData || !curveLength) { | 90 if (!curveData || !curveLength) { |
| 91 memcpy(destination, source, sizeof(float) * framesToProcess); | 91 memcpy(destination, source, sizeof(float) * framesToProcess); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Apply waveshaping curve. | 95 // Apply waveshaping curve. |
| 96 for (unsigned i = 0; i < framesToProcess; ++i) { | 96 for (unsigned i = 0; i < framesToProcess; ++i) { |
| 97 const float input = source[i]; | 97 const float input = source[i]; |
| 98 | 98 |
| 99 // Calculate a virtual index based on input -1 -> +1 with -1 being curve[0],
+1 being | 99 // Calculate a virtual index based on input -1 -> +1 with -1 being curve[0], |
| 100 // curve[curveLength - 1], and 0 being at the center of the curve data. Then
linearly | 100 // +1 being curve[curveLength - 1], and 0 being at the center of the curve |
| 101 // interpolate between the two points in the curve. | 101 // data. Then linearly interpolate between the two points in the curve. |
| 102 double virtualIndex = 0.5 * (input + 1) * (curveLength - 1); | 102 double virtualIndex = 0.5 * (input + 1) * (curveLength - 1); |
| 103 double output; | 103 double output; |
| 104 | 104 |
| 105 if (virtualIndex < 0) { | 105 if (virtualIndex < 0) { |
| 106 // input < -1, so use curve[0] | 106 // input < -1, so use curve[0] |
| 107 output = curveData[0]; | 107 output = curveData[0]; |
| 108 } else if (virtualIndex >= curveLength - 1) { | 108 } else if (virtualIndex >= curveLength - 1) { |
| 109 // input >= 1, so use last curve value | 109 // input >= 1, so use last curve value |
| 110 output = curveData[curveLength - 1]; | 110 output = curveData[curveLength - 1]; |
| 111 } else { | 111 } else { |
| 112 // The general case where -1 <= input < 1, where 0 <= virtualIndex < curve
Length - 1, | 112 // The general case where -1 <= input < 1, where 0 <= virtualIndex < |
| 113 // so interpolate between the nearest samples on the curve. | 113 // curveLength - 1, so interpolate between the nearest samples on the |
| 114 // curve. |
| 114 unsigned index1 = static_cast<unsigned>(virtualIndex); | 115 unsigned index1 = static_cast<unsigned>(virtualIndex); |
| 115 unsigned index2 = index1 + 1; | 116 unsigned index2 = index1 + 1; |
| 116 double interpolationFactor = virtualIndex - index1; | 117 double interpolationFactor = virtualIndex - index1; |
| 117 | 118 |
| 118 double value1 = curveData[index1]; | 119 double value1 = curveData[index1]; |
| 119 double value2 = curveData[index2]; | 120 double value2 = curveData[index2]; |
| 120 | 121 |
| 121 output = | 122 output = |
| 122 (1.0 - interpolationFactor) * value1 + interpolationFactor * value2; | 123 (1.0 - interpolationFactor) * value1 + interpolationFactor * value2; |
| 123 } | 124 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 break; | 198 break; |
| 198 } | 199 } |
| 199 default: | 200 default: |
| 200 ASSERT_NOT_REACHED(); | 201 ASSERT_NOT_REACHED(); |
| 201 } | 202 } |
| 202 | 203 |
| 203 return static_cast<double>(latencyFrames) / sampleRate(); | 204 return static_cast<double>(latencyFrames) / sampleRate(); |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace blink | 207 } // namespace blink |
| OLD | NEW |