Skip to content

Commit

Permalink
proper type and number of channels and calculation from compoly base …
Browse files Browse the repository at this point in the history
…but horrible performance
  • Loading branch information
AdamPorcineFudgepuppy committed Jul 17, 2024
1 parent a4b8201 commit 0b44d32
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 18 deletions.
17 changes: 12 additions & 5 deletions src/ComputerscareComplexTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ struct ComputerscareComplexTransformer : ComputerscareComplexBase {
}
void process(const ProcessArgs &args) override {
ComputerscarePolyModule::checkCounter();
int wrapMode = 0;

int compolyphonyKnobSetting = params[COMPOLY_CHANNELS].getValue();
int mainInputMode = params[MAIN_INPUT_MODE].getValue();

std::vector<int> inputCompolyphony = getInputCompolyphony({MAIN_INPUT_MODE},{MAIN_INPUT});
std::vector<std::vector <int>> inputCompolyphony = getInputCompolyphony({MAIN_INPUT_MODE},{MAIN_INPUT});


compolyChannelsMainOutput = calcOutputCompolyphony(compolyphonyKnobSetting,inputCompolyphony);
Expand All @@ -105,12 +106,18 @@ struct ComputerscareComplexTransformer : ComputerscareComplexBase {


for (int complexOutputChannel = 0; complexOutputChannel < compolyChannelsMainOutput; complexOutputChannel++) {
std::vector<float> mainInputVoltages = getComplexVoltageFromInterleavedInput(complexOutputChannel, MAIN_INPUT, 0, inputCompolyphony[0]);
// DEBUG("%i",complexOutputChannel);


std::vector<float> complexQuadRep = getComplexVoltage(complexOutputChannel, MAIN_INPUT,mainInputMode, wrapMode, inputCompolyphony);

float x = mainInputVoltages[0];
float y = mainInputVoltages[1];
float x = complexQuadRep[0];
float y = complexQuadRep[1];
float r = complexQuadRep[2];
float theta = complexQuadRep[3];

setOutputVoltages(COMPOLY_MAIN_OUT_A,mainOutputMode,complexOutputChannel,x,y,1,.4848);
setOutputVoltages(COMPOLY_MAIN_OUT_A,mainOutputMode,complexOutputChannel,x,y,r,theta);
//setOutputVoltages(COMPOLY_MAIN_OUT_A,mainOutputMode,complexOutputChannel,1,1,1,1);
}


Expand Down
4 changes: 2 additions & 2 deletions src/ComputerscareNomplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ struct ComputerscareNomplexPumbers : ComputerscareComplexBase
int numRealInputChannels = inputs[REAL_IN].getChannels();
int numImaginaryInputChannels = inputs[IMAGINARY_IN].getChannels();

compolyChannelsRectIn = calcOutputCompolyphony(rectInputCompolyphonyKnobSetting,{numRealInputChannels,numImaginaryInputChannels});
compolyChannelsRectIn = calcOutputCompolyphony(rectInputCompolyphonyKnobSetting,{{numRealInputChannels,numImaginaryInputChannels}});

int polarInputCompolyphonyKnobSetting = params[COMPOLY_CHANNELS_POLAR_IN].getValue();

int numModulusInputChannels = inputs[MODULUS_IN].getChannels();
int numArgumentInputChannels = inputs[ARGUMENT_IN].getChannels();

compolyChannelsPolarIn = calcOutputCompolyphony(polarInputCompolyphonyKnobSetting,{numModulusInputChannels,numArgumentInputChannels});
compolyChannelsPolarIn = calcOutputCompolyphony(polarInputCompolyphonyKnobSetting,{{numModulusInputChannels,numArgumentInputChannels}});

}

Expand Down
85 changes: 74 additions & 11 deletions src/complex/ComputerscareComplexBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,35 @@ struct ComputerscareComplexBase : ComputerscareMenuParamModule {
POLAR_SEPARATED
};

std::vector<int> getInputCompolyphony(std::vector<int> inputModeIndices, std::vector<int> inputFirstPortIndices) {
std::vector<int> output;
std::vector<std::vector <int>> getInputCompolyphony(std::vector<int> inputModeIndices, std::vector<int> inputFirstPortIndices) {
std::vector<std::vector <int>> output;

int numInputsToConsider = inputFirstPortIndices.size();



for(int i = 0; i < numInputsToConsider; i++) {
std::vector<int> myStuff;
int inputMode = params[inputModeIndices[i]].getValue();

int portOnePolyphony = inputs[inputFirstPortIndices[i]].getChannels();
int portTwoPolyphony = inputs[inputFirstPortIndices[i]+1].getChannels();

if(inputMode == RECT_INTERLEAVED || inputMode == POLAR_INTERLEAVED) {
int totalPolyphony = portOnePolyphony+portTwoPolyphony;
output.push_back((int) std::ceil((float) totalPolyphony/2));
myStuff.push_back((int) std::ceil((float) totalPolyphony/2));
}
else {
//separated mode
output.push_back(std::max(portOnePolyphony,portTwoPolyphony));
myStuff.push_back(std::max(portOnePolyphony,portTwoPolyphony));

}

myStuff.push_back(portOnePolyphony);
myStuff.push_back(portTwoPolyphony);
output.push_back(myStuff);
}

return output;
}

Expand Down Expand Up @@ -93,15 +99,15 @@ struct ComputerscareComplexBase : ComputerscareMenuParamModule {
}
}

int calcOutputCompolyphony(int knobSetting,std::vector<int> inputCompolyphonyChannels) {
int calcOutputCompolyphony(int knobSetting,std::vector<std::vector <int>> inputCompolyphonyChannels) {
int numInputsToConsider = inputCompolyphonyChannels.size();

int outputCompolyphony;

int maxOfInputsCompolyphony = 0;

for(int i = 0; i < numInputsToConsider; i++) {
maxOfInputsCompolyphony= std::max(maxOfInputsCompolyphony,inputCompolyphonyChannels[i]);
maxOfInputsCompolyphony= std::max(maxOfInputsCompolyphony,inputCompolyphonyChannels[i][0]);
}

//automatic, use max of input channels compolyphony
Expand All @@ -119,6 +125,8 @@ struct ComputerscareComplexBase : ComputerscareMenuParamModule {
}

/*
S
Separated:
Complex 0:
- port0, ch0
Expand All @@ -139,30 +147,85 @@ struct ComputerscareComplexBase : ComputerscareMenuParamModule {
-port0, ch3
*/

std::vector<float> getComplexVoltageFromInterleavedInput(int outputIndex, int firstPortID, int wrapMode,int inputCompolyphony) {
std::vector<float> getComplexVoltageFromSeparatedInput(int outputIndex, int firstPortID, int inputMode,int wrapMode,std::vector <int> inputCompolyphony) {
std::vector<float> output = {};

int firstPortIndex = outputIndex;
int secondPortIndex = outputIndex;
if(wrapMode == WRAP_NORMAL) {
/*
If monophonic, copy ch1 to all
Otherwise use the poly channels
*/
if(inputCompolyphony[1] == 1) {
firstPortIndex = 0;
} else {
firstPortIndex = outputIndex;
}
if(inputCompolyphony[2] == 1) {
secondPortIndex = 0;
} else {
secondPortIndex = outputIndex;
}
}
output.push_back(inputs[firstPortID].getVoltage(firstPortIndex));
output.push_back(inputs[firstPortID+1].getVoltage(secondPortIndex));

return output;
}
std::vector<float> getComplexVoltageFromInterleavedInput(int outputIndex, int firstPortID, int inputMode,int wrapMode,std::vector<int> inputCompolyphony) {
std::vector<float> output = {};
int portIndex = outputIndex >= 8 ? firstPortID + 1 : firstPortID;
int relativeOutputChannelIndex = outputIndex % 8;
int firstChannelIndex=0;


// if(wrapMode == WRAP_NORMAL) {
if(wrapMode == WRAP_NORMAL) {
/*
If monophonic, copy ch1 to all
Otherwise use the poly channels
*/
if(inputCompolyphony == 2) {
if(inputCompolyphony[0] == 2) {
firstChannelIndex = 0;
} else {
firstChannelIndex = relativeOutputChannelIndex*2;
}
// }
// DEBUG("%i",firstChannelIndex);
}
output.push_back(inputs[portIndex].getVoltage(firstChannelIndex));
output.push_back(inputs[portIndex].getVoltage(firstChannelIndex+1));
return output;
}

std::vector<float> getQuad(std::vector<float> ab,int type) {
float x,y,r,theta;
if(type==RECT_INTERLEAVED || type == RECT_SEPARATED) {
x = ab[0];
y = ab[1];
r = std::hypot(x,y);
theta = std::atan2(y,x);
} else {
r = ab[0];
theta = ab[1];
x = r*std::cos(theta);
y = r*std::sin(theta);
}
return {x,y,r,theta};
}





std::vector<float> getComplexVoltage(int outputIndex, int firstPortID, int inputMode,int wrapMode,std::vector<std::vector <int>> inputCompolyphony) {
std::vector<float> mainInputVoltages;
if(inputMode==RECT_INTERLEAVED || inputMode == POLAR_INTERLEAVED) {
mainInputVoltages = getComplexVoltageFromInterleavedInput(outputIndex, firstPortID,inputMode, wrapMode, inputCompolyphony[0]);
} else {
mainInputVoltages = getComplexVoltageFromSeparatedInput(outputIndex, firstPortID,inputMode, wrapMode, inputCompolyphony[0]);
}
return getQuad(mainInputVoltages,inputMode);
}

std::vector<int> getChannelIndicesFromSeparatedInput(int outputIndex, int wrapMode, std::vector<int> channelCounts) {
std::vector<int> output;
for(int i = 0; i < channelCounts.size(); i++) {
Expand Down

0 comments on commit 0b44d32

Please sign in to comment.