| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 float AudioBuffer::minAllowedSampleRate() | 43 float AudioBuffer::minAllowedSampleRate() |
| 44 { | 44 { |
| 45 return 22050; | 45 return 22050; |
| 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 PassRefPtrWillBeRawPtr<AudioBuffer> AudioBuffer::create(unsigned numberOfChannel
s, size_t numberOfFrames, 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 nullptr; | 56 return nullptr; |
| 57 | 57 |
| 58 RefPtr<AudioBuffer> buffer = adoptRef(new AudioBuffer(numberOfChannels, numb
erOfFrames, sampleRate)); | 58 RefPtrWillBeRawPtr<AudioBuffer> buffer = adoptRefWillBeNoop(new AudioBuffer(
numberOfChannels, numberOfFrames, sampleRate)); |
| 59 | 59 |
| 60 if (!buffer->createdSuccessfully(numberOfChannels)) | 60 if (!buffer->createdSuccessfully(numberOfChannels)) |
| 61 return nullptr; | 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 PassRefPtrWillBeRawPtr<AudioBuffer> AudioBuffer::createFromAudioFileData(const v
oid* data, size_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 RefPtrWillBeRawPtr<AudioBuffer> buffer = adoptRefWillBeNoop(new AudioBuf
fer(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 nullptr; | 74 return nullptr; |
| 75 } | 75 } |
| 76 | 76 |
| 77 PassRefPtrWillBeRawPtr<AudioBuffer> AudioBuffer::createFromAudioBus(AudioBus* bu
s) |
| 78 { |
| 79 if (!bus) |
| 80 return nullptr; |
| 81 RefPtrWillBeRawPtr<AudioBuffer> buffer = adoptRefWillBeNoop(new AudioBuffer(
bus)); |
| 82 if (buffer->createdSuccessfully(bus->numberOfChannels())) |
| 83 return buffer; |
| 84 return nullptr; |
| 85 } |
| 86 |
| 77 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const | 87 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const |
| 78 { | 88 { |
| 79 return numberOfChannels() == desiredNumberOfChannels; | 89 return numberOfChannels() == desiredNumberOfChannels; |
| 80 } | 90 } |
| 81 | 91 |
| 82 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) | 92 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) |
| 83 : m_gain(1.0) | 93 : m_gain(1.0) |
| 84 , m_sampleRate(sampleRate) | 94 , m_sampleRate(sampleRate) |
| 85 , m_length(numberOfFrames) | 95 , m_length(numberOfFrames) |
| 86 { | 96 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 { | 155 { |
| 146 for (unsigned i = 0; i < m_channels.size(); ++i) { | 156 for (unsigned i = 0; i < m_channels.size(); ++i) { |
| 147 if (getChannelData(i)) | 157 if (getChannelData(i)) |
| 148 getChannelData(i)->zeroRange(0, length()); | 158 getChannelData(i)->zeroRange(0, length()); |
| 149 } | 159 } |
| 150 } | 160 } |
| 151 | 161 |
| 152 } // namespace WebCore | 162 } // namespace WebCore |
| 153 | 163 |
| 154 #endif // ENABLE(WEB_AUDIO) | 164 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |