Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/19/2018 in Posts

  1. Yes I just adapt it to a signed value, normally a lfo is bipolar. declare 2 new static function ///////////////////////////////////////////////////////////////////////////// // Local variables ///////////////////////////////////////////////////////////////////////////// u16 phase =0; u16 curve =32768; u16 amp_cc =65535: ///////////////////////////////////////////////////////////////////////////// // Local Prototypes ///////////////////////////////////////////////////////////////////////////// static s16 XXX_hlp_log_signed(u16 curv, s16 signed_amp); static u16 XXX_hlp_log_unsigned(u16 curv, u16 abs_amp); Add the function ///////////////////////////////////////////////////////////////////////////// // help func: return the Log/Antilog of a given signed value ///////////////////////////////////////////////////////////////////////////// static s16 XXX_hlp_log_signed(u16 curv, s16 signed_amp){ s16 log_amp; if(signed_amp<-32767)signed_amp=-32767; // limit signed to -32767 to -32767 if(signed_amp<0){ u16 abs_amp = (u16)((0-signed_amp) << 1); log_amp = (s16)(0-(XXX_hlp_log_unsigned(curv, abs_amp)>>1)); }else{ log_amp = (s16)(XXX_hlp_log_unsigned(curv, (u16)(signed_amp<<1))>>1); } return log_amp; } ///////////////////////////////////////////////////////////////////////////// // help func: return the Log/Antilog of a given unsugned value // note: math.h must be included ///////////////////////////////////////////////////////////////////////////// static u16 XXX_hlp_log_unsigned(u16 curv, u16 abs_amp){ u16 log_amp; float curv_f, amp_f; if (curv < 32768){ // reducing curve to a float between 0 and 1 curv_f=(float)(32767-curv)/32767.0; // reducing column to a float between 0 and 1 amp_f = (1.0-((float)(abs_amp/65535.0))); // lin > log log_amp = (u16)(abs_amp + ((log(amp_f)*curv_f*amp_f)*65535)); }else{ // reducing curve to a float between 0 and 1 curv_f=(float)(curv-32767)/32767.0; // reducing column to a float between 0 and 1 amp_f = (float)(abs_amp/65535.0); // lin > log log_amp = (u16)(abs_amp - ((log(amp_f)*curv_f*amp_f)*65535)); } return log_amp; } now you will be able to use it everywhere with signed or unsigned 16bit value A TRIANGLE LFO with amplitude, phase and curve parameters: // calc an unipolar triangle(0 to 65535) depending on x(time) between 0 and 65355 and phase between 0 and 65355 u16 time = (u16)(x + phase + 16384) ; // apply the phase u16 tri = (time < 32768) ? time << 1 : ((65535 - time) << 1)); // now we shift down the unipolar to get a bipolar one s16 signed_tri = (s16)(tri - 32768); // call log function, curve is unsigned 16bit value! signed_tri = XXX_hlp_log_signed(curve, signed_tri); // apply amplitude parameter, amp_cc between 0 and 65355 signed_tri = (s16)(signed_tri*amp_cc/65535); // we shift back the triangle to unsigned 16 bit value, for use with lcd and aout tri = (u16)(signed_tri + 32768); Result: More? ;)
    1 point
  2. Ahah. Mine is a true log/antilog, this is math! see the function applied to a triangle LFO with variable speed and amplitude
    1 point
  3. Adding curve response Log and Antilog: first point after adding Math lib, it seems the loading sequence of libraries is wrong. the `__errno' compilation error. To resolve it we have to set the loading sequence, just change this line in your Makefile: LIBS= to LIBS = -lm -lgcc -lc works for me ;) Now the curve: in declaration add the curve variable, I use MIOS Studio to control it u8 curve = 64; in MIDI_Notify CC#1 is curve parameter ///////////////////////////////////////////////////////////////////////////// // This hook is called when a MIDI package has been received ///////////////////////////////////////////////////////////////////////////// void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package) { // store incoming ModWheel values to curve if( midi_package.type == CC && midi_package.cc_number == 1 ) curve = (u8)midi_package.value; } Ok now we will change the function to: ///////////////////////////////////////////////////////////////////////////// // This hook is called before the shift register chain is scanned ///////////////////////////////////////////////////////////////////////////// void APP_SRIO_ServicePrepare(void) { column +=128; //column increment(x axis) if( column > 0xffff){ // 65535 max column = 0; // this will clear/reset the bitmap ! memset(bitmap_array, 0, sizeof bitmap_array); } // log/antilog function if(curve<64){ // reducing curve to a float between 0 and 1 float curv_f=(float)(64-curve)/64.0; // reducing column to a float between 0 and 1 float column_f = (1.0-((float)(column/65536.0))); // line value is line = (u32)(column + ((log(column_f)*curv_f*column_f)*65536)); }else{ // reducing curve to a float between 0 and 1 float curv_f=(float)(curve-64)/64.0; // reducing column to a float between 0 and 1 float column_f = (float)(column/65536.0); // line value is line = (u32)(column - ((log(column_f)*curv_f*column_f)*65536)); } u8 x= (u8)(column>>9); //reducing 16 bit to 128pixels(7bits) u8 y= (u8)(line>>11); //reducing 16 bit to 64pixels(6bits) // set the pixel MIOS32_LCD_BitmapPixelSet(bitmap, x, 63-y, 1); // 63-y is to invert the y axis } result: Voilà! I hope it will help you ;) have a good sunday! Bruno
    1 point
×
×
  • Create New...