OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/webaudio/AudioContext.h" | 5 #include "modules/webaudio/AudioContext.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ExceptionMessages::IndexExceedsMaximumBound( | 47 ExceptionMessages::IndexExceedsMaximumBound( |
48 "number of hardware contexts", g_hardware_context_count, | 48 "number of hardware contexts", g_hardware_context_count, |
49 kMaxHardwareContexts)); | 49 kMaxHardwareContexts)); |
50 return nullptr; | 50 return nullptr; |
51 } | 51 } |
52 | 52 |
53 WebAudioLatencyHint latency_hint(WebAudioLatencyHint::kCategoryInteractive); | 53 WebAudioLatencyHint latency_hint(WebAudioLatencyHint::kCategoryInteractive); |
54 if (context_options.latencyHint().isAudioContextLatencyCategory()) { | 54 if (context_options.latencyHint().isAudioContextLatencyCategory()) { |
55 latency_hint = WebAudioLatencyHint( | 55 latency_hint = WebAudioLatencyHint( |
56 context_options.latencyHint().getAsAudioContextLatencyCategory()); | 56 context_options.latencyHint().getAsAudioContextLatencyCategory()); |
| 57 } else if (context_options.latencyHint().isDouble()) { |
| 58 // This should be the requested output latency in seconds, without taking |
| 59 // into account double buffering (same as baseLatency). |
| 60 latency_hint = |
| 61 WebAudioLatencyHint(context_options.latencyHint().getAsDouble()); |
57 } | 62 } |
58 // TODO: add support for latencyHint().isDouble() | |
59 | 63 |
60 AudioContext* audio_context = new AudioContext(document, latency_hint); | 64 AudioContext* audio_context = new AudioContext(document, latency_hint); |
61 audio_context->SuspendIfNeeded(); | 65 audio_context->SuspendIfNeeded(); |
62 | 66 |
63 if (!AudioUtilities::IsValidAudioBufferSampleRate( | 67 if (!AudioUtilities::IsValidAudioBufferSampleRate( |
64 audio_context->sampleRate())) { | 68 audio_context->sampleRate())) { |
65 exception_state.ThrowDOMException( | 69 exception_state.ThrowDOMException( |
66 kNotSupportedError, | 70 kNotSupportedError, |
67 ExceptionMessages::IndexOutsideRange( | 71 ExceptionMessages::IndexOutsideRange( |
68 "hardware sample rate", audio_context->sampleRate(), | 72 "hardware sample rate", audio_context->sampleRate(), |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DCHECK(destination()); | 261 DCHECK(destination()); |
258 | 262 |
259 if (ContextState() == kRunning) { | 263 if (ContextState() == kRunning) { |
260 destination()->GetAudioDestinationHandler().StopRendering(); | 264 destination()->GetAudioDestinationHandler().StopRendering(); |
261 SetContextState(kSuspended); | 265 SetContextState(kSuspended); |
262 GetDeferredTaskHandler().ClearHandlersToBeDeleted(); | 266 GetDeferredTaskHandler().ClearHandlersToBeDeleted(); |
263 } | 267 } |
264 } | 268 } |
265 | 269 |
266 double AudioContext::baseLatency() const { | 270 double AudioContext::baseLatency() const { |
267 return FramesPerBuffer() * 2 / static_cast<double>(sampleRate()); | 271 return FramesPerBuffer() / static_cast<double>(sampleRate()); |
268 } | 272 } |
269 | 273 |
270 } // namespace blink | 274 } // namespace blink |
OLD | NEW |