Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #62 from obsproject/process
Browse files Browse the repository at this point in the history
Ability to handle audio with more frames than the VST Blocksize
  • Loading branch information
DDRBoxman authored May 21, 2020
2 parents 86698f5 + 935a4e3 commit 83e1bf2
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions VSTPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,29 @@ void silenceChannel(float **channelData, int numChannels, long numFrames)

obs_audio_data *VSTPlugin::process(struct obs_audio_data *audio)
{

if (effect && effectReady) {
silenceChannel(outputs, VST_MAX_CHANNELS, audio->frames);

float *adata[VST_MAX_CHANNELS];
for (size_t d = 0; d < VST_MAX_CHANNELS; d++) {
if (audio->data[d] != NULL) {
adata[d] = (float *)audio->data[d];
} else {
adata[d] = inputs[d];
}
};
uint passes = (audio->frames + BLOCK_SIZE - 1) / BLOCK_SIZE;
uint extra = audio->frames % BLOCK_SIZE;
for (uint pass = 0; pass < passes; pass++) {
uint frames = pass == passes - 1 && extra ? extra : BLOCK_SIZE;
silenceChannel(outputs, VST_MAX_CHANNELS, BLOCK_SIZE);

float *adata[VST_MAX_CHANNELS];
for (size_t d = 0; d < VST_MAX_CHANNELS; d++) {
if (audio->data[d] != nullptr) {
adata[d] = ((float *)audio->data[d]) + (pass * BLOCK_SIZE);
} else {
adata[d] = inputs[d];
}
};

effect->processReplacing(effect, adata, outputs, audio->frames);
effect->processReplacing(effect, adata, outputs, frames);

for (size_t c = 0; c < VST_MAX_CHANNELS; c++) {
if (audio->data[c]) {
for (size_t i = 0; i < audio->frames; i++) {
adata[c][i] = outputs[c][i];
for (size_t c = 0; c < VST_MAX_CHANNELS; c++) {
if (audio->data[c]) {
for (size_t i = 0; i < frames; i++) {
adata[c][i] = outputs[c][i];
}
}
}
}
Expand Down

0 comments on commit 83e1bf2

Please sign in to comment.