Custom Object Mixed Variable Types


#1

I'm trying to make an emulation of the Turing Machine Euro shift-register pattern-generator.

The original uses 2 analogue shift-register ICs in series. I thought of using a 16bit number to store the bits that need to be shifted. I can rotate the bits, then use bit-shifting to extract two 8bit numbers.

What I'm wondering is, would it be better to use a 32bit int instead of the 16bit uint I was thinking of?

If 16bit is ok, what's the best way to convert the value to the signed 32bit format required for the output value?

Can I just assign the 16bit uint16_t value to the 32bit int32_t outlet?

Sorry for the stupid questions. Am still struggling with variable type-related issues.

Talking of which.. I'm also struggling to do a simple numerical comparison between the value of a 32bit unsigned param and the sampled 32bit signed value from a '+-' inlet.
I just want to branch based on whether one is greater than the other, but can't seem to get it to work properly using the '<' operator.

Any tips on either issue much appreciated.

a|x


#2

Hi Toneburst,

I have a customized versiont of the Turing Machine shift register :
- 1 circular buffer of 8 bits
- possibility to set an initial value in the buffer
- possibility to read value at the beginning of each cycle
- random input : set to 0, buffer shift without bit inversion, set to 64 buffer shift with all bits inverted. Between 0 and 64, bits are inverted randomly.
- trigmask input : apply bitwise "and" operator on buffer with trigmask value : if not equal to zero, pulse on "O" output.
- trig input : shift register if rising edge.

turing.axo (2.0 KB)

turing.axh (14.6 KB)


JeromeB Contributions
#3

Cool! I'll have a look at how you did it.
Still want to work on my own version though, as this is as much about learning how to work with custom object coding as anything else, for me.

Is your object on GitHub, or anywhere I can look at the code? I'm away from my laptop with only iOS devices for the next week, but would love to see what makes your object tick. Maybe you can post the source here, if it's not available elsewhere online, and it's not too long.

a|x


#4

If you search to see the code, just open turing.axo file with a text editor or, better, use axoloti patcher, menu "edit object definition" then "k-rate code".
But I can copy here the k-rate code if you have not axoloti next week :

outlet_o = 0;
if(inlet_trig > 0 && !ntrig){
    ntrig = 1;

    if((counter % 8) == 0){
        bufferinitvalue = buffer;
        counter = 0;
        if(inlet_initvalue != initvalue){
            buffer = (uint8_t)inlet_initvalue;
            initvalue = (uint8_t)inlet_initvalue;
        }
    }
    counter++;
 
    if((GenerateRandomNumber() % 255) < (inlet_random >> 19)){
        newbit = ~buffer & 0x1;
    } else {
        newbit = buffer & 0x1;
    }
    buffer = (buffer >> 1) | (newbit << 7);

    if((inlet_trigmask & buffer) > 0) outlet_o = 1;
}

if(!(inlet_trig > 0)) ntrig = 0;

outlet_note = buffer << 19;
outlet_initvalue = bufferinitvalue;

And local data and init code :

uint8_t ntrig;
uint8_t buffer;
uint8_t newbit;
uint8_t counter;
uint8_t initvalue;
uint8_t bufferinitvalue;

ntrig = 0;
buffer = 1;
counter = 0;
initvalue = 0;
bufferinitvalue = 0;

#5

Thanks, that's cool.

I discovered I can open the .axo file you posted directly in Safari on my iPhone. Didn't get time to tell you, earlier.

I see you're using 8bit ints, and not doing anything special when it comes to assigning the final value to the output. I'd assumed you'd need to cast it to 32bit or something.

I'll let you know how I get on with my version when I get back from holiday. I want to add a few twists to the formula, and maybe knock up a couple of companion objects with similar functionality to the Turing Expander modules.

Possibilities, possibilities..

Thanks again,

a|x


#6

Are you sure ? I think upcast is safe, mostly for unsigned integer, no ?


#7

I'd assumed based on no knowledge :wink:

I've done quite a bit of coding, but only really with higher-level languages, where variable types don't have to be explicitly declared, so still shakey on this stuff.

It makes sense that converting from fewer to more bits works, though, since nothing is lost, whereas going the other way might be more problematic.

a|x


#8

I think standard ISOC89 or 99 specifies that is safe, but i am not sure... C have a poor type system.

Please, share your future turing machine version ! Don't hesitate if I can help you.


#9

Thanks JeromeB. I'll let you know how I get on, when I return from my week away.

a|x


#10

Love this object and use it in everything.

Haven’t figured out a method to change the number of steps in the sequence—ideas?


#11

Hi @InvisibleMan,

It's possible to create a sequence of periodic notes but it will not be a "turing machine" clone.
I think it's possible to create a bigger circular buffer and use just the least significant bits. I will look at it.

Here a version with a euclidean sequencer : https://sebiik.github.io/community.axoloti.com.backup/t/jeromeb-contributions/1419/30?u=jeromeb
I use the output (an integer of 8 bits) as an index of a table of pentatonic notes.

I have to push a few objects on the repository. Soon.