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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 bool AudioContext::hasPendingActivity() const | 270 bool AudioContext::hasPendingActivity() const |
271 { | 271 { |
272 // According to spec AudioContext must die only after page navigates. | 272 // According to spec AudioContext must die only after page navigates. |
273 return !m_isCleared; | 273 return !m_isCleared; |
274 } | 274 } |
275 | 275 |
276 PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si
ze_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) | 276 PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si
ze_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) |
277 { | 277 { |
278 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfChannels, numb
erOfFrames, sampleRate); | 278 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfChannels, numb
erOfFrames, sampleRate, exceptionState); |
279 if (!audioBuffer.get()) { | |
280 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { | |
281 exceptionState.throwDOMException( | |
282 NotSupportedError, | |
283 "requested number of channels (" + String::number(numberOfChanne
ls) + ") exceeds maximum (" + String::number(AudioContext::maxNumberOfChannels()
) + ")"); | |
284 } else if (sampleRate < AudioBuffer::minAllowedSampleRate() || sampleRat
e > AudioBuffer::maxAllowedSampleRate()) { | |
285 exceptionState.throwDOMException( | |
286 NotSupportedError, | |
287 "requested sample rate (" + String::number(sampleRate) | |
288 + ") does not lie in the allowed range of " | |
289 + String::number(AudioBuffer::minAllowedSampleRate()) | |
290 + "-" + String::number(AudioBuffer::maxAllowedSampleRate()) + "
Hz"); | |
291 } else if (!numberOfFrames) { | |
292 exceptionState.throwDOMException( | |
293 NotSupportedError, | |
294 "number of frames must be greater than 0."); | |
295 } else { | |
296 exceptionState.throwDOMException( | |
297 NotSupportedError, | |
298 "unable to create buffer of " + String::number(numberOfChannels) | |
299 + " channel(s) of " + String::number(numberOfFrames) | |
300 + " frames each."); | |
301 } | |
302 return nullptr; | |
303 } | |
304 | 279 |
305 return audioBuffer; | 280 return audioBuffer; |
306 } | 281 } |
307 | 282 |
308 void AudioContext::decodeAudioData(ArrayBuffer* audioData, PassOwnPtr<AudioBuffe
rCallback> successCallback, PassOwnPtr<AudioBufferCallback> errorCallback, Excep
tionState& exceptionState) | 283 void AudioContext::decodeAudioData(ArrayBuffer* audioData, PassOwnPtr<AudioBuffe
rCallback> successCallback, PassOwnPtr<AudioBufferCallback> errorCallback, Excep
tionState& exceptionState) |
309 { | 284 { |
310 if (!audioData) { | 285 if (!audioData) { |
311 exceptionState.throwDOMException( | 286 exceptionState.throwDOMException( |
312 SyntaxError, | 287 SyntaxError, |
313 "invalid ArrayBuffer for audioData."); | 288 "invalid ArrayBuffer for audioData."); |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 // Avoid firing the event if the document has already gone away. | 955 // Avoid firing the event if the document has already gone away. |
981 if (executionContext()) { | 956 if (executionContext()) { |
982 // Call the offline rendering completion event listener. | 957 // Call the offline rendering completion event listener. |
983 dispatchEvent(OfflineAudioCompletionEvent::create(renderedBuffer)); | 958 dispatchEvent(OfflineAudioCompletionEvent::create(renderedBuffer)); |
984 } | 959 } |
985 } | 960 } |
986 | 961 |
987 } // namespace WebCore | 962 } // namespace WebCore |
988 | 963 |
989 #endif // ENABLE(WEB_AUDIO) | 964 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |