4#include "../vae_types.hpp"
5#include "../vae_util.hpp"
6#include "../pod/vae_bank.hpp"
7#include "../voices/vae_voice.hpp"
8#include "../voices/vae_voice_filter.hpp"
9#include "../voices/vae_voice_pan.hpp"
10#include "../vae_voice_manager.hpp"
14namespace vae {
namespace core {
42 Size actuallyRendered = 0;
45 if (v.
bank != bank.
id) { return true; }
50 auto& signal = source.signal;
54 if (signalLength == 0) {
return false; }
55 if (signal.sampleRate != sampleRate) {
62 const auto signalChannels = signal.channels();
64 auto& target = mixer.buffer;
65 const auto targetChannels = target.channels();
66 const auto gain = v.
gain * source.gain;
72 target.setValidSize(frames);
75 VAE_PROFILER_SCOPE_NAMED(
"Render Voice Basic")
78 const SampleIndex needed = v.loop ? frames : std::min(frames, SampleIndex(signalLength - v.time));
81 for (int c = 0; c < targetChannels; c++) {
82 const int channel = c % signalChannels;
83 for (SampleIndex s = 0; s < needed; s++) {
85 signal[channel][((v.time + s) % signalLength)] * gain * pan.volumes[c];
91 for (int c = 0; c < targetChannels; c++) {
92 for (SampleIndex s = 0; s < needed; s++) {
93 const int channel = c % signalChannels;
95 signal[channel][v.time + s] * gain * pan.volumes[c];
101 return needed == frames;
107 auto& fd = manager.getVoiceFilter(index);
112 fd.highpassScratch[c] = 0;
113 fd.lowpassScratch[c] = signal[c % signalChannels][v.time];
122 const Real speed = fd.speed * (
Sample(signal.sampleRate) /
Sample(sampleRate));
124 frames,
SampleIndex(std::floor((signalLength - v.time) / speed - fd.timeFract))
127 for (
int c = 0; c < target.channels(); c++) {
129 const int channel = c % signal.channels();
131 position = v.time + (s * speed) + fd.timeFract;
132 const Real lastPosition = std::floor(position);
133 const Size lastIndex = (
Size) lastPosition;
134 const Size nextIndex = (
Size) lastPosition + 1;
136 Real mix = position - lastPosition;
138 const Sample last = signal[channel][lastIndex % signalLength] * gain;
139 const Sample next = signal[channel][nextIndex % signalLength] * gain;
141 const Sample in = last +
mix * (next - last);
145 const Sample lf = fd.lowpass;
146 const Sample lpd = in + lf * (fd.lowpassScratch[c] - in);
147 fd.lowpassScratch[c] = lpd;
149 const Sample hf = fd.highpass;
150 const Sample hps = fd.highpassScratch[c];
151 const Sample hpd = hps + hf * (in - hps);
152 fd.highpassScratch[c] = hpd;
154 target[c][s] += (lpd - hpd) * pan.volumes[c];
159 fd.timeFract = position - v.time;
160 return needed == frames;
163 return actuallyRendered;
bool resize(const Size length, uchar channels)
! Will not keep the contents! Resizes the buffer to the desired length and channel count.
Non spatial voice processor.
Size mix(VoiceManger &manager, Bank &bank, SampleIndex frames, Size sampleRate)
Process a single bank.
ScratchBuffer mScratchBuffer
Temporary filtered/looped signal TODO this will not work with parallel bank processing.
There is only one voice pool and VAE and it's managed here.
VoicePan & getVoicePan(Size index)
void forEachVoice(const Func &&func)
Callback provided to iterate voices, needs to return a bool to indicate when a voice needs to be stop...
T min(const T &v1, const T &v2)
constexpr Size MaxBlock
Maximum block size.
constexpr unsigned char MaxChannels
Maximum channel count used to pre allocate buffers.
AudioBuffer::Size SampleIndex
Contains Typedefinitions and basic structures use by the public API and internally.
unsigned int Size
How the elements are addressed in the heapbuffer.
float Sample
Default sample types used where ever possible, changing this means the engine needs to be recompiled,...
Result
Return Types for most engine functions.
Bank object containing Sources, Mixers and Events Can be loaded and unloaded at runtime.
HeapBuffer< Mixer > mixers
Audio Mixers which can have effects ! is presorted !
HeapBuffer< Source > sources
Audio sources defined.
SourceHandle source
If invalid, means voice is not playing.
bool spatialized
If the voice has spatialization data.
Sample gain
Volume of the voice.
bool audible
Whether the voice was heard by any listener.
BankHandle bank
Which bank it belongs to.
bool filtered
This will enable high/lowpass filters and variable speed playback. Gets turned on when signal does no...
MixerHandle mixer
Where the voice should mix to.
SampleIndex time
Current time in samples.
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.