1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/**
bespoke synth, a software modular synthesizer
Copyright (C) 2021 Ryan Challinor (contact: awwbees@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
//
// PolyphonyMgr.h
// additiveSynth
//
// Created by Ryan Challinor on 11/20/12.
//
//
#pragma once
#include "SynthGlobals.h"
#include "ChannelBuffer.h"
const int kVoiceFadeSamples = 50;
extern ChannelBuffer gMidiVoiceWorkChannelBuffer;
class IMidiVoice;
class IVoiceParams;
class IDrawableModule;
struct ModulationParameters;
enum VoiceType
{
kVoiceType_Karplus,
kVoiceType_FM,
kVoiceType_SingleOscillator,
kVoiceType_Sampler
};
struct VoiceInfo
{
float mPitch{ -1 };
IMidiVoice* mVoice{ nullptr };
double mTime{ 0 };
bool mNoteOn{ false };
float mActivity{ 0 };
};
class PolyphonyMgr
{
public:
PolyphonyMgr(IDrawableModule* owner);
~PolyphonyMgr();
void Init(VoiceType type,
IVoiceParams* mVoiceParams);
void Start(double time, int pitch, float amount, int voiceIdx, ModulationParameters modulation);
void Stop(double time, int pitch, int voiceIdx);
void Process(double time, ChannelBuffer* out, int bufferSize);
void DrawDebug(float x, float y);
void SetVoiceLimit(int limit) { mVoiceLimit = limit; }
void KillAll();
void SetOversampling(int oversampling) { mOversampling = oversampling; }
private:
VoiceInfo mVoices[kNumVoices];
bool mAllowStealing{ true };
int mLastVoice{ -1 };
ChannelBuffer mFadeOutBuffer{ kVoiceFadeSamples };
ChannelBuffer mFadeOutWorkBuffer{ kVoiceFadeSamples };
float mWorkBuffer[2048]{};
int mFadeOutBufferPos{ 0 };
IDrawableModule* mOwner;
int mVoiceLimit{ kNumVoices };
int mOversampling{ 1 };
};
|