| 42 | } |
| 43 | |
| 44 | void GainNode::process(ContextRenderLock &r, int bufferSize) |
| 45 | { |
| 46 | // FIXME: for some cases there is a nice optimization to avoid processing here, and let the gain change |
| 47 | // happen in the summing junction input of the AudioNode we're connected to. |
| 48 | // Then we can avoid all of the following: |
| 49 | |
| 50 | AudioBus * outputBus = output(0)->bus(r); |
| 51 | ASSERT(outputBus); |
| 52 | |
| 53 | |
| 54 | if (!isInitialized() || !input(0)->isConnected()) |
| 55 | { |
| 56 | outputBus->zero(); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | AudioBus* inputBus = input(0)->bus(r); |
| 62 | const int inputBusChannelCount = inputBus->numberOfChannels(); |
| 63 | if (!inputBusChannelCount) |
| 64 | { |
| 65 | outputBus->zero(); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | int outputBusChannelCount = outputBus->numberOfChannels(); |
| 70 | if (inputBusChannelCount != outputBusChannelCount) |
| 71 | { |
| 72 | output(0)->setNumberOfChannels(r, inputBusChannelCount); |
| 73 | outputBusChannelCount = inputBusChannelCount; |
| 74 | outputBus = output(0)->bus(r); |
| 75 | } |
| 76 | |
| 77 | if (gain()->hasSampleAccurateValues()) |
| 78 | { |
| 79 | // Apply sample-accurate gain scaling for precise envelopes, grain windows, etc. |
| 80 | ASSERT(bufferSize <= m_sampleAccurateGainValues.size()); |
| 81 | if (bufferSize <= m_sampleAccurateGainValues.size()) |
| 82 | { |
| 83 | float* gainValues_base = m_sampleAccurateGainValues.data(); |
| 84 | float* gainValues = gainValues_base + _scheduler._renderOffset; |
| 85 | gain()->calculateSampleAccurateValues(r, gainValues, _scheduler._renderLength); |
| 86 | if (_scheduler._renderOffset > 0) |
| 87 | memset(gainValues_base, 0, sizeof(float) * _scheduler._renderOffset); |
| 88 | int bzero_start = _scheduler._renderOffset + _scheduler._renderLength; |
| 89 | if (bzero_start < bufferSize) |
| 90 | memset(gainValues_base + bzero_start, 0, sizeof(float) * bufferSize - bzero_start); |
| 91 | outputBus->copyWithSampleAccurateGainValuesFrom(*inputBus, m_sampleAccurateGainValues.data(), bufferSize); |
| 92 | } |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | // Apply the gain with de-zippering into the output bus. |
| 97 | outputBus->copyWithGainFrom(*inputBus, &m_lastGain, gain()->value()); |
| 98 | } |
| 99 | |
| 100 | outputBus->clearSilentFlag(); |
| 101 | } |
nothing calls this directly
no test coverage detected