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