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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return adoptRef(new GainHandler(node, sampleRate, gain)); | 46 return adoptRef(new GainHandler(node, sampleRate, gain)); |
47 } | 47 } |
48 | 48 |
49 void GainHandler::process(size_t framesToProcess) | 49 void GainHandler::process(size_t framesToProcess) |
50 { | 50 { |
51 // FIXME: for some cases there is a nice optimization to avoid processing he
re, and let the gain change | 51 // FIXME: for some cases there is a nice optimization to avoid processing he
re, and let the gain change |
52 // happen in the summing junction input of the AudioNode we're connected to. | 52 // happen in the summing junction input of the AudioNode we're connected to. |
53 // Then we can avoid all of the following: | 53 // Then we can avoid all of the following: |
54 | 54 |
55 AudioBus* outputBus = output(0).bus(); | 55 AudioBus* outputBus = output(0).bus(); |
56 ASSERT(outputBus); | 56 DCHECK(outputBus); |
57 | 57 |
58 if (!isInitialized() || !input(0).isConnected()) { | 58 if (!isInitialized() || !input(0).isConnected()) { |
59 outputBus->zero(); | 59 outputBus->zero(); |
60 } else { | 60 } else { |
61 AudioBus* inputBus = input(0).bus(); | 61 AudioBus* inputBus = input(0).bus(); |
62 | 62 |
63 if (m_gain->hasSampleAccurateValues()) { | 63 if (m_gain->hasSampleAccurateValues()) { |
64 // Apply sample-accurate gain scaling for precise envelopes, grain w
indows, etc. | 64 // Apply sample-accurate gain scaling for precise envelopes, grain w
indows, etc. |
65 ASSERT(framesToProcess <= m_sampleAccurateGainValues.size()); | 65 DCHECK_LE(framesToProcess, m_sampleAccurateGainValues.size()); |
66 if (framesToProcess <= m_sampleAccurateGainValues.size()) { | 66 if (framesToProcess <= m_sampleAccurateGainValues.size()) { |
67 float* gainValues = m_sampleAccurateGainValues.data(); | 67 float* gainValues = m_sampleAccurateGainValues.data(); |
68 m_gain->calculateSampleAccurateValues(gainValues, framesToProces
s); | 68 m_gain->calculateSampleAccurateValues(gainValues, framesToProces
s); |
69 outputBus->copyWithSampleAccurateGainValuesFrom(*inputBus, gainV
alues, framesToProcess); | 69 outputBus->copyWithSampleAccurateGainValuesFrom(*inputBus, gainV
alues, framesToProcess); |
70 // Update m_lastGain so if the timeline ever ends, we get | 70 // Update m_lastGain so if the timeline ever ends, we get |
71 // consistent data for the smoothing below. (Without this, | 71 // consistent data for the smoothing below. (Without this, |
72 // m_lastGain was the last value before the timeline started | 72 // m_lastGain was the last value before the timeline started |
73 // procesing. | 73 // procesing. |
74 m_lastGain = gainValues[framesToProcess - 1]; | 74 m_lastGain = gainValues[framesToProcess - 1]; |
75 } | 75 } |
(...skipping 10 matching lines...) Expand all Loading... |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 // FIXME: this can go away when we do mixing with gain directly in summing junct
ion of AudioNodeInput | 89 // FIXME: this can go away when we do mixing with gain directly in summing junct
ion of AudioNodeInput |
90 // | 90 // |
91 // As soon as we know the channel count of our input, we can lazily initialize. | 91 // As soon as we know the channel count of our input, we can lazily initialize. |
92 // Sometimes this may be called more than once with different channel counts, in
which case we must safely | 92 // Sometimes this may be called more than once with different channel counts, in
which case we must safely |
93 // uninitialize and then re-initialize with the new channel count. | 93 // uninitialize and then re-initialize with the new channel count. |
94 void GainHandler::checkNumberOfChannelsForInput(AudioNodeInput* input) | 94 void GainHandler::checkNumberOfChannelsForInput(AudioNodeInput* input) |
95 { | 95 { |
96 ASSERT(context()->isAudioThread()); | 96 DCHECK(context()->isAudioThread()); |
97 ASSERT(context()->isGraphOwner()); | 97 ASSERT(context()->isGraphOwner()); |
98 | 98 |
99 ASSERT(input); | 99 DCHECK(input); |
100 ASSERT(input == &this->input(0)); | 100 DCHECK_EQ(input, &this->input(0)); |
101 if (input != &this->input(0)) | 101 if (input != &this->input(0)) |
102 return; | 102 return; |
103 | 103 |
104 unsigned numberOfChannels = input->numberOfChannels(); | 104 unsigned numberOfChannels = input->numberOfChannels(); |
105 | 105 |
106 if (isInitialized() && numberOfChannels != output(0).numberOfChannels()) { | 106 if (isInitialized() && numberOfChannels != output(0).numberOfChannels()) { |
107 // We're already initialized but the channel count has changed. | 107 // We're already initialized but the channel count has changed. |
108 uninitialize(); | 108 uninitialize(); |
109 } | 109 } |
110 | 110 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 144 } |
145 | 145 |
146 DEFINE_TRACE(GainNode) | 146 DEFINE_TRACE(GainNode) |
147 { | 147 { |
148 visitor->trace(m_gain); | 148 visitor->trace(m_gain); |
149 AudioNode::trace(visitor); | 149 AudioNode::trace(visitor); |
150 } | 150 } |
151 | 151 |
152 } // namespace blink | 152 } // namespace blink |
153 | 153 |
OLD | NEW |