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

Side by Side Diff: Source/modules/webaudio/ConvolverNode.cpp

Issue 14628008: Require use of AudioBus::create() to avoid ref-counting issues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Require use of Created 7 years, 7 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 * 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 size_t bufferLength = buffer->length(); 125 size_t bufferLength = buffer->length();
126 126
127 // The current implementation supports up to four channel impulse responses, which are interpreted as true-stereo (see Reverb class). 127 // The current implementation supports up to four channel impulse responses, which are interpreted as true-stereo (see Reverb class).
128 bool isBufferGood = numberOfChannels > 0 && numberOfChannels <= 4 && bufferL ength; 128 bool isBufferGood = numberOfChannels > 0 && numberOfChannels <= 4 && bufferL ength;
129 ASSERT(isBufferGood); 129 ASSERT(isBufferGood);
130 if (!isBufferGood) 130 if (!isBufferGood)
131 return; 131 return;
132 132
133 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no t a memcpy(). 133 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no t a memcpy().
134 // This memory is simply used in the Reverb constructor and no reference to it is kept for later use in that class. 134 // This memory is simply used in the Reverb constructor and no reference to it is kept for later use in that class.
135 AudioBus bufferBus(numberOfChannels, bufferLength, false); 135 RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength , false);
136 for (unsigned i = 0; i < numberOfChannels; ++i) 136 for (unsigned i = 0; i < numberOfChannels; ++i)
137 bufferBus.setChannelMemory(i, buffer->getChannelData(i)->data(), bufferL ength); 137 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer Length);
138 138
139 bufferBus.setSampleRate(buffer->sampleRate()); 139 bufferBus->setSampleRate(buffer->sampleRate());
140 140
141 // Create the reverb with the given impulse response. 141 // Create the reverb with the given impulse response.
142 bool useBackgroundThreads = !context()->isOfflineContext(); 142 bool useBackgroundThreads = !context()->isOfflineContext();
143 OwnPtr<Reverb> reverb = adoptPtr(new Reverb(&bufferBus, AudioNode::Processin gSizeInFrames, MaxFFTSize, 2, useBackgroundThreads, m_normalize)); 143 OwnPtr<Reverb> reverb = adoptPtr(new Reverb(bufferBus.get(), AudioNode::Proc essingSizeInFrames, MaxFFTSize, 2, useBackgroundThreads, m_normalize));
144 144
145 { 145 {
146 // Synchronize with process(). 146 // Synchronize with process().
147 MutexLocker locker(m_processLock); 147 MutexLocker locker(m_processLock);
148 m_reverb = reverb.release(); 148 m_reverb = reverb.release();
149 m_buffer = buffer; 149 m_buffer = buffer;
150 } 150 }
151 } 151 }
152 152
153 AudioBuffer* ConvolverNode::buffer() 153 AudioBuffer* ConvolverNode::buffer()
154 { 154 {
155 ASSERT(isMainThread()); 155 ASSERT(isMainThread());
156 return m_buffer.get(); 156 return m_buffer.get();
157 } 157 }
158 158
159 double ConvolverNode::tailTime() const 159 double ConvolverNode::tailTime() const
160 { 160 {
161 return m_reverb ? m_reverb->impulseResponseLength() / static_cast<double>(sa mpleRate()) : 0; 161 return m_reverb ? m_reverb->impulseResponseLength() / static_cast<double>(sa mpleRate()) : 0;
162 } 162 }
163 163
164 double ConvolverNode::latencyTime() const 164 double ConvolverNode::latencyTime() const
165 { 165 {
166 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sampleRate ()) : 0; 166 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sampleRate ()) : 0;
167 } 167 }
168 168
169 } // namespace WebCore 169 } // namespace WebCore
170 170
171 #endif // ENABLE(WEB_AUDIO) 171 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioParam.cpp ('k') | Source/modules/webaudio/MediaStreamAudioDestinationNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698