Last active
August 29, 2015 14:11
-
-
Save beschulz/02148007938d6e5d88ec to your computer and use it in GitHub Desktop.
Tremolo Effect with quarter note frequency to illustrate bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Reproduction: | |
- set bpm to 120 | |
- set buffer size to 2048 | |
- play long sustained audio | |
- put one instance of this plugin into track | |
- Audio has tremolo effect applied, eighth note on ... eighth note off ... | |
- copy plugin so that there are eight instances | |
- audio disapears | |
Expected: | |
1.) it should make no audible difference, if I put one or eight | |
instances onto the track. the result should always be the same. | |
2.) the playhead that is available to the plugin represents the position | |
of the currently processed block in the arrangement for each plugin | |
instance in the signal-chain until the processing of the next block begins. | |
Speculation: | |
- the playhead is wrongly increased, so that ppqPos is offset by bufferSize for each plugin in the signal chain. | |
- for(int i=0; i!=numPlugsInChain; ++i) | |
{ | |
plugin[i]->process(current_block); | |
play_cursor += bufferSize; // don't do that :o) - I guess it's not that simple | |
} | |
*/ | |
void PlayHeadTestAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) | |
{ | |
AudioPlayHead* playHead = getPlayHead(); | |
AudioPlayHead::CurrentPositionInfo cpi; | |
if(playHead && playHead->getCurrentPosition(cpi)) | |
{ | |
double ppqBegin = cpi.ppqPosition; | |
double bps = cpi.bpm / 60.0; // beats per second | |
double blockLengthInSeconds = buffer.getNumSamples() / getSampleRate(); | |
double blockLengthInBeats = bps * blockLengthInSeconds; | |
for (int channel = 0; channel < getNumInputChannels(); ++channel) | |
{ | |
float* channelData = buffer.getWritePointer (channel); | |
for (int sample = 0; sample != buffer.getNumSamples(); ++sample) | |
{ | |
double percentualPositionInBlock = (sample / double(buffer.getNumSamples())); | |
double beatPositionOfThisSample = ppqBegin + blockLengthInBeats * percentualPositionInBlock; | |
double quarterPosition = std::fmod(beatPositionOfThisSample, 1.0); | |
float gain = (quarterPosition < 0.5) ? 1.0f : 0.0f; | |
channelData[sample] *= gain; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment