Skip to content

Commit

Permalink
Audio In effect (#7029)
Browse files Browse the repository at this point in the history
Co-authored-by: EvilDragon <[email protected]>
  • Loading branch information
Alexander-Zyurkalov and mkruselj authored Jun 5, 2023
1 parent dfd58f1 commit 94e5773
Show file tree
Hide file tree
Showing 14 changed files with 1,104 additions and 31 deletions.
3 changes: 3 additions & 0 deletions resources/surge-shared/configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
<type i="14" name="Airwindows">
<snapshot name="Init" p0="46" p1="1.000000" p2="0.000000" p3="1.000000"/>
</type>
<type i="29" name="Audio Input">
<snapshot name="Init" p0="0" p1="0.0" p2="-96.0" p3="0" p4="0.0" p5="0.0" p6="0" p7="0.0" p8="-96.0" p9="1.0" p10="1.0"/>
</type>
<type i="8" name="Conditioner">
<snapshot name="Init" p0="0.000000" p1="0.000000" p2="1.000000" p3="0.000000" p4="-6" p5="0.000000"
p6="0.000000" p7="0.000000" p8="-60" p8_deactivated="1"/>
Expand Down
2 changes: 2 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ add_library(${PROJECT_NAME}
dsp/effects/chowdsp/tape/LossFilter.h
dsp/effects/chowdsp/tape/ToneControl.cpp
dsp/effects/chowdsp/tape/ToneControl.h
dsp/effects/AudioInputEffect.cpp
dsp/effects/AudioInputEffect.h
dsp/filters/AllpassFilter.h
dsp/filters/BiquadFilter.h
dsp/filters/VectorizedSVFilter.cpp
Expand Down
32 changes: 32 additions & 0 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2750,5 +2750,37 @@ string findReplaceSubstring(string &source, const string &from, const string &to
return newString;
}

Surge::Storage::ScenesOutputData::ScenesOutputData()
{
for (int i = 0; i < n_scenes; i++)
{
for (int j = 0; j < N_OUTPUTS; j++)
{
std::shared_ptr<float[BLOCK_SIZE]> block{new float[BLOCK_SIZE]{}};
sceneData[i][j] = block;
}
}
}
const std::shared_ptr<float[BLOCK_SIZE]> &
Surge::Storage::ScenesOutputData::getSceneData(int scene, int channel) const
{
assert(scene < n_scenes && scene >= 0);
assert(channel < N_OUTPUTS && channel >= 0);
return sceneData[scene][channel];
}
bool Surge::Storage::ScenesOutputData::thereAreClients(int scene) const
{
return std::any_of(std::begin(sceneData[scene]), std::end(sceneData[scene]),
[](const auto &channel) { return channel.use_count() > 1; });
}
void Surge::Storage::ScenesOutputData::provideSceneData(int scene, int channel, float *data)
{
if (scene < n_scenes && scene >= 0 && channel < N_OUTPUTS && channel >= 0 &&
sceneData[scene][channel].use_count() > 1) // we don't provide data if there are no clients
{
memcpy(sceneData[scene][channel].get(), data, BLOCK_SIZE * sizeof(float));
}
}

} // namespace Storage
} // namespace Surge
38 changes: 32 additions & 6 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ enum fxslot_positions
};

// clang-format off
static int constexpr fxslot_order[n_fx_slots] =
static int constexpr fxslot_order[n_fx_slots] =
{fxslot_ains1, fxslot_ains2, fxslot_ains3, fxslot_ains4,
fxslot_bins1, fxslot_bins2, fxslot_bins3, fxslot_bins4,
fxslot_send1, fxslot_send2, fxslot_send3, fxslot_send4,
Expand Down Expand Up @@ -384,6 +384,7 @@ enum fx_type
fxt_mstool,
fxt_spring_reverb,
fxt_bonsai,
fxt_audio_input,

n_fx_types,
};
Expand Down Expand Up @@ -416,19 +417,20 @@ const char fx_type_names[n_fx_types][32] = {"Off",
"Waveshaper",
"Mid-Side Tool",
"Spring Reverb",
"Bonsai"};
"Bonsai",
"Audio Input"};

const char fx_type_shortnames[n_fx_types][16] = {
"Off", "Delay", "Reverb 1", "Phaser", "Rotary", "Distortion",
"EQ", "Freq Shift", "Conditioner", "Chorus", "Vocoder", "Reverb 2",
"Flanger", "Ring Mod", "Airwindows", "Neuron", "Graphic EQ", "Resonator",
"CHOW", "Exciter", "Ensemble", "Combulator", "Nimbus", "Tape",
"Treemonster", "Waveshaper", "Mid-Side Tool", "Spring Reverb", "Bonsai"};
"Treemonster", "Waveshaper", "Mid-Side Tool", "Spring Reverb", "Bonsai", "Audio In"};

const char fx_type_acronyms[n_fx_types][8] = {
"OFF", "DLY", "RV1", "PH", "ROT", "DIST", "EQ", "FRQ", "DYN", "CH",
"VOC", "RV2", "FL", "RM", "AW", "NEU", "GEQ", "RES", "CHW", "XCT",
"ENS", "CMB", "NIM", "TAPE", "TM", "WS", "M-S", "SRV", "BON"};
"ENS", "CMB", "NIM", "TAPE", "TM", "WS", "M-S", "SRV", "BON", "IN"};

