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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 , m_preDelayReadIndex(0) | 48 , m_preDelayReadIndex(0) |
49 , m_preDelayWriteIndex(DefaultPreDelayFrames) | 49 , m_preDelayWriteIndex(DefaultPreDelayFrames) |
50 , m_ratio(uninitializedValue) | 50 , m_ratio(uninitializedValue) |
51 , m_slope(uninitializedValue) | 51 , m_slope(uninitializedValue) |
52 , m_linearThreshold(uninitializedValue) | 52 , m_linearThreshold(uninitializedValue) |
53 , m_dbThreshold(uninitializedValue) | 53 , m_dbThreshold(uninitializedValue) |
54 , m_dbKnee(uninitializedValue) | 54 , m_dbKnee(uninitializedValue) |
55 , m_kneeThreshold(uninitializedValue) | 55 , m_kneeThreshold(uninitializedValue) |
56 , m_kneeThresholdDb(uninitializedValue) | 56 , m_kneeThresholdDb(uninitializedValue) |
57 , m_ykneeThresholdDb(uninitializedValue) | 57 , m_ykneeThresholdDb(uninitializedValue) |
58 , m_K(uninitializedValue) | 58 , m_knee(uninitializedValue) |
59 { | 59 { |
60 setNumberOfChannels(numberOfChannels); | 60 setNumberOfChannels(numberOfChannels); |
61 | 61 |
62 // Initializes most member variables | 62 // Initializes most member variables |
63 reset(); | 63 reset(); |
64 | 64 |
65 m_meteringReleaseK = static_cast<float>(discreteTimeConstantForSampleRate(me
teringReleaseTimeConstant, sampleRate)); | 65 m_meteringReleaseK = static_cast<float>(discreteTimeConstantForSampleRate(me
teringReleaseTimeConstant, sampleRate)); |
66 } | 66 } |
67 | 67 |
68 void DynamicsCompressorKernel::setNumberOfChannels(unsigned numberOfChannels) | 68 void DynamicsCompressorKernel::setNumberOfChannels(unsigned numberOfChannels) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 m_ratio = ratio; | 183 m_ratio = ratio; |
184 m_slope = 1 / m_ratio; | 184 m_slope = 1 / m_ratio; |
185 | 185 |
186 float k = kAtSlope(1 / m_ratio); | 186 float k = kAtSlope(1 / m_ratio); |
187 | 187 |
188 m_kneeThresholdDb = dbThreshold + dbKnee; | 188 m_kneeThresholdDb = dbThreshold + dbKnee; |
189 m_kneeThreshold = decibelsToLinear(m_kneeThresholdDb); | 189 m_kneeThreshold = decibelsToLinear(m_kneeThresholdDb); |
190 | 190 |
191 m_ykneeThresholdDb = linearToDecibels(kneeCurve(m_kneeThreshold, k)); | 191 m_ykneeThresholdDb = linearToDecibels(kneeCurve(m_kneeThreshold, k)); |
192 | 192 |
193 m_K = k; | 193 m_knee = k; |
194 } | 194 } |
195 return m_K; | 195 return m_knee; |
196 } | 196 } |
197 | 197 |
198 void DynamicsCompressorKernel::process(const float* sourceChannels[], | 198 void DynamicsCompressorKernel::process(const float* sourceChannels[], |
199 float* destinationChannels[], | 199 float* destinationChannels[], |
200 unsigned numberOfChannels, | 200 unsigned numberOfChannels, |
201 unsigned framesToProcess, | 201 unsigned framesToProcess, |
202 | 202 |
203 float dbThreshold, | 203 float dbThreshold, |
204 float dbKnee, | 204 float dbKnee, |
205 float ratio, | 205 float ratio, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // Polynomial of the form | 249 // Polynomial of the form |
250 // y = a + b*x + c*x^2 + d*x^3 + e*x^4; | 250 // y = a + b*x + c*x^2 + d*x^3 + e*x^4; |
251 | 251 |
252 float y1 = releaseFrames * releaseZone1; | 252 float y1 = releaseFrames * releaseZone1; |
253 float y2 = releaseFrames * releaseZone2; | 253 float y2 = releaseFrames * releaseZone2; |
254 float y3 = releaseFrames * releaseZone3; | 254 float y3 = releaseFrames * releaseZone3; |
255 float y4 = releaseFrames * releaseZone4; | 255 float y4 = releaseFrames * releaseZone4; |
256 | 256 |
257 // All of these coefficients were derived for 4th order polynomial curve fit
ting where the y values | 257 // All of these coefficients were derived for 4th order polynomial curve fit
ting where the y values |
258 // match the evenly spaced x values as follows: (y1 : x == 0, y2 : x == 1, y
3 : x == 2, y4 : x == 3) | 258 // match the evenly spaced x values as follows: (y1 : x == 0, y2 : x == 1, y
3 : x == 2, y4 : x == 3) |
259 float kA = 0.9999999999999998f*y1 + 1.8432219684323923e-16f*y2 - 1.937339435
1676423e-16f*y3 + 8.824516011816245e-18f*y4; | 259 float a = 0.9999999999999998f * y1 + 1.8432219684323923e-16f * y2 - 1.937339
4351676423e-16f * y3 + 8.824516011816245e-18f * y4; |
260 float kB = -1.5788320352845888f*y1 + 2.3305837032074286f*y2 - 0.914119420484
0429f*y3 + 0.1623677525612032f*y4; | 260 float b = -1.5788320352845888f * y1 + 2.3305837032074286f * y2 - 0.914119420
4840429f * y3 + 0.1623677525612032f * y4; |
261 float kC = 0.5334142869106424f*y1 - 1.272736789213631f*y2 + 0.92588560422075
12f*y3 - 0.18656310191776226f*y4; | 261 float c = 0.5334142869106424f * y1 - 1.272736789213631f * y2 + 0.92588560422
07512f * y3 - 0.18656310191776226f * y4; |
262 float kD = 0.08783463138207234f*y1 - 0.1694162967925622f*y2 + 0.085880579515
95272f*y3 - 0.00429891410546283f*y4; | 262 float d = 0.08783463138207234f * y1 - 0.1694162967925622f * y2 + 0.085880579
51595272f * y3 - 0.00429891410546283f * y4; |
263 float kE = -0.042416883008123074f*y1 + 0.1115693827987602f*y2 - 0.0976467632
5265872f*y3 + 0.028494263462021576f*y4; | 263 float e = -0.042416883008123074f * y1 + 0.1115693827987602f * y2 - 0.0976467
6325265872f * y3 + 0.028494263462021576f * y4; |
264 | 264 |
265 // x ranges from 0 -> 3 0 1 2 3 | 265 // x ranges from 0 -> 3 0 1 2 3 |
266 // -15 -10 -5 0db | 266 // -15 -10 -5 0db |
267 | 267 |
268 // y calculates adaptive release frames depending on the amount of compressi
on. | 268 // y calculates adaptive release frames depending on the amount of compressi
on. |
269 | 269 |
270 setPreDelayTime(preDelayTime); | 270 setPreDelayTime(preDelayTime); |
271 | 271 |
272 const int nDivisionFrames = 32; | 272 const int nDivisionFrames = 32; |
273 | 273 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Contain within range: -12 -> 0 then scale to go from 0 -> 3 | 318 // Contain within range: -12 -> 0 then scale to go from 0 -> 3 |
319 float x = compressionDiffDb; | 319 float x = compressionDiffDb; |
320 x = clampTo(x, -12.0f, 0.0f); | 320 x = clampTo(x, -12.0f, 0.0f); |
321 x = 0.25f * (x + 12); | 321 x = 0.25f * (x + 12); |
322 | 322 |
323 // Compute adaptive release curve using 4th order polynomial. | 323 // Compute adaptive release curve using 4th order polynomial. |
324 // Normal values for the polynomial coefficients would create a mono
tonically increasing function. | 324 // Normal values for the polynomial coefficients would create a mono
tonically increasing function. |
325 float x2 = x * x; | 325 float x2 = x * x; |
326 float x3 = x2 * x; | 326 float x3 = x2 * x; |
327 float x4 = x2 * x2; | 327 float x4 = x2 * x2; |
328 float releaseFrames = kA + kB * x + kC * x2 + kD * x3 + kE * x4; | 328 float releaseFrames = a + b * x + c * x2 + d * x3 + e * x4; |
329 | 329 |
330 #define kSpacingDb 5 | 330 #define kSpacingDb 5 |
331 float dbPerFrame = kSpacingDb / releaseFrames; | 331 float dbPerFrame = kSpacingDb / releaseFrames; |
332 | 332 |
333 envelopeRate = decibelsToLinear(dbPerFrame); | 333 envelopeRate = decibelsToLinear(dbPerFrame); |
334 } else { | 334 } else { |
335 // Attack mode - compressionDiffDb should be positive dB | 335 // Attack mode - compressionDiffDb should be positive dB |
336 | 336 |
337 // Fix gremlins. | 337 // Fix gremlins. |
338 if (std::isnan(compressionDiffDb)) | 338 if (std::isnan(compressionDiffDb)) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 m_preDelayBuffers[i]->zero(); | 462 m_preDelayBuffers[i]->zero(); |
463 | 463 |
464 m_preDelayReadIndex = 0; | 464 m_preDelayReadIndex = 0; |
465 m_preDelayWriteIndex = DefaultPreDelayFrames; | 465 m_preDelayWriteIndex = DefaultPreDelayFrames; |
466 | 466 |
467 m_maxAttackCompressionDiffDb = -1; // uninitialized state | 467 m_maxAttackCompressionDiffDb = -1; // uninitialized state |
468 } | 468 } |
469 | 469 |
470 } // namespace blink | 470 } // namespace blink |
471 | 471 |
OLD | NEW |