| 44 | } |
| 45 | |
| 46 | bool SampleVoice::Process(double time, ChannelBuffer* out, int oversampling) |
| 47 | { |
| 48 | PROFILER(SampleVoice); |
| 49 | |
| 50 | if (IsDone(time) || |
| 51 | mVoiceParams->mSampleData == nullptr || |
| 52 | mVoiceParams->mSampleLength == 0) |
| 53 | return false; |
| 54 | |
| 55 | float volSq = mVoiceParams->mVol * mVoiceParams->mVol; |
| 56 | |
| 57 | for (int pos = 0; pos < out->BufferSize(); ++pos) |
| 58 | { |
| 59 | if (mOwner) |
| 60 | mOwner->ComputeSliders(pos); |
| 61 | |
| 62 | if (mPos <= mVoiceParams->mSampleLength || mVoiceParams->mLoop) |
| 63 | { |
| 64 | float freq = TheScale->PitchToFreq(GetPitch(pos)); |
| 65 | float speed; |
| 66 | if (mVoiceParams->mDetectedFreq != -1) |
| 67 | speed = freq / mVoiceParams->mDetectedFreq; |
| 68 | else |
| 69 | speed = freq / TheScale->PitchToFreq(TheScale->ScaleRoot() + 48); |
| 70 | |
| 71 | float sample = GetInterpolatedSample(mPos, mVoiceParams->mSampleData, mVoiceParams->mSampleLength) * mAdsr.Value(time) * volSq; |
| 72 | |
| 73 | if (out->NumActiveChannels() == 1) |
| 74 | { |
| 75 | out->GetChannel(0)[pos] += sample; |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | out->GetChannel(0)[pos] += sample * GetLeftPanGain(GetPan()); |
| 80 | out->GetChannel(1)[pos] += sample * GetRightPanGain(GetPan()); |
| 81 | } |
| 82 | |
| 83 | mPos += speed; |
| 84 | } |
| 85 | |
| 86 | time += gInvSampleRateMs; |
| 87 | } |
| 88 | |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | void SampleVoice::Start(double time, float target) |
| 93 | { |
nothing calls this directly
no test coverage detected