Help with code translation

Can someone translate in English for me what these lines of code are doing?

#define setPhoneme(p)    (PORTD = (PORTD & 3) | ((p) << 2))
#define setInflection(i) (PORTB = (PORTB & 0xfc) | ((i) & 0x03))
#define setStrobe(s)     (PORTB = (PORTB & 0xfb) | ((s) ? 4:0))

Thanks!

Well, phoneme selection appears to be on bits 2 and 3 of PORTD, inflection on bits 0 and 1 of PORTB, and strobe is on bit 2 of PORTB

AWOL: Well, phoneme selection appears to be on bits 2 and 3 of PORTD, inflection on bits 0 and 1 of PORTB, and strobe is on bit 2 of PORTB

I think phoneme is bits 2-7 on PORTD but is stored in p from bit 0 to 5. Thanks for getting started. I thought about replying but was a bit lazy and turned away for a bit to stare on a research paper.

Quite right, 2 - 7 it is. My mistake. 64 phonemes, maximum

Thanks, makes sense when compared to the connections, ie pins D2-10 are being used, but I am not familiar with the way the pins are being assigned (port manipulation + bit math??).

I do not see p or i being declared as variables, are these general variables available in the Arduino PDE library space?

buchacho:
Thanks, makes sense when compared to the connections, ie pins D2-10 are being used, but I am not familiar with the way the pins are being assigned (port manipulation + bit math??).

I do not see p or i being declared as variables, are these general variables available in the Arduino PDE library space?

Exactly, (port manipulation + bit math??)

No, p and i are, en, I don’t know a name. They’re dummy place holders to be substituted when the compiler processes the define.

Say if you have in your code: setPhoneme(50);, then in your real code to be compiled, after the pre-compiler directives such as #define are processed, it looks like (PORTD = (PORTD & 3) | ((50) << 2));

It is a straight 1:1 substitution relation that even kids can do.

So with those declarations, if I want to say only set pin D2 to high, would I be able to do it like this:

setPhoneme = 1;

And if I want to send random values of 0-63 (in binary) on pins 2-7:

randNumber = random(63);
setPhoneme = randNumber;

buchacho: So with those declarations, if I want to say only set pin D2 to high, would I be able to do it like this:

setPhoneme = 1;

No you do setPhoneme(1). That sets D2 to high and D3-D7 to low, while D0 and D1 are not changed.

You need to do exactly as defined in the #define