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

Side by Side Diff: Source/platform/audio/AudioDestination.cpp

Issue 458313005: Cleanup namespace usage from animation to exported in platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Cleanup namespace usage from animation to exported in platform/ Created 6 years, 4 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 /* 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 AudioDestination::AudioDestination(AudioIOCallback& callback, const String& inpu tDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, floa t sampleRate) 53 AudioDestination::AudioDestination(AudioIOCallback& callback, const String& inpu tDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, floa t sampleRate)
54 : m_callback(callback) 54 : m_callback(callback)
55 , m_numberOfOutputChannels(numberOfOutputChannels) 55 , m_numberOfOutputChannels(numberOfOutputChannels)
56 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)) 56 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize))
57 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal se)) 57 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal se))
58 , m_sampleRate(sampleRate) 58 , m_sampleRate(sampleRate)
59 , m_isPlaying(false) 59 , m_isPlaying(false)
60 { 60 {
61 // Use the optimal buffer size recommended by the audio backend. 61 // Use the optimal buffer size recommended by the audio backend.
62 m_callbackBufferSize = blink::Platform::current()->audioHardwareBufferSize() ; 62 m_callbackBufferSize = Platform::current()->audioHardwareBufferSize();
63 63
64 #if OS(ANDROID) 64 #if OS(ANDROID)
65 // The optimum low-latency hardware buffer size is usually too small on Andr oid for WebAudio to 65 // The optimum low-latency hardware buffer size is usually too small on Andr oid for WebAudio to
66 // render without glitching. So, if it is small, use a larger size. If it wa s already large, use 66 // render without glitching. So, if it is small, use a larger size. If it wa s already large, use
67 // the requested size. 67 // the requested size.
68 // 68 //
69 // Since WebAudio renders in 128-frame blocks, the small buffer sizes (144 f or a Galaxy Nexus), 69 // Since WebAudio renders in 128-frame blocks, the small buffer sizes (144 f or a Galaxy Nexus),
70 // cause significant processing jitter. Sometimes multiple blocks will proce ssed, but other 70 // cause significant processing jitter. Sometimes multiple blocks will proce ssed, but other
71 // times will not be since the FIFO can satisfy the request. By using a larg er 71 // times will not be since the FIFO can satisfy the request. By using a larg er
72 // callbackBufferSize, we smooth out the jitter. 72 // callbackBufferSize, we smooth out the jitter.
73 const size_t kSmallBufferSize = 1024; 73 const size_t kSmallBufferSize = 1024;
74 const size_t kDefaultCallbackBufferSize = 2048; 74 const size_t kDefaultCallbackBufferSize = 2048;
75 75
76 if (m_callbackBufferSize <= kSmallBufferSize) 76 if (m_callbackBufferSize <= kSmallBufferSize)
77 m_callbackBufferSize = kDefaultCallbackBufferSize; 77 m_callbackBufferSize = kDefaultCallbackBufferSize;
78 #endif 78 #endif
79 79
80 // Quick exit if the requested size is too large. 80 // Quick exit if the requested size is too large.
81 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize); 81 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize);
82 if (m_callbackBufferSize + renderBufferSize > fifoSize) 82 if (m_callbackBufferSize + renderBufferSize > fifoSize)
83 return; 83 return;
84 84
85 m_audioDevice = adoptPtr(blink::Platform::current()->createAudioDevice(m_cal lbackBufferSize, numberOfInputChannels, numberOfOutputChannels, sampleRate, this , inputDeviceId)); 85 m_audioDevice = adoptPtr(Platform::current()->createAudioDevice(m_callbackBu fferSize, numberOfInputChannels, numberOfOutputChannels, sampleRate, this, input DeviceId));
86 ASSERT(m_audioDevice); 86 ASSERT(m_audioDevice);
87 87
88 // Create a FIFO to handle the possibility of the callback size 88 // Create a FIFO to handle the possibility of the callback size
89 // not being a multiple of the render size. If the FIFO already 89 // not being a multiple of the render size. If the FIFO already
90 // contains enough data, the data will be provided directly. 90 // contains enough data, the data will be provided directly.
91 // Otherwise, the FIFO will call the provider enough times to 91 // Otherwise, the FIFO will call the provider enough times to
92 // satisfy the request for data. 92 // satisfy the request for data.
93 m_fifo = adoptPtr(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize, renderBufferSize)); 93 m_fifo = adoptPtr(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize, renderBufferSize));
94 94
95 // Input buffering. 95 // Input buffering.
(...skipping 24 matching lines...) Expand all
120 void AudioDestination::stop() 120 void AudioDestination::stop()
121 { 121 {
122 if (m_isPlaying && m_audioDevice) { 122 if (m_isPlaying && m_audioDevice) {
123 m_audioDevice->stop(); 123 m_audioDevice->stop();
124 m_isPlaying = false; 124 m_isPlaying = false;
125 } 125 }
126 } 126 }
127 127
128 float AudioDestination::hardwareSampleRate() 128 float AudioDestination::hardwareSampleRate()
129 { 129 {
130 return static_cast<float>(blink::Platform::current()->audioHardwareSampleRat e()); 130 return static_cast<float>(Platform::current()->audioHardwareSampleRate());
131 } 131 }
132 132
133 unsigned long AudioDestination::maxChannelCount() 133 unsigned long AudioDestination::maxChannelCount()
134 { 134 {
135 return static_cast<float>(blink::Platform::current()->audioHardwareOutputCha nnels()); 135 return static_cast<float>(Platform::current()->audioHardwareOutputChannels() );
136 } 136 }
137 137
138 void AudioDestination::render(const blink::WebVector<float*>& sourceData, const blink::WebVector<float*>& audioData, size_t numberOfFrames) 138 void AudioDestination::render(const WebVector<float*>& sourceData, const WebVect or<float*>& audioData, size_t numberOfFrames)
139 { 139 {
140 bool isNumberOfChannelsGood = audioData.size() == m_numberOfOutputChannels; 140 bool isNumberOfChannelsGood = audioData.size() == m_numberOfOutputChannels;
141 if (!isNumberOfChannelsGood) { 141 if (!isNumberOfChannelsGood) {
142 ASSERT_NOT_REACHED(); 142 ASSERT_NOT_REACHED();
143 return; 143 return;
144 } 144 }
145 145
146 bool isBufferSizeGood = numberOfFrames == m_callbackBufferSize; 146 bool isBufferSizeGood = numberOfFrames == m_callbackBufferSize;
147 if (!isBufferSizeGood) { 147 if (!isBufferSizeGood) {
148 ASSERT_NOT_REACHED(); 148 ASSERT_NOT_REACHED();
(...skipping 22 matching lines...) Expand all
171 m_inputFifo->consume(m_inputBus.get(), framesToProcess); 171 m_inputFifo->consume(m_inputBus.get(), framesToProcess);
172 sourceBus = m_inputBus.get(); 172 sourceBus = m_inputBus.get();
173 } 173 }
174 174
175 m_callback.render(sourceBus, bus, framesToProcess); 175 m_callback.render(sourceBus, bus, framesToProcess);
176 } 176 }
177 177
178 } // namespace blink 178 } // namespace blink
179 179
180 #endif // ENABLE(WEB_AUDIO) 180 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/platform/audio/AudioDestination.h ('k') | Source/platform/audio/AudioDestinationConsumer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698