Add the phase generator by beat clock
This commit is contained in:
parent
ee056bcea8
commit
1983894bc8
2 changed files with 44 additions and 0 deletions
|
|
@ -199,6 +199,40 @@ void BeatClock::fillBufferUpTo(unsigned delay)
|
|||
mustApplyHostPos_ = mustApplyHostPos;
|
||||
}
|
||||
|
||||
void BeatClock::calculatePhase(float beatPeriod, float* phaseOut)
|
||||
{
|
||||
const unsigned numFrames = currentCycleFrames_;
|
||||
|
||||
if (beatPeriod == 0.0f) {
|
||||
fill(absl::MakeSpan(phaseOut, numFrames), 0.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
const float invBeatPeriod = 1.0f / beatPeriod;
|
||||
const float* beatPositionData = getRunningBeatPosition().data();
|
||||
|
||||
for (unsigned i = 0; i < numFrames; ++i) {
|
||||
float beatPosition = std::max(0.0f, beatPositionData[i]);
|
||||
float phase = beatPosition * invBeatPeriod;
|
||||
phase -= static_cast<int>(phase);
|
||||
phaseOut[i] = phase;
|
||||
}
|
||||
}
|
||||
|
||||
void BeatClock::calculatePhaseModulated(const float* beatPeriodData, float* phaseOut)
|
||||
{
|
||||
const unsigned numFrames = currentCycleFrames_;
|
||||
const float* beatPositionData = getRunningBeatPosition().data();
|
||||
|
||||
for (unsigned i = 0; i < numFrames; ++i) {
|
||||
float beatPeriod = beatPeriodData[i];
|
||||
float beatPosition = std::max(0.0f, beatPositionData[i]);
|
||||
float phase = beatPosition / beatPeriod;
|
||||
phase -= static_cast<int>(phase);
|
||||
phaseOut[i] = (beatPeriod != 0.0f) ? phase : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sfz
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const sfz::BBT& pos)
|
||||
|
|
|
|||
|
|
@ -130,6 +130,16 @@ public:
|
|||
* @brief Get the time signature numerator for each frame of the current cycle.
|
||||
*/
|
||||
absl::Span<const int> getRunningBeatsPerBar();
|
||||
/**
|
||||
* @brief Create a normalized phase signal for LFO which completes a
|
||||
* period every N-th beat.
|
||||
*/
|
||||
void calculatePhase(float beatPeriod, float* phaseOut);
|
||||
/**
|
||||
* @brief Create a normalized phase signal for LFO which completes a
|
||||
* period every N-th beat, where N can vary over time.
|
||||
*/
|
||||
void calculatePhaseModulated(const float* beatPeriodData, float* phaseOut);
|
||||
|
||||
private:
|
||||
void fillBufferUpTo(unsigned delay);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue