|
| 1 | +// Copyright AudioKit. All Rights Reserved. |
| 2 | + |
| 3 | +#include "SoundpipeDSPBase.h" |
| 4 | +#include "ParameterRamper.h" |
| 5 | +#include "Soundpipe.h" |
| 6 | + |
| 7 | +enum TalkboxParameter : AUParameterAddress { |
| 8 | + TalkboxParameterQuality, |
| 9 | +}; |
| 10 | + |
| 11 | +class TalkboxDSP : public SoundpipeDSPBase { |
| 12 | +private: |
| 13 | + sp_talkbox *talkbox; |
| 14 | + ParameterRamper qualityRamp{1.0}; |
| 15 | + |
| 16 | +public: |
| 17 | + TalkboxDSP() { |
| 18 | + inputBufferLists.resize(2); // Set up for two input streams |
| 19 | + parameters[TalkboxParameterQuality] = &qualityRamp; |
| 20 | + } |
| 21 | + |
| 22 | + void init(int channelCount, double sampleRate) override { |
| 23 | + SoundpipeDSPBase::init(channelCount, sampleRate); |
| 24 | + sp_talkbox_create(&talkbox); |
| 25 | + sp_talkbox_init(sp, talkbox); |
| 26 | + } |
| 27 | + |
| 28 | + void deinit() override { |
| 29 | + SoundpipeDSPBase::deinit(); |
| 30 | + sp_talkbox_destroy(&talkbox); |
| 31 | + } |
| 32 | + |
| 33 | + void reset() override { |
| 34 | + SoundpipeDSPBase::reset(); |
| 35 | + if (!isInitialized) return; |
| 36 | + sp_talkbox_init(sp, talkbox); |
| 37 | + } |
| 38 | + |
| 39 | + void process(FrameRange range) override { |
| 40 | + for (int i : range) { |
| 41 | + float sourceIn = inputSample(0, i); // source input (first input stream) |
| 42 | + float excitationIn = input2Sample(0, i); // excitation input (second input stream) |
| 43 | + float outSample; |
| 44 | + |
| 45 | + talkbox->quality = qualityRamp.getAndStep(); |
| 46 | + |
| 47 | + sp_talkbox_compute(sp, talkbox, &sourceIn, &excitationIn, &outSample); |
| 48 | + |
| 49 | + outputSample(0, i) = outSample; |
| 50 | + } |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +AK_REGISTER_DSP(TalkboxDSP, "tbox") |
| 55 | +AK_REGISTER_PARAMETER(TalkboxParameterQuality) |
0 commit comments