enum fx_bypass
{
Expand Down Expand Up @@ -665,7 +667,10 @@ struct LFOStorage

struct FxStorage
{
// Just a heads up: if you change this, please go look at fx_reorder in SurgeStorage too!
// Just a heads up: if you change this, please go look at reorderFx in SurgeSynthesizer too!
FxStorage(fxslot_positions slot) : fxslot(slot) {}
FxStorage() = delete;
fxslot_positions fxslot;
Parameter type;
Parameter return_level;
Parameter p[n_fx_params];
Expand Down Expand Up @@ -983,7 +988,14 @@ class SurgePatch

// data
SurgeSceneStorage scene[n_scenes], morphscene;
FxStorage fx[n_fx_slots];

FxStorage fx[n_fx_slots]{
FxStorage(fxslot_ains1), FxStorage(fxslot_ains2), FxStorage(fxslot_bins1),
FxStorage(fxslot_bins2), FxStorage(fxslot_send1), FxStorage(fxslot_send2),
FxStorage(fxslot_global1), FxStorage(fxslot_global2), FxStorage(fxslot_ains3),
FxStorage(fxslot_ains4), FxStorage(fxslot_bins3), FxStorage(fxslot_bins4),
FxStorage(fxslot_send3), FxStorage(fxslot_send4), FxStorage(fxslot_global3),
FxStorage(fxslot_global4)};
int scene_start[n_scenes], scene_size;

std::unordered_map<std::string, Parameter *> param_ptr_by_oscname;
Expand Down Expand Up @@ -1102,6 +1114,18 @@ namespace Surge
{
namespace Storage
{
struct ScenesOutputData
{
std::shared_ptr<float[BLOCK_SIZE]> sceneData[n_scenes][N_OUTPUTS]{{nullptr, nullptr},
{nullptr, nullptr}};

public:
ScenesOutputData();
const std::shared_ptr<float[BLOCK_SIZE]> &getSceneData(int scene, int channel) const;
void provideSceneData(int scene, int channel, float *data);
bool thereAreClients(int scene) const;
};

struct FxUserPreset;
struct ModulatorPreset;
} // namespace Storage
Expand Down Expand Up @@ -1546,6 +1570,8 @@ class alignas(16) SurgeStorage

std::atomic<int> otherscene_clients;

Surge::Storage::ScenesOutputData scenesOutputData;

std::unordered_map<int, std::string> helpURL_controlgroup;
std::unordered_map<std::string, std::string> helpURL_paramidentifier;
std::unordered_map<std::string, std::string> helpURL_specials;
Expand Down
9 changes: 6 additions & 3 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4574,6 +4574,10 @@ void SurgeSynthesizer::process()
sc_state[i] = play_scene[i];
}

for (int i = 0; i < n_scenes; i++)
for (int channel = 0; channel < N_OUTPUTS; channel++)
storage.scenesOutputData.provideSceneData(i, channel, sceneout[i][channel]);

// apply insert effects
if (fx_bypass != fxb_no_fx)
{
Expand Down Expand Up @@ -4936,9 +4940,8 @@ void SurgeSynthesizer::reorderFx(int source, int target, FXReorderMode m)

std::lock_guard<std::recursive_mutex> lockModulation(storage.modRoutingMutex);

FxStorage so, to;
so = storage.getPatch().fx[source];
to = storage.getPatch().fx[target];
FxStorage so{storage.getPatch().fx[source]};
FxStorage to{storage.getPatch().fx[target]};

fxmodsync[source].clear();
fxmodsync[target].clear();
Expand Down
10 changes: 8 additions & 2 deletions src/common/SurgeSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,14 @@ class alignas(16) SurgeSynthesizer
// TODO: FIX SCENE ASSUMPTION (use std::array)
std::array<BiquadFilter, n_hpBQ> hpA, hpB;

bool fx_reload[n_fx_slots]; // if true, reload new effect parameters from fxsync
FxStorage fxsync[n_fx_slots]; // used for synchronisation of parameter init
bool fx_reload[n_fx_slots]; // if true, reload new effect parameters from fxsync
FxStorage fxsync[n_fx_slots]{
FxStorage(fxslot_ains1), FxStorage(fxslot_ains2), FxStorage(fxslot_bins1),
FxStorage(fxslot_bins2), FxStorage(fxslot_send1), FxStorage(fxslot_send2),
FxStorage(fxslot_global1), FxStorage(fxslot_global2), FxStorage(fxslot_ains3),
FxStorage(fxslot_ains4), FxStorage(fxslot_bins3), FxStorage(fxslot_bins4),
FxStorage(fxslot_send3), FxStorage(fxslot_send4), FxStorage(fxslot_global3),
FxStorage(fxslot_global4)}; // used for synchronisation of parameter init
bool fx_reload_mod[n_fx_slots];

struct FXModSyncItem
Expand Down
3 changes: 3 additions & 0 deletions src/common/dsp/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "chowdsp/SpringReverbEffect.h"
#include "chowdsp/TapeEffect.h"
#include "DebugHelpers.h"
#include "AudioInputEffect.h"

using namespace std;

Expand Down Expand Up @@ -113,6 +114,8 @@ Effect *spawn_effect(int id, SurgeStorage *storage, FxStorage *fxdata, pdata *pd
return new chowdsp::SpringReverbEffect(storage, fxdata, pd);
case fxt_bonsai:
return new BonsaiEffect(storage, fxdata, pd);
case fxt_audio_input:
return new AudioInputEffect(storage, fxdata, pd);
default:
return 0;
};
Expand Down
Loading

0 comments on commit 94e5773

Please sign in to comment.