OLD | NEW |
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const | 143 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const |
144 { | 144 { |
145 return numberOfChannels() == desiredNumberOfChannels; | 145 return numberOfChannels() == desiredNumberOfChannels; |
146 } | 146 } |
147 | 147 |
148 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) | 148 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) |
149 : m_sampleRate(sampleRate) | 149 : m_sampleRate(sampleRate) |
150 , m_length(numberOfFrames) | 150 , m_length(numberOfFrames) |
151 { | 151 { |
152 ScriptWrappable::init(this); | |
153 m_channels.reserveCapacity(numberOfChannels); | 152 m_channels.reserveCapacity(numberOfChannels); |
154 | 153 |
155 for (unsigned i = 0; i < numberOfChannels; ++i) { | 154 for (unsigned i = 0; i < numberOfChannels; ++i) { |
156 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); | 155 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); |
157 // If the channel data array could not be created, just return. The call
er will need to | 156 // If the channel data array could not be created, just return. The call
er will need to |
158 // check that the desired number of channels were created. | 157 // check that the desired number of channels were created. |
159 if (!channelDataArray) { | 158 if (!channelDataArray) { |
160 return; | 159 return; |
161 } | 160 } |
162 | 161 |
163 channelDataArray->setNeuterable(false); | 162 channelDataArray->setNeuterable(false); |
164 m_channels.append(channelDataArray); | 163 m_channels.append(channelDataArray); |
165 } | 164 } |
166 } | 165 } |
167 | 166 |
168 AudioBuffer::AudioBuffer(AudioBus* bus) | 167 AudioBuffer::AudioBuffer(AudioBus* bus) |
169 : m_sampleRate(bus->sampleRate()) | 168 : m_sampleRate(bus->sampleRate()) |
170 , m_length(bus->length()) | 169 , m_length(bus->length()) |
171 { | 170 { |
172 ScriptWrappable::init(this); | |
173 // Copy audio data from the bus to the Float32Arrays we manage. | 171 // Copy audio data from the bus to the Float32Arrays we manage. |
174 unsigned numberOfChannels = bus->numberOfChannels(); | 172 unsigned numberOfChannels = bus->numberOfChannels(); |
175 m_channels.reserveCapacity(numberOfChannels); | 173 m_channels.reserveCapacity(numberOfChannels); |
176 for (unsigned i = 0; i < numberOfChannels; ++i) { | 174 for (unsigned i = 0; i < numberOfChannels; ++i) { |
177 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); | 175 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); |
178 // If the channel data array could not be created, just return. The call
er will need to | 176 // If the channel data array could not be created, just return. The call
er will need to |
179 // check that the desired number of channels were created. | 177 // check that the desired number of channels were created. |
180 if (!channelDataArray) | 178 if (!channelDataArray) |
181 return; | 179 return; |
182 | 180 |
(...skipping 26 matching lines...) Expand all Loading... |
209 { | 207 { |
210 for (unsigned i = 0; i < m_channels.size(); ++i) { | 208 for (unsigned i = 0; i < m_channels.size(); ++i) { |
211 if (getChannelData(i)) | 209 if (getChannelData(i)) |
212 getChannelData(i)->zeroRange(0, length()); | 210 getChannelData(i)->zeroRange(0, length()); |
213 } | 211 } |
214 } | 212 } |
215 | 213 |
216 } // namespace blink | 214 } // namespace blink |
217 | 215 |
218 #endif // ENABLE(WEB_AUDIO) | 216 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |