Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: media/base/audio_latency.cc

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: More updates based on reviewer comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "media/base/audio_latency.h" 5 #include "media/base/audio_latency.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "media/base/audio_parameters.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 namespace { 17 namespace {
17 #if !defined(OS_WIN) 18 #if !defined(OS_WIN)
18 // Taken from "Bit Twiddling Hacks" 19 // Taken from "Bit Twiddling Hacks"
19 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 20 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
20 uint32_t RoundUpToPowerOfTwo(uint32_t v) { 21 uint32_t RoundUpToPowerOfTwo(uint32_t v) {
21 v--; 22 v--;
22 v |= v >> 1; 23 v |= v >> 1;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // the jitter. 120 // the jitter.
120 const int kSmallBufferSize = 1024; 121 const int kSmallBufferSize = 1024;
121 const int kDefaultCallbackBufferSize = 2048; 122 const int kDefaultCallbackBufferSize = 2048;
122 if (hardware_buffer_size <= kSmallBufferSize) 123 if (hardware_buffer_size <= kSmallBufferSize)
123 return kDefaultCallbackBufferSize; 124 return kDefaultCallbackBufferSize;
124 #endif 125 #endif
125 126
126 return hardware_buffer_size; 127 return hardware_buffer_size;
127 } 128 }
128 129
130 int AudioLatency::GetExactBufferSize(base::TimeDelta duration,
131 const AudioParameters& hardware_params) {
132 const int hardware_buffer_size = hardware_params.frames_per_buffer();
133 const double requested_buffer_size =
134 duration.InSecondsF() * hardware_params.sample_rate();
135
136 // Round up the requested size to the nearest multiple of the hardware size
137 const int buffer_size =
138 std::ceil(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) *
139 hardware_buffer_size;
o1ka 2017/03/29 10:56:05 It's actually not the nearest multiply (round), bu
Andrew MacPherson 2017/03/30 08:07:18 This was my intent but since both you and dalecurt
140
141 const double twenty_ms_size = 2.0 * hardware_params.sample_rate() / 100;
142 const int max_buffer_size =
143 std::ceil(twenty_ms_size / hardware_buffer_size) * hardware_buffer_size;
o1ka 2017/03/29 10:56:05 In fact, we are just limiting |duration| to 20 ms,
DaleCurtis 2017/03/29 22:42:41 Hmm, this wasn't what I was proposing. I was propo
Andrew MacPherson 2017/03/30 08:07:18 Sorry, my mistake here. I can remove this but I be
DaleCurtis 2017/03/30 18:53:46 This should be removed from this code. We don't wa
144
145 return std::max(std::min(buffer_size, max_buffer_size), hardware_buffer_size);
146 }
o1ka 2017/03/29 10:56:05 Dale - Is our intention to use multiplies of HW bu
DaleCurtis 2017/03/29 22:42:41 Yes, I think that should be okay and likely will r
DaleCurtis 2017/03/29 22:42:41 Yes, I think that should be okay and likely will r
Andrew MacPherson 2017/03/30 08:07:18 Ok, I've updated GetHighLatencyBufferSize() to alw
147
129 } // namespace media 148 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_latency.h ('k') | third_party/WebKit/LayoutTests/webaudio/audiocontextoptions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698