Get total number of voices in subpatch


#1

Hello,

I wanted to do a polyphonic sound with each voice panned differently. With the patch/polyindex object I can get access to the current voice number. But how do I get access to the total number of voices? Looking at the C++-Code generated, I can't see where this info would be available. voice.polyIndex gives the voice number but the only place that actually contains the total number of voices are a bunch of arrays (e.g. int8_t notePlaying[8]; and int32_t voicePriority[8];) and a bunch of other places, including this loop:

public: void Init(rootc * _parent) {
[..]
int vi; for(vi=0;vi<8;vi++) {
   voice *v = &getVoices()[vi];
   v->polyIndex = vi;
   v->common = this;
   v->Init(&getVoices()[vi]);
[..]

The upper limit (in my example: 8) is hardcoded into this loop and I don't see how I could access this information.
My idea to work around this was to create a polyCount object that has some sort of shared variable in it that each of the instantiated voices increases by one. However, that doesn't work as none of the code segments (local data, init, krate, srate, dispose) allow to declare such a shared type. I can have a static uint8_t counter = 0in the local data section, but that inline initializer doesn't compile with ISO C++, so it doesn't work. My last idea was to use C-style linkage but then it would not be possible to have multiple polyphonic subpatches in a main patch.

So... I'm starting to guess that there might be a preprocessor statement or some sort of placeholder that I can use in the code instead. Is there something like this?

Thanks!


#2

@TheSlowGrowth I am following this. I was jus trying to get the polyindex to work with panning the other day. Since polyindex is unipolar(1.2.3.4.5...) it is not really good for panning as it is. Cause when you use the polyindex for panning it will offset from center and then offset each voice with +1... So all voice will tilt to the right...

I didnt find a way to make the voice become bipolar(0, -1, +2, -3) So each voice are seperated left/right. If you find a way PLEASE post it here. I am really interested. My questions about it is from here:


#3

My plan was to make an object that outputs a bipolar signal like this:

voice       |   1   |  2   |  3  |  4  |  5  |
signal/64.0 |  -1   | -0.5 |  0  | 0.5 |  1  |

or

voice       |   1   |  2    |   3   |  4  |   5   |   6   |  7  |
signal/64.0 |  -1   | -0.66 | -0.33 |  0  |  0.33 |  0.66 |  1  |

and so on. You could simply add a math/*c object after that to create a variable pan spread.
The only problem is that I don't get any info about the number of voices. So I can't do the scaling properly.


#4

@TheSlowGrowth

Thank you for the detailed answer. I think this is what I am looking for :slight_smile: This would be a super great object IMO fot those bipolar signals.

I think this can also me done manually, in same manner that you would do with the pan spread. Not ideal to have to * manually but, better than how the poly index works now, where everything just tilts to the right. for pan at least, works great for many other things. WOuld those number be adjustable if I embed the object and mod it myself. But of course, if you cannot get number of voice this is probably not gonna work.


#5

Any news on this?

Like @TheSlowGrowth, I can't find any way of getting the number of voices. A #define NVOICES n would be a good addition to xpatch.cpp. I suppose one could make a module that captures the maximun for polyIndex, but that's getting a bit whacky-hacky...


#6

EDIT: see the correct solution by @johannes here.


Just an idea i had:

in the patcher:

I add a i outlet connected to a const value set to 1.

out of the polyphonic patcher, the outlets i implicitly add together depending on the number of voices :


Now, in order to have this number in the patcher, I add an inlet i into the patcher...

... and feed it with the (implicitly summed) oulet i.

:thinking: It seems a little far fetched to me, but it seems to work.


#7

Nice one! Probably reliable enough :slight_smile:

I had a go with parent->polyIndex, indirectly capturing its maximum programmatically (outlet_nvoices = 1) and that accumulates in the outlets, like in your example. In any case, for a module to get to know the number of voices without being in a poly sub patch (and capturing max of polyIndex), or without using a patch method like you demonstrated, something else is needed.


#8

I think that the inlet will be at 0 at the first control cycle. It can cause trouble in some cases.


#9

Yes. In some modules I defer processing until after the first iteration to handle that, and sometimes with more than one such deferred processing phase (for other reasons).


#10

Thank you, this is a nice temporary solution!

(Though it's rather hacky and uses unnecessary amounts of SRAM. So I'd still prefer a clean, official solution.)


#11

sorry for my late reply,
"attr_poly" will magically convert into the number of voices (or 1 if it is not a polyphonic subpatch).


#12

great, that was what I expected to find when I wrote my first post.
There should be a documentation abouth those attributes somewhere.

I'll make a polyCount object and the spread object that I described earlier.


#13

Okay, I made two objects, which I will later put in the community library.

TSG/patch/numVoices.axo - outputs the number of voices in a polyphonic subpatch
TSG/patch/polySpread.axo - outputs a number spread between -64 and +64, depending on the current voice number and the total number of voices.

I don't have my axoloti at hand, so I can't test it right now. If anyone of you wants to have a look now, I'll attach them here:
numVoices.axo (515 Bytes)
polySpread.axo (734 Bytes)
polySpread.axh (5.2 KB)

If you have a moment to chek them out, I would appreciate it. Otherwise I'll do it when I'm home later, then put them in the community library and make a post in my contribution-thread.