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

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

Issue 906233002: Use nullptr instead of 0 in WebAudio (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « no previous file | Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 28 matching lines...) Expand all
39 #include "modules/webaudio/AudioContext.h" 39 #include "modules/webaudio/AudioContext.h"
40 #include "platform/audio/AudioBus.h" 40 #include "platform/audio/AudioBus.h"
41 #include "platform/audio/AudioFileReader.h" 41 #include "platform/audio/AudioFileReader.h"
42 #include "platform/audio/AudioUtilities.h" 42 #include "platform/audio/AudioUtilities.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate) 46 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate)
47 { 47 {
48 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate) || numberOfCha nnels > AudioContext::maxNumberOfChannels() || !numberOfChannels || !numberOfFra mes) 48 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate) || numberOfCha nnels > AudioContext::maxNumberOfChannels() || !numberOfChannels || !numberOfFra mes)
49 return 0; 49 return nullptr;
50 50
51 AudioBuffer* buffer = new AudioBuffer(numberOfChannels, numberOfFrames, samp leRate); 51 AudioBuffer* buffer = new AudioBuffer(numberOfChannels, numberOfFrames, samp leRate);
52 52
53 if (!buffer->createdSuccessfully(numberOfChannels)) 53 if (!buffer->createdSuccessfully(numberOfChannels))
54 return 0; 54 return nullptr;
55 return buffer; 55 return buffer;
56 } 56 }
57 57
58 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate, ExceptionState& exceptionState) 58 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate, ExceptionState& exceptionState)
59 { 59 {
60 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannel s()) { 60 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannel s()) {
61 exceptionState.throwDOMException( 61 exceptionState.throwDOMException(
62 NotSupportedError, 62 NotSupportedError,
63 ExceptionMessages::indexOutsideRange( 63 ExceptionMessages::indexOutsideRange(
64 "number of channels", 64 "number of channels",
65 numberOfChannels, 65 numberOfChannels,
66 1u, 66 1u,
67 ExceptionMessages::InclusiveBound, 67 ExceptionMessages::InclusiveBound,
68 AudioContext::maxNumberOfChannels(), 68 AudioContext::maxNumberOfChannels(),
69 ExceptionMessages::InclusiveBound)); 69 ExceptionMessages::InclusiveBound));
70 return 0; 70 return nullptr;
71 } 71 }
72 72
73 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) { 73 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) {
74 exceptionState.throwDOMException( 74 exceptionState.throwDOMException(
75 NotSupportedError, 75 NotSupportedError,
76 ExceptionMessages::indexOutsideRange( 76 ExceptionMessages::indexOutsideRange(
77 "sample rate", 77 "sample rate",
78 sampleRate, 78 sampleRate,
79 AudioUtilities::minAudioBufferSampleRate(), 79 AudioUtilities::minAudioBufferSampleRate(),
80 ExceptionMessages::InclusiveBound, 80 ExceptionMessages::InclusiveBound,
81 AudioUtilities::maxAudioBufferSampleRate(), 81 AudioUtilities::maxAudioBufferSampleRate(),
82 ExceptionMessages::InclusiveBound)); 82 ExceptionMessages::InclusiveBound));
83 return 0; 83 return nullptr;
84 } 84 }
85 85
86 if (!numberOfFrames) { 86 if (!numberOfFrames) {
87 exceptionState.throwDOMException( 87 exceptionState.throwDOMException(
88 NotSupportedError, 88 NotSupportedError,
89 ExceptionMessages::indexExceedsMinimumBound( 89 ExceptionMessages::indexExceedsMinimumBound(
90 "number of frames", 90 "number of frames",
91 numberOfFrames, 91 numberOfFrames,
92 static_cast<size_t>(0))); 92 static_cast<size_t>(0)));
93 return 0; 93 return nullptr;
94 } 94 }
95 95
96 AudioBuffer* audioBuffer = create(numberOfChannels, numberOfFrames, sampleRa te); 96 AudioBuffer* audioBuffer = create(numberOfChannels, numberOfFrames, sampleRa te);
97 97
98 if (!audioBuffer) { 98 if (!audioBuffer) {
99 exceptionState.throwDOMException( 99 exceptionState.throwDOMException(
100 NotSupportedError, 100 NotSupportedError,
101 "createBuffer(" 101 "createBuffer("
102 + String::number(numberOfChannels) + ", " 102 + String::number(numberOfChannels) + ", "
103 + String::number(numberOfFrames) + ", " 103 + String::number(numberOfFrames) + ", "
104 + String::number(sampleRate) 104 + String::number(sampleRate)
105 + ") failed."); 105 + ") failed.");
106 } 106 }
107 107
108 return audioBuffer; 108 return audioBuffer;
109 } 109 }
110 110
111 AudioBuffer* AudioBuffer::createFromAudioFileData(const void* data, size_t dataS ize, bool mixToMono, float sampleRate) 111 AudioBuffer* AudioBuffer::createFromAudioFileData(const void* data, size_t dataS ize, bool mixToMono, float sampleRate)
112 { 112 {
113 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM ono, sampleRate); 113 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM ono, sampleRate);
114 if (bus.get()) { 114 if (bus.get()) {
115 AudioBuffer* buffer = new AudioBuffer(bus.get()); 115 AudioBuffer* buffer = new AudioBuffer(bus.get());
116 if (buffer->createdSuccessfully(bus->numberOfChannels())) 116 if (buffer->createdSuccessfully(bus->numberOfChannels()))
117 return buffer; 117 return buffer;
118 } 118 }
119 119
120 return 0; 120 return nullptr;
121 } 121 }
122 122
123 AudioBuffer* AudioBuffer::createFromAudioBus(AudioBus* bus) 123 AudioBuffer* AudioBuffer::createFromAudioBus(AudioBus* bus)
124 { 124 {
125 if (!bus) 125 if (!bus)
126 return 0; 126 return nullptr;
127 AudioBuffer* buffer = new AudioBuffer(bus); 127 AudioBuffer* buffer = new AudioBuffer(bus);
128 if (buffer->createdSuccessfully(bus->numberOfChannels())) 128 if (buffer->createdSuccessfully(bus->numberOfChannels()))
129 return buffer; 129 return buffer;
130 return 0; 130 return nullptr;
131 } 131 }
132 132
133 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const 133 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const
134 { 134 {
135 return numberOfChannels() == desiredNumberOfChannels; 135 return numberOfChannels() == desiredNumberOfChannels;
136 } 136 }
137 137
138 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate) 138 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
139 : m_sampleRate(sampleRate) 139 : m_sampleRate(sampleRate)
140 , m_length(numberOfFrames) 140 , m_length(numberOfFrames)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return nullptr; 181 return nullptr;
182 } 182 }
183 183
184 DOMFloat32Array* channelData = m_channels[channelIndex].get(); 184 DOMFloat32Array* channelData = m_channels[channelIndex].get();
185 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse t(), channelData->length()); 185 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse t(), channelData->length());
186 } 186 }
187 187
188 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) 188 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex)
189 { 189 {
190 if (channelIndex >= m_channels.size()) 190 if (channelIndex >= m_channels.size())
191 return 0; 191 return nullptr;
192 192
193 return m_channels[channelIndex].get(); 193 return m_channels[channelIndex].get();
194 } 194 }
195 195
196 void AudioBuffer::zero() 196 void AudioBuffer::zero()
197 { 197 {
198 for (unsigned i = 0; i < m_channels.size(); ++i) { 198 for (unsigned i = 0; i < m_channels.size(); ++i) {
199 if (getChannelData(i)) 199 if (getChannelData(i))
200 getChannelData(i)->zeroRange(0, length()); 200 getChannelData(i)->zeroRange(0, length());
201 } 201 }
(...skipping 12 matching lines...) Expand all
214 for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) { 214 for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) {
215 getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD eallocationObserver::instance()); 215 getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD eallocationObserver::instance());
216 } 216 }
217 } 217 }
218 return wrapper; 218 return wrapper;
219 } 219 }
220 220
221 } // namespace blink 221 } // namespace blink
222 222
223 #endif // ENABLE(WEB_AUDIO) 223 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « no previous file | Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698