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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 playback_rate_(playback_rate), | 65 playback_rate_(playback_rate), |
66 detune_(detune), | 66 detune_(detune), |
67 is_looping_(false), | 67 is_looping_(false), |
68 did_set_looping_(false), | 68 did_set_looping_(false), |
69 loop_start_(0), | 69 loop_start_(0), |
70 loop_end_(0), | 70 loop_end_(0), |
71 virtual_read_index_(0), | 71 virtual_read_index_(0), |
72 is_grain_(false), | 72 is_grain_(false), |
73 grain_offset_(0.0), | 73 grain_offset_(0.0), |
74 grain_duration_(kDefaultGrainDuration), | 74 grain_duration_(kDefaultGrainDuration), |
75 min_playback_rate_(1.0) { | 75 min_playback_rate_(1.0), |
76 buffer_has_been_set_(false) { | |
76 // Default to mono. A call to setBuffer() will set the number of output | 77 // Default to mono. A call to setBuffer() will set the number of output |
77 // channels to that of the buffer. | 78 // channels to that of the buffer. |
78 AddOutput(1); | 79 AddOutput(1); |
79 | 80 |
80 Initialize(); | 81 Initialize(); |
81 } | 82 } |
82 | 83 |
83 PassRefPtr<AudioBufferSourceHandler> AudioBufferSourceHandler::Create( | 84 PassRefPtr<AudioBufferSourceHandler> AudioBufferSourceHandler::Create( |
84 AudioNode& node, | 85 AudioNode& node, |
85 float sample_rate, | 86 float sample_rate, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 | 382 |
382 virtual_read_index_ = virtual_read_index; | 383 virtual_read_index_ = virtual_read_index; |
383 | 384 |
384 return true; | 385 return true; |
385 } | 386 } |
386 | 387 |
387 void AudioBufferSourceHandler::SetBuffer(AudioBuffer* buffer, | 388 void AudioBufferSourceHandler::SetBuffer(AudioBuffer* buffer, |
388 ExceptionState& exception_state) { | 389 ExceptionState& exception_state) { |
389 DCHECK(IsMainThread()); | 390 DCHECK(IsMainThread()); |
390 | 391 |
391 if (buffer_) { | 392 if (buffer && buffer_has_been_set_) { |
392 exception_state.ThrowDOMException( | 393 exception_state.ThrowDOMException(kInvalidStateError, |
393 kInvalidStateError, | 394 "Cannot set buffer to non-null after it " |
394 "Cannot set buffer after it has been already been set"); | 395 "has been already been set to a non-null " |
396 "buffer"); | |
hongchan
2017/07/28 18:45:32
I am not so sure about the term "a non-null buffer
Raymond Toy
2017/07/28 19:16:55
This is the absn.buffer attribute, so you can set
| |
395 return; | 397 return; |
396 } | 398 } |
397 | 399 |
398 // The context must be locked since changing the buffer can re-configure the | 400 // The context must be locked since changing the buffer can re-configure the |
399 // number of channels that are output. | 401 // number of channels that are output. |
400 BaseAudioContext::AutoLocker context_locker(Context()); | 402 BaseAudioContext::AutoLocker context_locker(Context()); |
401 | 403 |
402 // This synchronizes with process(). | 404 // This synchronizes with process(). |
403 MutexLocker process_locker(process_lock_); | 405 MutexLocker process_locker(process_lock_); |
404 | 406 |
405 if (buffer) { | 407 if (buffer) { |
408 buffer_has_been_set_ = true; | |
409 | |
406 // Do any necesssary re-configuration to the buffer's number of channels. | 410 // Do any necesssary re-configuration to the buffer's number of channels. |
407 unsigned number_of_channels = buffer->numberOfChannels(); | 411 unsigned number_of_channels = buffer->numberOfChannels(); |
408 | 412 |
409 // This should not be possible since AudioBuffers can't be created with too | 413 // This should not be possible since AudioBuffers can't be created with too |
410 // many channels either. | 414 // many channels either. |
411 if (number_of_channels > BaseAudioContext::MaxNumberOfChannels()) { | 415 if (number_of_channels > BaseAudioContext::MaxNumberOfChannels()) { |
412 exception_state.ThrowDOMException( | 416 exception_state.ThrowDOMException( |
413 kNotSupportedError, | 417 kNotSupportedError, |
414 ExceptionMessages::IndexOutsideRange( | 418 ExceptionMessages::IndexOutsideRange( |
415 "number of input channels", number_of_channels, 1u, | 419 "number of input channels", number_of_channels, 1u, |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 | 767 |
764 void AudioBufferSourceNode::start(double when, | 768 void AudioBufferSourceNode::start(double when, |
765 double grain_offset, | 769 double grain_offset, |
766 double grain_duration, | 770 double grain_duration, |
767 ExceptionState& exception_state) { | 771 ExceptionState& exception_state) { |
768 GetAudioBufferSourceHandler().Start(when, grain_offset, grain_duration, | 772 GetAudioBufferSourceHandler().Start(when, grain_offset, grain_duration, |
769 exception_state); | 773 exception_state); |
770 } | 774 } |
771 | 775 |
772 } // namespace blink | 776 } // namespace blink |
OLD | NEW |