| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 float sampleRate, | 335 float sampleRate, |
| 336 size_t bufferSize, | 336 size_t bufferSize, |
| 337 unsigned numberOfInputChannels, | 337 unsigned numberOfInputChannels, |
| 338 unsigned numberOfOutputChannels) | 338 unsigned numberOfOutputChannels) |
| 339 : AudioNode(context), ActiveScriptWrappable(this) { | 339 : AudioNode(context), ActiveScriptWrappable(this) { |
| 340 setHandler(ScriptProcessorHandler::create(*this, sampleRate, bufferSize, | 340 setHandler(ScriptProcessorHandler::create(*this, sampleRate, bufferSize, |
| 341 numberOfInputChannels, | 341 numberOfInputChannels, |
| 342 numberOfOutputChannels)); | 342 numberOfOutputChannels)); |
| 343 } | 343 } |
| 344 | 344 |
| 345 static size_t chooseBufferSize() { | 345 static size_t chooseBufferSize(size_t callbackBufferSize) { |
| 346 // Choose a buffer size based on the audio hardware buffer size. Arbitarily | 346 // Choose a buffer size based on the audio hardware buffer size. Arbitarily |
| 347 // make it a power of two that is 4 times greater than the hardware buffer | 347 // make it a power of two that is 4 times greater than the hardware buffer |
| 348 // size. | 348 // size. |
| 349 // FIXME: What is the best way to choose this? | 349 // FIXME: What is the best way to choose this? |
| 350 size_t hardwareBufferSize = Platform::current()->audioHardwareBufferSize(); | |
| 351 size_t bufferSize = | 350 size_t bufferSize = |
| 352 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize) + 0.5); | 351 1 << static_cast<unsigned>(log2(4 * callbackBufferSize) + 0.5); |
| 353 | 352 |
| 354 if (bufferSize < 256) | 353 if (bufferSize < 256) |
| 355 return 256; | 354 return 256; |
| 356 if (bufferSize > 16384) | 355 if (bufferSize > 16384) |
| 357 return 16384; | 356 return 16384; |
| 358 | 357 |
| 359 return bufferSize; | 358 return bufferSize; |
| 360 } | 359 } |
| 361 | 360 |
| 362 ScriptProcessorNode* ScriptProcessorNode::create( | 361 ScriptProcessorNode* ScriptProcessorNode::create( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 IndexSizeError, | 423 IndexSizeError, |
| 425 "number of output channels (" + String::number(numberOfOutputChannels) + | 424 "number of output channels (" + String::number(numberOfOutputChannels) + |
| 426 ") exceeds maximum (" + | 425 ") exceeds maximum (" + |
| 427 String::number(BaseAudioContext::maxNumberOfChannels()) + ")."); | 426 String::number(BaseAudioContext::maxNumberOfChannels()) + ")."); |
| 428 return nullptr; | 427 return nullptr; |
| 429 } | 428 } |
| 430 | 429 |
| 431 // Check for valid buffer size. | 430 // Check for valid buffer size. |
| 432 switch (bufferSize) { | 431 switch (bufferSize) { |
| 433 case 0: | 432 case 0: |
| 434 bufferSize = chooseBufferSize(); | 433 // Choose an appropriate size. For an AudioContext, we need to |
| 434 // choose an appropriate size based on the callback buffer size. |
| 435 // For OfflineAudioContext, there's no callback buffer size, so |
| 436 // just use the minimum valid buffer size. |
| 437 bufferSize = |
| 438 context.hasRealtimeConstraint() |
| 439 ? chooseBufferSize(context.destination()->callbackBufferSize()) |
| 440 : 256; |
| 435 break; | 441 break; |
| 436 case 256: | 442 case 256: |
| 437 case 512: | 443 case 512: |
| 438 case 1024: | 444 case 1024: |
| 439 case 2048: | 445 case 2048: |
| 440 case 4096: | 446 case 4096: |
| 441 case 8192: | 447 case 8192: |
| 442 case 16384: | 448 case 16384: |
| 443 break; | 449 break; |
| 444 default: | 450 default: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 473 | 479 |
| 474 // If |onaudioprocess| event handler is defined, the node should not be | 480 // If |onaudioprocess| event handler is defined, the node should not be |
| 475 // GCed even if it is out of scope. | 481 // GCed even if it is out of scope. |
| 476 if (hasEventListeners(EventTypeNames::audioprocess)) | 482 if (hasEventListeners(EventTypeNames::audioprocess)) |
| 477 return true; | 483 return true; |
| 478 | 484 |
| 479 return false; | 485 return false; |
| 480 } | 486 } |
| 481 | 487 |
| 482 } // namespace blink | 488 } // namespace blink |
| OLD | NEW |