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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp

Issue 2102133002: Add constructors for WebAudio nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and prefix use counter names with WebAudio Created 4 years, 3 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 13 matching lines...) Expand all
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "modules/webaudio/AudioBuffer.h" 29 #include "modules/webaudio/AudioBuffer.h"
30 30
31 #include "bindings/core/v8/ExceptionMessages.h" 31 #include "bindings/core/v8/ExceptionMessages.h"
32 #include "bindings/core/v8/ExceptionState.h" 32 #include "bindings/core/v8/ExceptionState.h"
33 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
34 #include "modules/webaudio/AudioBufferOptions.h"
34 #include "modules/webaudio/BaseAudioContext.h" 35 #include "modules/webaudio/BaseAudioContext.h"
35 #include "platform/audio/AudioBus.h" 36 #include "platform/audio/AudioBus.h"
36 #include "platform/audio/AudioFileReader.h" 37 #include "platform/audio/AudioFileReader.h"
37 #include "platform/audio/AudioUtilities.h" 38 #include "platform/audio/AudioUtilities.h"
38 #include "wtf/typed_arrays/Float32Array.h" 39 #include "wtf/typed_arrays/Float32Array.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate) 43 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate)
43 { 44 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 "createBuffer(" 98 "createBuffer("
98 + String::number(numberOfChannels) + ", " 99 + String::number(numberOfChannels) + ", "
99 + String::number(numberOfFrames) + ", " 100 + String::number(numberOfFrames) + ", "
100 + String::number(sampleRate) 101 + String::number(sampleRate)
101 + ") failed."); 102 + ") failed.");
102 } 103 }
103 104
104 return audioBuffer; 105 return audioBuffer;
105 } 106 }
106 107
108 AudioBuffer* AudioBuffer::create(BaseAudioContext* context, const AudioBufferOpt ions& options, ExceptionState& exceptionState)
109 {
110 unsigned numberOfChannels;
111 size_t numberOfFrames;
112 float sampleRate;
113
114 if (!options.hasNumberOfChannels()) {
115 exceptionState.throwDOMException(
116 NotFoundError,
117 "AudioBufferOptions: numberOfChannels is required.");
118 return nullptr;
119 }
120
121 if (!options.hasLength()) {
122 exceptionState.throwDOMException(
123 NotFoundError,
124 "AudioBufferOptions: length is required.");
125 return nullptr;
126 }
127
128 numberOfChannels = options.numberOfChannels();
129 numberOfFrames = options.length();
130
131 if (options.hasSampleRate())
132 sampleRate = options.sampleRate();
133 else
134 sampleRate = context->sampleRate();
135
136 return create(numberOfChannels, numberOfFrames, sampleRate, exceptionState);
137 }
138
107 AudioBuffer* AudioBuffer::createFromAudioFileData(const void* data, size_t dataS ize, bool mixToMono, float sampleRate) 139 AudioBuffer* AudioBuffer::createFromAudioFileData(const void* data, size_t dataS ize, bool mixToMono, float sampleRate)
108 { 140 {
109 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM ono, sampleRate); 141 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM ono, sampleRate);
110 if (bus) { 142 if (bus) {
111 AudioBuffer* buffer = new AudioBuffer(bus.get()); 143 AudioBuffer* buffer = new AudioBuffer(bus.get());
112 if (buffer->createdSuccessfully(bus->numberOfChannels())) 144 if (buffer->createdSuccessfully(bus->numberOfChannels()))
113 return buffer; 145 return buffer;
114 } 146 }
115 147
116 return nullptr; 148 return nullptr;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 for (unsigned i = 0; i < m_channels.size(); ++i) { 330 for (unsigned i = 0; i < m_channels.size(); ++i) {
299 if (DOMFloat32Array* array = getChannelData(i)) { 331 if (DOMFloat32Array* array = getChannelData(i)) {
300 float* data = array->data(); 332 float* data = array->data();
301 memset(data, 0, length() * sizeof(*data)); 333 memset(data, 0, length() * sizeof(*data));
302 } 334 }
303 } 335 }
304 } 336 }
305 337
306 } // namespace blink 338 } // namespace blink
307 339
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioBuffer.h ('k') | third_party/WebKit/Source/modules/webaudio/AudioBuffer.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698