Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp

Issue 2000423008: Clamp AudioParam automations to the nominal range. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 330
331 // Remove all events starting at startTime. 331 // Remove all events starting at startTime.
332 for (unsigned i = 0; i < m_events.size(); ++i) { 332 for (unsigned i = 0; i < m_events.size(); ++i) {
333 if (m_events[i].time() >= startTime) { 333 if (m_events[i].time() >= startTime) {
334 m_events.remove(i, m_events.size() - i); 334 m_events.remove(i, m_events.size() - i);
335 break; 335 break;
336 } 336 }
337 } 337 }
338 } 338 }
339 339
340 float AudioParamTimeline::valueForContextTime(AudioDestinationHandler& audioDest ination, float defaultValue, bool& hasValue) 340 float AudioParamTimeline::valueForContextTime(AudioDestinationHandler& audioDest ination, float defaultValue, bool& hasValue, float minValue, float maxValue)
341 { 341 {
342 { 342 {
343 MutexTryLocker tryLocker(m_eventsLock); 343 MutexTryLocker tryLocker(m_eventsLock);
344 if (!tryLocker.locked() || !m_events.size() || audioDestination.currentT ime() < m_events[0].time()) { 344 if (!tryLocker.locked() || !m_events.size() || audioDestination.currentT ime() < m_events[0].time()) {
345 hasValue = false; 345 hasValue = false;
346 return defaultValue; 346 return defaultValue;
347 } 347 }
348 } 348 }
349 349
350 // Ask for just a single value. 350 // Ask for just a single value.
351 float value; 351 float value;
352 double sampleRate = audioDestination.sampleRate(); 352 double sampleRate = audioDestination.sampleRate();
353 size_t startFrame = audioDestination.currentSampleFrame(); 353 size_t startFrame = audioDestination.currentSampleFrame();
354 double controlRate = sampleRate / AudioHandler::ProcessingSizeInFrames; // o ne parameter change per render quantum 354 double controlRate = sampleRate / AudioHandler::ProcessingSizeInFrames; // o ne parameter change per render quantum
355 value = valuesForFrameRange(startFrame, startFrame + 1, defaultValue, &value , 1, sampleRate, controlRate); 355 value = valuesForFrameRange(startFrame, startFrame + 1, defaultValue, &value , 1, sampleRate, controlRate, minValue, maxValue);
356 356
357 hasValue = true; 357 hasValue = true;
358 return value; 358 return value;
359 } 359 }
360 360
361 float AudioParamTimeline::valuesForFrameRange( 361 float AudioParamTimeline::valuesForFrameRange(
362 size_t startFrame, 362 size_t startFrame,
363 size_t endFrame, 363 size_t endFrame,
364 float defaultValue, 364 float defaultValue,
365 float* values, 365 float* values,
366 unsigned numberOfValues, 366 unsigned numberOfValues,
367 double sampleRate, 367 double sampleRate,
368 double controlRate) 368 double controlRate,
369 float minValue,
370 float maxValue)
369 { 371 {
370 // We can't contend the lock in the realtime audio thread. 372 // We can't contend the lock in the realtime audio thread.
371 MutexTryLocker tryLocker(m_eventsLock); 373 MutexTryLocker tryLocker(m_eventsLock);
372 if (!tryLocker.locked()) { 374 if (!tryLocker.locked()) {
373 if (values) { 375 if (values) {
374 for (unsigned i = 0; i < numberOfValues; ++i) 376 for (unsigned i = 0; i < numberOfValues; ++i)
375 values[i] = defaultValue; 377 values[i] = defaultValue;
376 } 378 }
377 return defaultValue; 379 return defaultValue;
378 } 380 }
hongchan 2016/06/17 17:00:40 Sorry to bring this up again, why this pattern is
Raymond Toy 2016/06/17 17:10:05 I didn't actually change this. Are you saying I s
hongchan 2016/06/17 17:55:06 Disregard my comment. They are different, but look
379 381
380 return valuesForFrameRangeImpl(startFrame, endFrame, defaultValue, values, n umberOfValues, sampleRate, controlRate); 382 float lastValue = valuesForFrameRangeImpl(startFrame, endFrame, defaultValue , values, numberOfValues, sampleRate, controlRate);
383
384 // Clamp the values now to the nominal range
385 for (unsigned k = 0; k < numberOfValues; ++k)
386 values[k] = clampTo(values[k], minValue, maxValue);
387
388 return lastValue;
hongchan 2016/06/17 17:00:40 Are these safe outside of tryLock?
Raymond Toy 2016/06/17 17:10:05 I didn't really change the thread safety here. It
hongchan 2016/06/17 17:55:06 I misundstood the scope of tryLock. This looks saf
381 } 389 }
382 390
383 float AudioParamTimeline::valuesForFrameRangeImpl( 391 float AudioParamTimeline::valuesForFrameRangeImpl(
384 size_t startFrame, 392 size_t startFrame,
385 size_t endFrame, 393 size_t endFrame,
386 float defaultValue, 394 float defaultValue,
387 float* values, 395 float* values,
388 unsigned numberOfValues, 396 unsigned numberOfValues,
389 double sampleRate, 397 double sampleRate,
390 double controlRate) 398 double controlRate)
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 for (; writeIndex < numberOfValues; ++writeIndex) 924 for (; writeIndex < numberOfValues; ++writeIndex)
917 values[writeIndex] = value; 925 values[writeIndex] = value;
918 926
919 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last 927 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last
920 // computed value. 928 // computed value.
921 return values[numberOfValues - 1]; 929 return values[numberOfValues - 1];
922 } 930 }
923 931
924 } // namespace blink 932 } // namespace blink
925 933
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698