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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 float AudioBuffer::maxAllowedSampleRate() | 48 float AudioBuffer::maxAllowedSampleRate() |
49 { | 49 { |
50 return 96000; | 50 return 96000; |
51 } | 51 } |
52 | 52 |
53 PassRefPtr<AudioBuffer> AudioBuffer::create(unsigned numberOfChannels, size_t nu
mberOfFrames, float sampleRate) | 53 PassRefPtr<AudioBuffer> AudioBuffer::create(unsigned numberOfChannels, size_t nu
mberOfFrames, float sampleRate) |
54 { | 54 { |
55 if (sampleRate < minAllowedSampleRate() || sampleRate > maxAllowedSampleRate
() || numberOfChannels > AudioContext::maxNumberOfChannels() || !numberOfFrames) | 55 if (sampleRate < minAllowedSampleRate() || sampleRate > maxAllowedSampleRate
() || numberOfChannels > AudioContext::maxNumberOfChannels() || !numberOfFrames) |
56 return 0; | 56 return nullptr; |
57 | 57 |
58 RefPtr<AudioBuffer> buffer = adoptRef(new AudioBuffer(numberOfChannels, numb
erOfFrames, sampleRate)); | 58 RefPtr<AudioBuffer> buffer = adoptRef(new AudioBuffer(numberOfChannels, numb
erOfFrames, sampleRate)); |
59 | 59 |
60 if (!buffer->createdSuccessfully(numberOfChannels)) | 60 if (!buffer->createdSuccessfully(numberOfChannels)) |
61 return 0; | 61 return nullptr; |
62 return buffer; | 62 return buffer; |
63 } | 63 } |
64 | 64 |
65 PassRefPtr<AudioBuffer> AudioBuffer::createFromAudioFileData(const void* data, s
ize_t dataSize, bool mixToMono, float sampleRate) | 65 PassRefPtr<AudioBuffer> AudioBuffer::createFromAudioFileData(const void* data, s
ize_t dataSize, bool mixToMono, float sampleRate) |
66 { | 66 { |
67 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM
ono, sampleRate); | 67 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM
ono, sampleRate); |
68 if (bus.get()) { | 68 if (bus.get()) { |
69 RefPtr<AudioBuffer> buffer = adoptRef(new AudioBuffer(bus.get())); | 69 RefPtr<AudioBuffer> buffer = adoptRef(new AudioBuffer(bus.get())); |
70 if (buffer->createdSuccessfully(bus->numberOfChannels())) | 70 if (buffer->createdSuccessfully(bus->numberOfChannels())) |
71 return buffer; | 71 return buffer; |
72 } | 72 } |
73 | 73 |
74 return 0; | 74 return nullptr; |
75 } | 75 } |
76 | 76 |
77 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const | 77 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const |
78 { | 78 { |
79 return numberOfChannels() == desiredNumberOfChannels; | 79 return numberOfChannels() == desiredNumberOfChannels; |
80 } | 80 } |
81 | 81 |
82 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) | 82 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) |
83 : m_gain(1.0) | 83 : m_gain(1.0) |
84 , m_sampleRate(sampleRate) | 84 , m_sampleRate(sampleRate) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 channelDataArray->setNeuterable(false); | 119 channelDataArray->setNeuterable(false); |
120 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); | 120 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); |
121 m_channels.append(channelDataArray); | 121 m_channels.append(channelDataArray); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 PassRefPtr<Float32Array> AudioBuffer::getChannelData(unsigned channelIndex, Exce
ptionState& exceptionState) | 125 PassRefPtr<Float32Array> AudioBuffer::getChannelData(unsigned channelIndex, Exce
ptionState& exceptionState) |
126 { | 126 { |
127 if (channelIndex >= m_channels.size()) { | 127 if (channelIndex >= m_channels.size()) { |
128 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str
ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_
channels.size()) + ")"); | 128 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str
ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_
channels.size()) + ")"); |
129 return 0; | 129 return nullptr; |
130 } | 130 } |
131 | 131 |
132 Float32Array* channelData = m_channels[channelIndex].get(); | 132 Float32Array* channelData = m_channels[channelIndex].get(); |
133 return Float32Array::create(channelData->buffer(), channelData->byteOffset()
, channelData->length()); | 133 return Float32Array::create(channelData->buffer(), channelData->byteOffset()
, channelData->length()); |
134 } | 134 } |
135 | 135 |
136 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex) | 136 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex) |
137 { | 137 { |
138 if (channelIndex >= m_channels.size()) | 138 if (channelIndex >= m_channels.size()) |
139 return 0; | 139 return 0; |
140 | 140 |
141 return m_channels[channelIndex].get(); | 141 return m_channels[channelIndex].get(); |
142 } | 142 } |
143 | 143 |
144 void AudioBuffer::zero() | 144 void AudioBuffer::zero() |
145 { | 145 { |
146 for (unsigned i = 0; i < m_channels.size(); ++i) { | 146 for (unsigned i = 0; i < m_channels.size(); ++i) { |
147 if (getChannelData(i)) | 147 if (getChannelData(i)) |
148 getChannelData(i)->zeroRange(0, length()); | 148 getChannelData(i)->zeroRange(0, length()); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 } // namespace WebCore | 152 } // namespace WebCore |
153 | 153 |
154 #endif // ENABLE(WEB_AUDIO) | 154 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |