Object oriented coding


#1

I've been thinking about a module that has several different modulation codes in it as possible functions and then the ability to select any of these codes independently for the 8 outputs, thus object oriënted coding (as someone told me)..

though, could anyone explain to me how I would define such function in the local data? Or point me to a module that is using this approach?

eg. for each output I want to be able to select an LFO (multiple functions for basic waveforms) or an envelope or a simple, 16 step sequencer.


#2

wow ehm... I thought, let's just try something out... randomly.... and thadaaaaa I actually hit bullseye in one throw... hahahaha
so, no need to explain anymore XD


#3

oh my.... this is really really nice..


#4

I'm not sure what you're talking about is Object-Orientated coding, as such. Are you talking about using functions, defined in the Local Data section of your object's XML?

a|x


#5

yes, that's what I mean... (sorry, I'm still a noob :wink: haha)

but I got it working, at the moment I got 2 modulation outputs where I can select what kind of LFO shape I want to select for each output, reset&gate each independently and apply FM amount with any of the other selected modulations (gonna be 8 in total)


#6

oeh lala, this is super nice with my shufflingsequencer, automator and morphor modules...
now I've also build in the same preset- save/load functions as those


#7

ok, so I Do have a question about those functions...

yesterday I tried to made an oscillator, which would only need one single function for the oscillator.
I hoped by recalling that function within a for-loop, I could generate multiple voices.
Though it seems that the internal parameters of this function should be arrays instead of normal int32_t...
( eg. uint32_t phase[8] for 8 possible phase generations).

When I tried using the "normal" "uint32_t phase", it just added all these phases together and output a single wave with a frequency of the sum of all the frequencies of all the voices..

I did this like (simplified version):

in local data:
uint32_t phase;
uint32_t sine;
int32_t out[8];
int32_t sum;
int32_t oscillator(freq)
{
phase+=freq;
SINE2TINTERP(phase,sine)
}

in S-rate data:
sum=0;
for(i=0;i<8;i++)
{
oscillator(pitch[i]);
out[i]=sine;
sum+=out[i]>>6;
}
outlet_out=sum;

but it seems I have to change both phase and sine (and additional declarations) into arrays for it to work, like:
uint32_t phase[8];
int32_t sine[8];

So.. I think I'm doing something wrong here, or not?
I hoped to be able to design a simple function for an oscillator, which could then be called upon multiple times to generate an # amount of voices (by feeding it array-values for frequency, FM etc).
Or is it just necessary to also make an array of phases?


#8

I'm a bit confused about your code, but your function should look something like this:

int32_t oscillator(int32_t freq, uint8_t oscIndex) {
	phase[oscIndex] += freq;
	SINE2TINTERP(phase,sine);
}

It also needs to either return a value, or set a value in an array directly.

You could do:

int32_t oscillator(int32_t freq, uint8_t oscIndex) {
    	phase[oscIndex] += freq;
    	return SINE2TINTERP(phase,sine);
}

or:

void oscillator(int32_t freq, uint8_t oscIndex) {
    	phase[oscIndex] += freq;
    	osc[oscIndex] = SINE2TINTERP(phase,sine);
}

I'm at work at the moment, so can't write much. Try looking at this page, and see if that answers your questions.

http://www.tutorialspoint.com/cprogramming/c_functions.htm

a|x


#9

ah thanks, this is enough info.
I already did this to fix the "problem" but hoped to find a more elegant solution. Though it seems I just got to live with this :wink:


#10

Functions are very useful, once you get your head around them.

One thing to remember though: although using them can dramatically reduce the size of your code, in terms of what the processor has to do, calling a function, say, 10 times is directly equivalent to writing the same chunk of code 10 times.

a|x


#11

I know, but still it's really useful as the code itself is much smaller and thus asks less time to be written to the axoloti.
In big projects that's a huge plus as it doesn't go into a time-out.
Also, I want to add multiple oscillator codes inside a single oscillator. Then be able to select between 1 and 4 voices and how they inter-modulate each other. This way, you also go around the sample-buffer that is used outside the modules, which means you'll have an oscillator with a 1-sample delay for all modulations :stuck_out_tongue:

but I decided now, that I'm first going write a function to generate the phases of the seperate oscillators and then write functions for the shape of these phases. If I'm right, these shapes don't need to be in an array, as they'r being updated by another value each pass-by, and thus have no memory of themselves (unlike the phase of an oscillator or the position of a filter).


#12

You can have one function call another function, which can sometimes be helpful.

a|x