RandomCrapMess(5) – give some space

Here’s the follow up of this project. I don’t even know if some people find interest in this, but anyway this serve as report diary in digital madness. The more I code that stuff the more I realise that it’s actually a weird module.

Having build a prototype is a good thing to clear some things out. The internal clock isn’t really useful as the module to really shine needs to be “in sync” with an external clock. Therefore I think I’ll remove the clock and transfrom that control into a divider factor for the incoming clock (which could be CV modifiable). The prototype also determined cleary the boundaries of the module. And mostly importantly fixed the hardware, I can’t add buttons and pots now (a relief!).  One can add so many things in code that it may become a real mess to design and build, and most importantly consistent with its primary goal.

Having said that, a pseudo-random gate module based  on Linear Feedback Shift Register is on itself a weird thing and certainly isn’t really a daily-used module. So, as explained in the previous post, I decided to add drum pattern. Pre-made Patterns are great however, I’ll probably change it for some sort of euclidean sequencer  to keep that (pseudo) random concept. If memory space allows it, maybe I could add the tree modes in the chip. But once again, the user interface can become very clumsy and mind-blowing to use.

IMG_0073

Anyway, I make some change on one of the most important fonction on the project mostly because I found it quite ugly and a total non-sens. It allows each registers to be modified in length.

void new_reg_conf(uint8_t chan, uint8_t val){
        uint8_t *p_length = 0; 
	uint8_t *p_taps[4] = {0,0,0,0}; 
	uint16_t *p_register = 0; 
	
	switch(chan) 
	{
		case 0:
		p_length	= &length_4;
		p_taps[0] 	= &lfsr4_taps[0];
		p_taps[1] 	= &lfsr4_taps[1];
		p_taps[2] 	= &lfsr4_taps[2];
		p_taps[3] 	= &lfsr4_taps[3];
		p_register 	= &lfsr_4; 
		break; 
		
		case 1: 
		p_length 	= &length_5;
		p_taps[0] 	= &lfsr5_taps[0];
		p_taps[1] 	= &lfsr5_taps[1];
		p_taps[2] 	= &lfsr5_taps[2];
		p_taps[3] 	= &lfsr5_taps[3];
		p_register 	= &lfsr_5; 
		break;
		
		[...]
	}
	
	switch(val)
	{
		case L_4BIT:
		*p_length = L_4BIT; 
		*p_taps[3] 	= 3;	
		*p_taps[0]	= 1;
		*p_register &= L_4BIT_MASK; 
		break; 
		
		[...]
		
		case L_16BIT:
		*p_length = L_16BIT;
		*p_taps[3] = 15; 
		*p_taps[0] = 2;
		*p_taps[1] = 3;
		*p_taps[2] = 5;
		*p_register &= L_16BIT_MASK; 
		break;
	}
}
	

the ancestor of this fonction re-attributed the value of the array for every chan value passed in it via nested switch cases. It wasn’t really pretty and also very memory space ineficient. For the price of some additional RAM variables, this version makes the code cleaner and most importantly 10% of the code space is saved. Pointers and deferencing is a bit tricky to grasp at first, but very handy in some applications ! In this case, the reattribuation case is written only once and actually dispatch value into memory location directly. (Needless to say that the variable related to the register are declared in the same file). I’m pretty sure this can be reduced even more, not smart enough at the moment !

It’s funny sometimes you code things up, hoping for it to work, it does and you still question why. As it seemed so complicated, you’re only expectation is in the faillure.

For those interested in C programming and don’t know where to start, I recomend Richard Buckland Courses.

Advertisements

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s