| 61 | } |
| 62 | |
| 63 | bool KarplusStrongVoice::Process(double time, ChannelBuffer* out, int oversampling) |
| 64 | { |
| 65 | PROFILER(KarplusStrongVoice); |
| 66 | |
| 67 | if (IsDone(time)) |
| 68 | return false; |
| 69 | |
| 70 | int bufferSize = out->BufferSize(); |
| 71 | int channels = out->NumActiveChannels(); |
| 72 | double sampleIncrementMs = gInvSampleRateMs; |
| 73 | double sampleRate = gSampleRate; |
| 74 | ChannelBuffer* destBuffer = out; |
| 75 | |
| 76 | if (oversampling != 1) |
| 77 | { |
| 78 | gMidiVoiceWorkChannelBuffer.SetNumActiveChannels(channels); |
| 79 | destBuffer = &gMidiVoiceWorkChannelBuffer; |
| 80 | gMidiVoiceWorkChannelBuffer.Clear(); |
| 81 | bufferSize *= oversampling; |
| 82 | sampleIncrementMs /= oversampling; |
| 83 | sampleRate *= oversampling; |
| 84 | } |
| 85 | |
| 86 | float freq; |
| 87 | float filterRate; |
| 88 | float filterLerp; |
| 89 | float pitch; |
| 90 | float oscPhaseInc; |
| 91 | |
| 92 | if (mVoiceParams->mLiteCPUMode) |
| 93 | DoParameterUpdate(0, oversampling, pitch, freq, filterRate, filterLerp, oscPhaseInc); |
| 94 | |
| 95 | for (int pos = 0; pos < bufferSize; ++pos) |
| 96 | { |
| 97 | if (!mVoiceParams->mLiteCPUMode) |
| 98 | DoParameterUpdate(pos / oversampling, oversampling, pitch, freq, filterRate, filterLerp, oscPhaseInc); |
| 99 | |
| 100 | if (mVoiceParams->mSourceType == kSourceTypeSaw) |
| 101 | mOsc.SetType(kOsc_Saw); |
| 102 | else |
| 103 | mOsc.SetType(kOsc_Sin); |
| 104 | mOscPhase += oscPhaseInc; |
| 105 | float sample = 0; |
| 106 | float oscSample = mOsc.Audio(time, mOscPhase); |
| 107 | float noiseSample = RandomSample(); |
| 108 | float pitchBlend = ofClamp((pitch - 40) / 60.0f, 0, 1); |
| 109 | pitchBlend *= pitchBlend; |
| 110 | if (mVoiceParams->mSourceType == kSourceTypeSin || mVoiceParams->mSourceType == kSourceTypeSaw) |
| 111 | sample = oscSample; |
| 112 | else if (mVoiceParams->mSourceType == kSourceTypeNoise) |
| 113 | sample = noiseSample; |
| 114 | else if (mVoiceParams->mSourceType == kSourceTypeMix) |
| 115 | sample = noiseSample * pitchBlend + oscSample * (1 - pitchBlend); |
| 116 | else if (mVoiceParams->mSourceType == kSourceTypeInput || mVoiceParams->mSourceType == kSourceTypeInputNoEnvelope) |
| 117 | sample = mKarplusStrongModule->GetBuffer()->GetChannel(0)[pos / oversampling]; |
| 118 | |
| 119 | if (mVoiceParams->mSourceType != kSourceTypeInputNoEnvelope) |
| 120 | sample *= mEnv.Value(time) + mVoiceParams->mExcitation; |
nothing calls this directly
no test coverage detected