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 * 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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "public/platform/WebAudioBus.h" | 25 #include "public/platform/WebAudioBus.h" |
26 | 26 |
27 #include "wtf/build_config.h" | 27 #include "wtf/build_config.h" |
28 | 28 |
29 #if ENABLE(WEB_AUDIO) | |
30 #include "platform/audio/AudioBus.h" | 29 #include "platform/audio/AudioBus.h" |
31 #else | |
32 #include "wtf/ThreadSafeRefCounted.h" | |
33 | |
34 namespace blink { | |
35 class AudioBus : public ThreadSafeRefCounted<AudioBus> { | |
36 }; | |
37 } // namespace blink | |
38 #endif | |
39 | |
40 #include "wtf/PassRefPtr.h" | 30 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefPtr.h" | 31 #include "wtf/RefPtr.h" |
42 | 32 |
43 namespace blink { | 33 namespace blink { |
44 | 34 |
45 class WebAudioBusPrivate : public AudioBus { | 35 class WebAudioBusPrivate : public AudioBus { |
46 }; | 36 }; |
47 | 37 |
48 void WebAudioBus::initialize(unsigned numberOfChannels, size_t length, double sa
mpleRate) | 38 void WebAudioBus::initialize(unsigned numberOfChannels, size_t length, double sa
mpleRate) |
49 { | 39 { |
50 #if ENABLE(WEB_AUDIO) | |
51 RefPtr<AudioBus> audioBus = AudioBus::create(numberOfChannels, length); | 40 RefPtr<AudioBus> audioBus = AudioBus::create(numberOfChannels, length); |
52 audioBus->setSampleRate(sampleRate); | 41 audioBus->setSampleRate(sampleRate); |
53 | 42 |
54 if (m_private) | 43 if (m_private) |
55 (static_cast<AudioBus*>(m_private))->deref(); | 44 (static_cast<AudioBus*>(m_private))->deref(); |
56 | 45 |
57 audioBus->ref(); | 46 audioBus->ref(); |
58 m_private = static_cast<WebAudioBusPrivate*>(audioBus.get()); | 47 m_private = static_cast<WebAudioBusPrivate*>(audioBus.get()); |
59 #else | |
60 ASSERT_NOT_REACHED(); | |
61 #endif | |
62 } | 48 } |
63 | 49 |
64 void WebAudioBus::resizeSmaller(size_t newLength) | 50 void WebAudioBus::resizeSmaller(size_t newLength) |
65 { | 51 { |
66 #if ENABLE(WEB_AUDIO) | |
67 ASSERT(m_private); | 52 ASSERT(m_private); |
68 if (m_private) { | 53 if (m_private) { |
69 ASSERT(newLength <= length()); | 54 ASSERT(newLength <= length()); |
70 m_private->resizeSmaller(newLength); | 55 m_private->resizeSmaller(newLength); |
71 } | 56 } |
72 #else | |
73 ASSERT_NOT_REACHED(); | |
74 #endif | |
75 } | 57 } |
76 | 58 |
77 void WebAudioBus::reset() | 59 void WebAudioBus::reset() |
78 { | 60 { |
79 #if ENABLE(WEB_AUDIO) | |
80 if (m_private) { | 61 if (m_private) { |
81 (static_cast<AudioBus*>(m_private))->deref(); | 62 (static_cast<AudioBus*>(m_private))->deref(); |
82 m_private = 0; | 63 m_private = 0; |
83 } | 64 } |
84 #else | |
85 ASSERT_NOT_REACHED(); | |
86 #endif | |
87 } | 65 } |
88 | 66 |
89 unsigned WebAudioBus::numberOfChannels() const | 67 unsigned WebAudioBus::numberOfChannels() const |
90 { | 68 { |
91 #if ENABLE(WEB_AUDIO) | |
92 if (!m_private) | 69 if (!m_private) |
93 return 0; | 70 return 0; |
94 return m_private->numberOfChannels(); | 71 return m_private->numberOfChannels(); |
95 #else | |
96 ASSERT_NOT_REACHED(); | |
97 return 0; | |
98 #endif | |
99 } | 72 } |
100 | 73 |
101 size_t WebAudioBus::length() const | 74 size_t WebAudioBus::length() const |
102 { | 75 { |
103 #if ENABLE(WEB_AUDIO) | |
104 if (!m_private) | 76 if (!m_private) |
105 return 0; | 77 return 0; |
106 return m_private->length(); | 78 return m_private->length(); |
107 #else | |
108 ASSERT_NOT_REACHED(); | |
109 return 0; | |
110 #endif | |
111 } | 79 } |
112 | 80 |
113 double WebAudioBus::sampleRate() const | 81 double WebAudioBus::sampleRate() const |
114 { | 82 { |
115 #if ENABLE(WEB_AUDIO) | |
116 if (!m_private) | 83 if (!m_private) |
117 return 0; | 84 return 0; |
118 return m_private->sampleRate(); | 85 return m_private->sampleRate(); |
119 #else | |
120 ASSERT_NOT_REACHED(); | |
121 return 0; | |
122 #endif | |
123 } | 86 } |
124 | 87 |
125 float* WebAudioBus::channelData(unsigned channelIndex) | 88 float* WebAudioBus::channelData(unsigned channelIndex) |
126 { | 89 { |
127 #if ENABLE(WEB_AUDIO) | |
128 if (!m_private) | 90 if (!m_private) |
129 return 0; | 91 return 0; |
130 ASSERT(channelIndex < numberOfChannels()); | 92 ASSERT(channelIndex < numberOfChannels()); |
131 return m_private->channel(channelIndex)->mutableData(); | 93 return m_private->channel(channelIndex)->mutableData(); |
132 #else | |
133 ASSERT_NOT_REACHED(); | |
134 return 0; | |
135 #endif | |
136 } | 94 } |
137 | 95 |
138 PassRefPtr<AudioBus> WebAudioBus::release() | 96 PassRefPtr<AudioBus> WebAudioBus::release() |
139 { | 97 { |
140 #if ENABLE(WEB_AUDIO) | |
141 RefPtr<AudioBus> audioBus(adoptRef(static_cast<AudioBus*>(m_private))); | 98 RefPtr<AudioBus> audioBus(adoptRef(static_cast<AudioBus*>(m_private))); |
142 m_private = 0; | 99 m_private = 0; |
143 return audioBus; | 100 return audioBus; |
144 #else | |
145 ASSERT_NOT_REACHED(); | |
146 return nullptr; | |
147 #endif | |
148 } | 101 } |
149 | 102 |
150 } // namespace blink | 103 } // namespace blink |
OLD | NEW |