Created
January 16, 2023 01:48
-
-
Save Xenakios/559e76152f8ae169abafde31161ae4ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| void AdditiveSynth::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) | |
| { | |
| // might want to avoid doing this for voices that are not active or | |
| // if parameters have not changed, but this will have to do for now | |
| for(auto& v : m_voices) | |
| { | |
| v.updateState(); | |
| } | |
| auto bufptrs = buffer.getArrayOfWritePointers(); | |
| auto it = midiMessages.begin(); | |
| for (int i=0;i<buffer.getNumSamples();++i) | |
| { | |
| // Using while, because we may have multiple messages at the same sample position | |
| // This might be somewhat inefficient in Juce context, but we will do this like this | |
| // because Clap processing will require doing it similarly anyway | |
| while (it!=midiMessages.end() && (*it).samplePosition==i) | |
| { | |
| // suspected inefficiency here because getMessage returns a copy for some reason | |
| const auto msg = (*it).getMessage(); | |
| if (msg.isNoteOn()) | |
| { | |
| handleNoteOn(-1,-1,msg.getNoteNumber(),-1,msg.getFloatVelocity()); | |
| //DBG("note on " << msg.getNoteNumber() << " at sample pos " << i ); | |
| } | |
| else if (msg.isNoteOff()) | |
| { | |
| handleNoteOff(-1,-1,msg.getNoteNumber(),-1); | |
| //DBG("note off " << msg.getNoteNumber() << " at sample pos " << i ); | |
| } | |
| ++it; | |
| } | |
| float voicesums[2] = {0.0f,0.0f}; | |
| for(auto& v : m_voices) | |
| { | |
| if (v.m_is_available==false) | |
| { | |
| v.step(); | |
| voicesums[0] += v.output_frame[0]; | |
| voicesums[1] += v.output_frame[1]; | |
| } | |
| } | |
| bufptrs[0][i] = voicesums[0]; | |
| bufptrs[1][i] = voicesums[1]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment