Jump to content

Recommended Posts

Posted

thank you for the hints. I solved it the following way:

unsigned char Math_Scale10BitTo7Bit(unsigned int v, unsigned int min10Bit, unsigned int max10Bit, unsigned char min7Bit, unsigned char max7Bit) __wparam
{
	// scales an 7-bit (0-255) value between min & max
	unsigned char scaled = 0;
	unsigned long promille;
	if(min7Bit <= 0){min7Bit = 0;}
	if(max7Bit > 127){max7Bit = 127;}
	if(min10Bit <= 0){min10Bit = 0;}
	if(max10Bit > 1023){max10Bit = 1023;}

	if(min10Bit <= v && v < max10Bit && min7Bit < max7Bit){
		promille = (unsigned long)(v);
		promille = (promille - min10Bit) * 1000 / (max10Bit - min10Bit);
		scaled = (max7Bit - min7Bit + 1) * promille / 1000 + min7Bit;
	}else if(min10Bit > v){
		scaled = min7Bit;
	}else if(max10Bit <= v){
		scaled = max7Bit;
	}
	return scaled;
}
this way I can call the method like this:
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
  // a pot has been moved, send CC#<pin-number> at channel 1
  MIOS_MIDI_BeginStream();
  MIOS_MIDI_TxBufferPut(0xb0); // CC at channel 1
  MIOS_MIDI_TxBufferPut(pin);  // pin number corresponds to CC number
  MIOS_MIDI_TxBufferPut(Math_Scale10BitTo7Bit(MIOS_AIN_PinGet(last_ain_pin), AIN_10BITMIN, AIN_10BITMAX, AIN_7BITMIN, AIN_7BITMAX));
   MIOS_MIDI_EndStream();

  // notify display handler in DISPLAY_Tick() that AIN value has changed
  last_ain_pin = pin;
  app_flags.DISPLAY_UPDATE_REQ = 1;
}

and not to forget:

AIN_DEADBAND  = 5 (I dont really understand how deadband really works, this value is experimental)

plus http://www.ucapps.de/mios/mios_libsdcc_v2_5_0.zip - which is the library for my humble java-like calculations.

Posted

Hi t0gg1e4u,

although your code seems mathmatically correct, one should add that the heavy use of unoptimized divisions (and to some extend multiplications) may introduce various codesize and timing problems;

surely not if you just turn slowly one knob at a time, but I'd expect strange behaviours under heavy load (many quick changes on multiple inputs).

Please understand this as a final comment: if it works for you, it should be fine  ;)

Best,

Michael

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...