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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* context, float sample Rate) | 58 AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* context, float sample Rate) |
59 : AudioScheduledSourceNode(context, sampleRate) | 59 : AudioScheduledSourceNode(context, sampleRate) |
60 , m_buffer(nullptr) | 60 , m_buffer(nullptr) |
61 , m_isLooping(false) | 61 , m_isLooping(false) |
62 , m_loopStart(0) | 62 , m_loopStart(0) |
63 , m_loopEnd(0) | 63 , m_loopEnd(0) |
64 , m_virtualReadIndex(0) | 64 , m_virtualReadIndex(0) |
65 , m_isGrain(false) | 65 , m_isGrain(false) |
66 , m_grainOffset(0.0) | 66 , m_grainOffset(0.0) |
67 , m_grainDuration(DefaultGrainDuration) | 67 , m_grainDuration(DefaultGrainDuration) |
68 , m_lastGain(1.0) | |
69 , m_pannerNode(0) | 68 , m_pannerNode(0) |
70 { | 69 { |
71 ScriptWrappable::init(this); | 70 ScriptWrappable::init(this); |
72 setNodeType(NodeTypeAudioBufferSource); | 71 setNodeType(NodeTypeAudioBufferSource); |
73 | 72 |
74 m_gain = AudioParam::create(context, "gain", 1.0, 0.0, 1.0); | |
75 m_playbackRate = AudioParam::create(context, "playbackRate", 1.0, 0.0, MaxRa te); | 73 m_playbackRate = AudioParam::create(context, "playbackRate", 1.0, 0.0, MaxRa te); |
76 | 74 |
77 // Default to mono. A call to setBuffer() will set the number of output cha nnels to that of the buffer. | 75 // Default to mono. A call to setBuffer() will set the number of output cha nnels to that of the buffer. |
78 addOutput(adoptPtr(new AudioNodeOutput(this, 1))); | 76 addOutput(adoptPtr(new AudioNodeOutput(this, 1))); |
79 | 77 |
80 initialize(); | 78 initialize(); |
81 } | 79 } |
82 | 80 |
83 AudioBufferSourceNode::~AudioBufferSourceNode() | 81 AudioBufferSourceNode::~AudioBufferSourceNode() |
84 { | 82 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 124 |
127 for (unsigned i = 0; i < outputBus->numberOfChannels(); ++i) | 125 for (unsigned i = 0; i < outputBus->numberOfChannels(); ++i) |
128 m_destinationChannels[i] = outputBus->channel(i)->mutableData(); | 126 m_destinationChannels[i] = outputBus->channel(i)->mutableData(); |
129 | 127 |
130 // Render by reading directly from the buffer. | 128 // Render by reading directly from the buffer. |
131 if (!renderFromBuffer(outputBus, quantumFrameOffset, bufferFramesToProce ss)) { | 129 if (!renderFromBuffer(outputBus, quantumFrameOffset, bufferFramesToProce ss)) { |
132 outputBus->zero(); | 130 outputBus->zero(); |
133 return; | 131 return; |
134 } | 132 } |
135 | 133 |
136 // Apply the gain (in-place) to the output bus. | |
137 float totalGain = gain()->value() * m_buffer->gain(); | |
138 outputBus->copyWithGainFrom(*outputBus, &m_lastGain, totalGain); | |
Raymond Toy
2014/04/07 20:17:12
Do we still need to do some kind of copy here or d
KhNo
2014/04/08 02:27:16
It is just for applying gain to outputBus itself.
| |
139 outputBus->clearSilentFlag(); | 134 outputBus->clearSilentFlag(); |
140 } else { | 135 } else { |
141 // Too bad - the tryLock() failed. We must be in the middle of changing buffers and were already outputting silence anyway. | 136 // Too bad - the tryLock() failed. We must be in the middle of changing buffers and were already outputting silence anyway. |
142 outputBus->zero(); | 137 outputBus->zero(); |
143 } | 138 } |
144 } | 139 } |
145 | 140 |
146 // Returns true if we're finished. | 141 // Returns true if we're finished. |
147 bool AudioBufferSourceNode::renderSilenceAndFinishIfNotLooping(AudioBus*, unsign ed index, size_t framesToProcess) | 142 bool AudioBufferSourceNode::renderSilenceAndFinishIfNotLooping(AudioBus*, unsign ed index, size_t framesToProcess) |
148 { | 143 { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 void AudioBufferSourceNode::finish() | 486 void AudioBufferSourceNode::finish() |
492 { | 487 { |
493 clearPannerNode(); | 488 clearPannerNode(); |
494 ASSERT(!m_pannerNode); | 489 ASSERT(!m_pannerNode); |
495 AudioScheduledSourceNode::finish(); | 490 AudioScheduledSourceNode::finish(); |
496 } | 491 } |
497 | 492 |
498 } // namespace WebCore | 493 } // namespace WebCore |
499 | 494 |
500 #endif // ENABLE(WEB_AUDIO) | 495 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |