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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 | 342 |
343 case ParamEvent::SetTarget: | 343 case ParamEvent::SetTarget: |
344 { | 344 { |
345 currentTime = fillToTime; | 345 currentTime = fillToTime; |
346 | 346 |
347 // Exponential approach to target value with given time cons tant. | 347 // Exponential approach to target value with given time cons tant. |
348 float target = event.value(); | 348 float target = event.value(); |
349 float timeConstant = event.timeConstant(); | 349 float timeConstant = event.timeConstant(); |
350 float discreteTimeConstant = static_cast<float>(AudioUtiliti es::discreteTimeConstantForSampleRate(timeConstant, controlRate)); | 350 float discreteTimeConstant = static_cast<float>(AudioUtiliti es::discreteTimeConstantForSampleRate(timeConstant, controlRate)); |
351 | 351 |
352 #if CPU(X86) || CPU(X86_64) | |
353 // Resorve recursion by expanding constants to achieve a 4-s tep loop unrolling. | |
Raymond Toy
2015/08/14 16:00:03
"Resorve"?
adrian.belgun
2015/08/17 07:58:14
Done. Sorry for that.
| |
354 // v1 = v0 + (t - v0) * c | |
355 // v2 = v1 + (t - v1) * c | |
356 // v2 = v0 + (t - v0) * c + (t - (v0 + (t - v0) * c)) * c | |
357 // v2 = v0 + (t - v0) * c + (t - v0) * c - (t - v0) * c * c | |
358 // v2 = v0 + (t - v0) * (2c - c^2) | |
359 // Thus c0 = c, c1 = 2c - c^2. The same logic applies to c2 and c3. | |
360 const float c0 = discreteTimeConstant; | |
361 const float c1 = 2 * c0 - c0 * c0; | |
362 const float c2 = 3 * c0 - 3 * c0 * c0 + c0 * c0 * c0; | |
363 const float c3 = 4 * c0 - 6 * c0 * c0 + 4 * c0 * c0 * c0 - c 0 * c0 * c0 * c0; | |
364 | |
365 float delta; | |
366 __m128 vC = _mm_set_ps(c2, c1, c0, 0); | |
367 __m128 vDelta, vValue, vResult; | |
368 | |
369 // Process 4 loop steps. | |
370 unsigned fillToFrameTrunc = writeIndex + ((fillToFrame - wri teIndex) / 4) * 4; | |
371 for (; writeIndex < fillToFrameTrunc; writeIndex += 4) { | |
372 delta = target - value; | |
373 vDelta = _mm_set_ps1(delta); | |
374 vValue = _mm_set_ps1(value); | |
375 | |
376 vResult = _mm_add_ps(vValue, _mm_mul_ps(vDelta, vC)); | |
377 _mm_storeu_ps(values + writeIndex, vResult); | |
378 | |
379 // Update value for next iteration. | |
380 value += delta * c3; | |
381 } | |
382 #endif | |
383 // Serially process remaining values | |
352 for (; writeIndex < fillToFrame; ++writeIndex) { | 384 for (; writeIndex < fillToFrame; ++writeIndex) { |
353 values[writeIndex] = value; | 385 values[writeIndex] = value; |
354 value += (target - value) * discreteTimeConstant; | 386 value += (target - value) * discreteTimeConstant; |
355 } | 387 } |
356 | 388 |
357 break; | 389 break; |
358 } | 390 } |
359 | 391 |
360 case ParamEvent::SetValueCurve: | 392 case ParamEvent::SetValueCurve: |
361 { | 393 { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 // to the end of the values buffer. | 490 // to the end of the values buffer. |
459 for (; writeIndex < numberOfValues; ++writeIndex) | 491 for (; writeIndex < numberOfValues; ++writeIndex) |
460 values[writeIndex] = value; | 492 values[writeIndex] = value; |
461 | 493 |
462 return value; | 494 return value; |
463 } | 495 } |
464 | 496 |
465 } // namespace blink | 497 } // namespace blink |
466 | 498 |
467 #endif // ENABLE(WEB_AUDIO) | 499 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |