| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) | 60 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) |
| 61 : m_gain(1.0) | 61 : m_gain(1.0) |
| 62 , m_sampleRate(sampleRate) | 62 , m_sampleRate(sampleRate) |
| 63 , m_length(numberOfFrames) | 63 , m_length(numberOfFrames) |
| 64 { | 64 { |
| 65 ScriptWrappable::init(this); | 65 ScriptWrappable::init(this); |
| 66 m_channels.reserveCapacity(numberOfChannels); | 66 m_channels.reserveCapacity(numberOfChannels); |
| 67 | 67 |
| 68 for (unsigned i = 0; i < numberOfChannels; ++i) { | 68 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 69 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); | 69 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); |
| 70 channelDataArray->setNeuterable(false); |
| 70 m_channels.append(channelDataArray); | 71 m_channels.append(channelDataArray); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 AudioBuffer::AudioBuffer(AudioBus* bus) | 75 AudioBuffer::AudioBuffer(AudioBus* bus) |
| 75 : m_gain(1.0) | 76 : m_gain(1.0) |
| 76 , m_sampleRate(bus->sampleRate()) | 77 , m_sampleRate(bus->sampleRate()) |
| 77 , m_length(bus->length()) | 78 , m_length(bus->length()) |
| 78 { | 79 { |
| 79 ScriptWrappable::init(this); | 80 ScriptWrappable::init(this); |
| 80 // Copy audio data from the bus to the Float32Arrays we manage. | 81 // Copy audio data from the bus to the Float32Arrays we manage. |
| 81 unsigned numberOfChannels = bus->numberOfChannels(); | 82 unsigned numberOfChannels = bus->numberOfChannels(); |
| 82 m_channels.reserveCapacity(numberOfChannels); | 83 m_channels.reserveCapacity(numberOfChannels); |
| 83 for (unsigned i = 0; i < numberOfChannels; ++i) { | 84 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 84 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); | 85 RefPtr<Float32Array> channelDataArray = Float32Array::create(m_length); |
| 86 channelDataArray->setNeuterable(false); |
| 85 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); | 87 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); |
| 86 m_channels.append(channelDataArray); | 88 m_channels.append(channelDataArray); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 | 91 |
| 90 void AudioBuffer::releaseMemory() | 92 void AudioBuffer::releaseMemory() |
| 91 { | 93 { |
| 92 m_channels.clear(); | 94 m_channels.clear(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex, ExceptionState&
es) | 97 PassRefPtr<Float32Array> AudioBuffer::getChannelData(unsigned channelIndex, Exce
ptionState& es) |
| 96 { | 98 { |
| 97 if (channelIndex >= m_channels.size()) { | 99 if (channelIndex >= m_channels.size()) { |
| 98 es.throwDOMException(SyntaxError); | 100 es.throwDOMException(SyntaxError); |
| 99 return 0; | 101 return 0; |
| 100 } | 102 } |
| 101 | 103 |
| 102 return m_channels[channelIndex].get(); | 104 Float32Array* channelData = m_channels[channelIndex].get(); |
| 105 return Float32Array::create(channelData->buffer(), channelData->byteOffset()
, channelData->length()); |
| 103 } | 106 } |
| 104 | 107 |
| 105 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex) | 108 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex) |
| 106 { | 109 { |
| 107 if (channelIndex >= m_channels.size()) | 110 if (channelIndex >= m_channels.size()) |
| 108 return 0; | 111 return 0; |
| 109 | 112 |
| 110 return m_channels[channelIndex].get(); | 113 return m_channels[channelIndex].get(); |
| 111 } | 114 } |
| 112 | 115 |
| 113 void AudioBuffer::zero() | 116 void AudioBuffer::zero() |
| 114 { | 117 { |
| 115 for (unsigned i = 0; i < m_channels.size(); ++i) { | 118 for (unsigned i = 0; i < m_channels.size(); ++i) { |
| 116 if (getChannelData(i)) | 119 if (getChannelData(i)) |
| 117 getChannelData(i)->zeroRange(0, length()); | 120 getChannelData(i)->zeroRange(0, length()); |
| 118 } | 121 } |
| 119 } | 122 } |
| 120 | 123 |
| 121 } // namespace WebCore | 124 } // namespace WebCore |
| 122 | 125 |
| 123 #endif // ENABLE(WEB_AUDIO) | 126 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |