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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 | 30 |
31 #if ENABLE(WEB_AUDIO) | 31 #if ENABLE(WEB_AUDIO) |
32 | 32 |
33 #include "modules/webaudio/AudioBuffer.h" | 33 #include "modules/webaudio/AudioBuffer.h" |
34 | 34 |
35 #include "bindings/core/v8/ExceptionMessages.h" | 35 #include "bindings/core/v8/ExceptionMessages.h" |
36 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
37 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
| 38 #include "modules/webaudio/AudioContext.h" |
38 #include "platform/audio/AudioBus.h" | 39 #include "platform/audio/AudioBus.h" |
39 #include "platform/audio/AudioFileReader.h" | 40 #include "platform/audio/AudioFileReader.h" |
40 #include "modules/webaudio/AudioContext.h" | 41 #include "platform/audio/AudioUtilities.h" |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 float AudioBuffer::minAllowedSampleRate() | |
45 { | |
46 // crbug.com/344375 | |
47 return 3000; | |
48 } | |
49 | |
50 float AudioBuffer::maxAllowedSampleRate() | |
51 { | |
52 // Windows can support up to this rate. | |
53 return 192000; | |
54 } | |
55 | |
56 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
s, float sampleRate) | 45 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
s, float sampleRate) |
57 { | 46 { |
58 if (sampleRate < minAllowedSampleRate() || sampleRate > maxAllowedSampleRate
() || numberOfChannels > AudioContext::maxNumberOfChannels() || !numberOfChannel
s || !numberOfFrames) | 47 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate) || numberOfCha
nnels > AudioContext::maxNumberOfChannels() || !numberOfChannels || !numberOfFra
mes) |
59 return 0; | 48 return 0; |
60 | 49 |
61 AudioBuffer* buffer = new AudioBuffer(numberOfChannels, numberOfFrames, samp
leRate); | 50 AudioBuffer* buffer = new AudioBuffer(numberOfChannels, numberOfFrames, samp
leRate); |
62 | 51 |
63 if (!buffer->createdSuccessfully(numberOfChannels)) | 52 if (!buffer->createdSuccessfully(numberOfChannels)) |
64 return 0; | 53 return 0; |
65 return buffer; | 54 return buffer; |
66 } | 55 } |
67 | 56 |
68 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
s, float sampleRate, ExceptionState& exceptionState) | 57 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
s, float sampleRate, ExceptionState& exceptionState) |
69 { | 58 { |
70 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannel
s()) { | 59 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannel
s()) { |
71 exceptionState.throwDOMException( | 60 exceptionState.throwDOMException( |
72 NotSupportedError, | 61 NotSupportedError, |
73 ExceptionMessages::indexOutsideRange( | 62 ExceptionMessages::indexOutsideRange( |
74 "number of channels", | 63 "number of channels", |
75 numberOfChannels, | 64 numberOfChannels, |
76 1u, | 65 1u, |
77 ExceptionMessages::InclusiveBound, | 66 ExceptionMessages::InclusiveBound, |
78 AudioContext::maxNumberOfChannels(), | 67 AudioContext::maxNumberOfChannels(), |
79 ExceptionMessages::InclusiveBound)); | 68 ExceptionMessages::InclusiveBound)); |
80 return 0; | 69 return 0; |
81 } | 70 } |
82 | 71 |
83 if (sampleRate < AudioBuffer::minAllowedSampleRate() || sampleRate > AudioBu
ffer::maxAllowedSampleRate()) { | 72 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) { |
84 exceptionState.throwDOMException( | 73 exceptionState.throwDOMException( |
85 NotSupportedError, | 74 NotSupportedError, |
86 ExceptionMessages::indexOutsideRange( | 75 ExceptionMessages::indexOutsideRange( |
87 "sample rate", | 76 "sample rate", |
88 sampleRate, | 77 sampleRate, |
89 AudioBuffer::minAllowedSampleRate(), | 78 AudioUtilities::minAudioBufferSampleRate(), |
90 ExceptionMessages::InclusiveBound, | 79 ExceptionMessages::InclusiveBound, |
91 AudioBuffer::maxAllowedSampleRate(), | 80 AudioUtilities::maxAudioBufferSampleRate(), |
92 ExceptionMessages::InclusiveBound)); | 81 ExceptionMessages::InclusiveBound)); |
93 return 0; | 82 return 0; |
94 } | 83 } |
95 | 84 |
96 if (!numberOfFrames) { | 85 if (!numberOfFrames) { |
97 exceptionState.throwDOMException( | 86 exceptionState.throwDOMException( |
98 NotSupportedError, | 87 NotSupportedError, |
99 ExceptionMessages::indexExceedsMinimumBound( | 88 ExceptionMessages::indexExceedsMinimumBound( |
100 "number of frames", | 89 "number of frames", |
101 numberOfFrames, | 90 numberOfFrames, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 { | 196 { |
208 for (unsigned i = 0; i < m_channels.size(); ++i) { | 197 for (unsigned i = 0; i < m_channels.size(); ++i) { |
209 if (getChannelData(i)) | 198 if (getChannelData(i)) |
210 getChannelData(i)->zeroRange(0, length()); | 199 getChannelData(i)->zeroRange(0, length()); |
211 } | 200 } |
212 } | 201 } |
213 | 202 |
214 } // namespace blink | 203 } // namespace blink |
215 | 204 |
216 #endif // ENABLE(WEB_AUDIO) | 205 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |