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

Side by Side Diff: content/renderer/media/audio_hardware.cc

Issue 9395057: Fix muted audio when playback rate != 1.0 or 0.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT and issue 9442005 Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/renderer/media/audio_hardware.h" 5 #include "content/renderer/media/audio_hardware.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/view_messages.h" 8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_thread_impl.h" 9 #include "content/renderer/render_thread_impl.h"
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 uint32 buffer_size = 0; 42 uint32 buffer_size = 0;
43 RenderThreadImpl::current()->Send( 43 RenderThreadImpl::current()->Send(
44 new ViewHostMsg_GetHardwareBufferSize(&buffer_size)); 44 new ViewHostMsg_GetHardwareBufferSize(&buffer_size));
45 output_buffer_size = buffer_size; 45 output_buffer_size = buffer_size;
46 } 46 }
47 47
48 return output_buffer_size; 48 return output_buffer_size;
49 } 49 }
50 50
51 size_t GetHighLatencyOutputBufferSize(int sample_rate) { 51 size_t GetHighLatencyOutputBufferSize(int sample_rate) {
52 // The minimum number of samples in a hardware packet. 52 // kNominalBufferSize has been tested on Windows, Mac OS X, and Linux
53 // This value is selected so that we can handle down to 5khz sample rate. 53 // using the low-latency audio codepath (SyncSocket implementation
Chris Rogers 2012/02/23 23:39:54 Sorry for causing all the confusion with the doubl
vrk (LEFT CHROMIUM) 2012/02/27 18:19:13 Oh good catch! I opted for 2. Thanks!
54 static const size_t kMinSamplesPerHardwarePacket = 1024; 54 // with the AUDIO_PCM_LINEAR flag.
55 const size_t kNominalBufferSize = 2048;
55 56
56 // The maximum number of samples in a hardware packet. 57 if (sample_rate <= 48000)
57 // This value is selected so that we can handle up to 192khz sample rate. 58 return kNominalBufferSize;
58 static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024; 59 else if (sample_rate <= 96000)
60 return kNominalBufferSize * 2;
59 61
60 // This constant governs the hardware audio buffer size, this value should be 62 return kNominalBufferSize * 4;
61 // chosen carefully.
62 // This value is selected so that we have 8192 samples for 48khz streams.
63 static const size_t kMillisecondsPerHardwarePacket = 170;
64
65 // Select the number of samples that can provide at least
66 // |kMillisecondsPerHardwarePacket| worth of audio data.
67 size_t samples = kMinSamplesPerHardwarePacket;
68 while (samples <= kMaxSamplesPerHardwarePacket &&
69 samples * base::Time::kMillisecondsPerSecond <
70 sample_rate * kMillisecondsPerHardwarePacket) {
71 samples *= 2;
72 }
73 return samples;
74 } 63 }
75 64
76 uint32 GetInputChannelCount() { 65 uint32 GetInputChannelCount() {
77 DCHECK(RenderThreadImpl::current() != NULL); 66 DCHECK(RenderThreadImpl::current() != NULL);
78 67
79 if (!input_channel_count) { 68 if (!input_channel_count) {
80 uint32 channels = 0; 69 uint32 channels = 0;
81 RenderThreadImpl::current()->Send( 70 RenderThreadImpl::current()->Send(
82 new ViewHostMsg_GetHardwareInputChannelCount(&channels)); 71 new ViewHostMsg_GetHardwareInputChannelCount(&channels));
83 input_channel_count = channels; 72 input_channel_count = channels;
84 } 73 }
85 74
86 return input_channel_count; 75 return input_channel_count;
87 } 76 }
88 77
89 void ResetCache() { 78 void ResetCache() {
90 DCHECK(RenderThreadImpl::current() != NULL); 79 DCHECK(RenderThreadImpl::current() != NULL);
91 80
92 output_sample_rate = 0.0; 81 output_sample_rate = 0.0;
93 input_sample_rate = 0.0; 82 input_sample_rate = 0.0;
94 output_buffer_size = 0; 83 output_buffer_size = 0;
95 input_channel_count = 0; 84 input_channel_count = 0;
96 } 85 }
97 86
98 } // namespace audio_hardware 87 } // namespace audio_hardware
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/audio_renderer_impl.cc » ('j') | media/filters/audio_renderer_algorithm_base.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698