void Resize(Window w, unsigned width, unsigned height) { if (w != topWindow) return; /* ignore illegal resizes */ LIMIT(width, MIN_TOP_WIDTH, MAX_TOP_WIDTH); LIMIT(height, MIN_TOP_HEIGHT, MAX_TOP_HEIGHT); top_width = width; top_height = height; if (!drawWindow) return; if (radar_score_mapped) draw_width = top_width - 258; else draw_width = top_width; draw_height = top_height; Check_view_dimensions(); Net_flush(); XResizeWindow(dpy, drawWindow, draw_width, draw_height); if (dbuf_state->type == PIXMAP_COPY) { XFreePixmap(dpy, drawPixmap); drawPixmap = XCreatePixmap(dpy, drawWindow, draw_width, draw_height, dispDepth); } players_height = top_height - (RadarHeight + ButtonHeight + 2); XResizeWindow(dpy, playersWindow, players_width, players_height); Talk_resize(); Config_resize(); }
void run_adding_AutoPan(LADSPA_Handle Instance, unsigned long SampleCount) { AutoPan * ptr = (AutoPan *)Instance; LADSPA_Data * input_L = ptr->input_L; LADSPA_Data * input_R = ptr->input_R; LADSPA_Data * output_L = ptr->output_L; LADSPA_Data * output_R = ptr->output_R; LADSPA_Data freq = LIMIT(*(ptr->freq),0.0f,20.0f); LADSPA_Data depth = LIMIT(*(ptr->depth),0.0f,100.0f); LADSPA_Data gain = db2lin(LIMIT(*(ptr->gain),-70.0f,20.0f)); unsigned long sample_index; LADSPA_Data phase_L = 0; LADSPA_Data phase_R = 0; for (sample_index = 0; sample_index < SampleCount; sample_index++) { phase_L = 1024.0f * freq * sample_index / ptr->SampleRate + ptr->Phase; while (phase_L >= 1024.0f) phase_L -= 1024.0f; phase_R = phase_L + 512.0f; while (phase_R >= 1024.0f) phase_R -= 1024.0f; *(output_L++) += *(input_L++) * gain * ptr->run_adding_gain * (1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase_L]); *(output_R++) += *(input_R++) * gain * ptr->run_adding_gain * (1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase_R]); } ptr->Phase = phase_L; while (ptr->Phase >= 1024.0f) ptr->Phase -= 1024.0f; }
void run_adding_Tremolo(LADSPA_Handle Instance, unsigned long SampleCount) { LADSPA_Data * input; LADSPA_Data * output; LADSPA_Data freq; LADSPA_Data depth; LADSPA_Data gain; Tremolo * ptr; unsigned long sample_index; LADSPA_Data phase = 0.0f; ptr = (Tremolo *)Instance; input = ptr->InputBuffer_1; output = ptr->OutputBuffer_1; freq = LIMIT(*(ptr->Control_Freq),0.0f,20.0f); depth = LIMIT(*(ptr->Control_Depth),0.0f,100.0f); gain = db2lin(LIMIT(*(ptr->Control_Gain),-70.0f,20.0f)); for (sample_index = 0; sample_index < SampleCount; sample_index++) { phase = 1024.0f * freq * sample_index / ptr->SampleRate + ptr->Phase; while (phase >= 1024.0f) phase -= 1024.0f; *(output++) += *(input++) * ptr->run_adding_gain * gain * (1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase]); } ptr->Phase = phase; while (ptr->Phase >= 1024.0f) ptr->Phase -= 1024.0f; }
void run_Tremolo(LV2_Handle Instance, uint32_t SampleCount) { float * input; float * output; float freq; float depth; float gain; Tremolo * ptr; double sample_index; float phase = 0.0f; ptr = (Tremolo *)Instance; input = ptr->InputBuffer_1; output = ptr->OutputBuffer_1; freq = LIMIT(*(ptr->Control_Freq),0.0f,20.0f); depth = LIMIT(*(ptr->Control_Depth),0.0f,100.0f); gain = db2lin(LIMIT(*(ptr->Control_Gain),-70.0f,20.0f)); for (sample_index = 0; sample_index < SampleCount; sample_index++) { phase = 1024.0f * freq * sample_index / ptr->SampleRate + ptr->Phase; while (phase >= 1024.0f) phase -= 1024.0f; *(output++) = *(input++) * gain * (1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase]); } ptr->Phase = phase; while (ptr->Phase >= 1024.0f) ptr->Phase -= 1024.0f; }
void run_adding_Vibrato(LADSPA_Handle Instance, unsigned long SampleCount) { Vibrato * ptr = (Vibrato *)Instance; LADSPA_Data freq = LIMIT(*(ptr->freq),0.0f,PM_FREQ); LADSPA_Data depth = LIMIT(LIMIT(*(ptr->depth),0.0f,20.0f) * ptr->sample_rate / 200.0f / M_PI / freq, 0, ptr->buflen / 2); LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f)); LADSPA_Data wetlevel = db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f)); LADSPA_Data * input = ptr->input; LADSPA_Data * output = ptr->output; unsigned long sample_index; unsigned long sample_count = SampleCount; LADSPA_Data in = 0.0f; LADSPA_Data phase = 0.0f; LADSPA_Data fpos = 0.0f; LADSPA_Data n = 0.0f; LADSPA_Data rem = 0.0f; LADSPA_Data s_a, s_b; if (freq == 0.0f) depth = 0.0f; for (sample_index = 0; sample_index < sample_count; sample_index++) { in = *(input++); phase = COS_TABLE_SIZE * freq * sample_index / ptr->sample_rate + ptr->phase; while (phase >= COS_TABLE_SIZE) phase -= COS_TABLE_SIZE; push_buffer(in, ptr->ringbuffer, ptr->buflen, &(ptr->pos)); fpos = depth * (1.0f - cos_table[(unsigned long) phase]); n = floorf(fpos); rem = fpos - n; s_a = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n); s_b = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n + 1); *(output++) += ptr->run_adding_gain * wetlevel * ((1 - rem) * s_a + rem * s_b) + drylevel * read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, ptr->buflen / 2); } ptr->phase += COS_TABLE_SIZE * freq * sample_index / ptr->sample_rate; while (ptr->phase >= COS_TABLE_SIZE) ptr->phase -= COS_TABLE_SIZE; *(ptr->latency) = ptr->buflen / 2; }
unsigned int revers_filter(unsigned int color, UNUSED t_opt *opt) { unsigned char comp[3]; decomp_color(color, comp); comp[0] = LIMIT(2.0 * (128 - comp[0]) + comp[0], 0, 255); comp[1] = LIMIT(2.0 * (128 - comp[1]) + comp[1], 0, 255); comp[2] = LIMIT(2.0 * (128 - comp[2]) + comp[2], 0, 255); return (recomp_color(comp)); }
static void i80286_data_descriptor_full(i80286_state *cpustate, int reg, UINT16 selector, int cpl, UINT32 trap, UINT16 offset, int size) { if (PM) { UINT16 desc[3]; UINT8 r; UINT32 addr; /* selector format 15..3 number/address in descriptor table 2: 0 global, 1 local descriptor table 1,0: requested privileg level must be higher or same as current privileg level in code selector */ if ((reg != SS) && !IDXTBL(selector)) { cpustate->sregs[reg]=0; cpustate->limit[reg]=0; cpustate->base[reg]=0; cpustate->rights[reg]=0; cpustate->valid[reg]=0; return; } if ((addr = i80286_selector_address(cpustate,selector)) == -1) throw trap; desc[0] = ReadWord(addr); desc[1] = ReadWord(addr+2); desc[2] = ReadWord(addr+4); r = RIGHTS(desc); if (!SEGDESC(r)) throw trap; if (reg == SS) { if (!IDXTBL(selector)) throw trap; if (DPL(r)!=cpl) throw trap; if (RPL(selector)!=cpl) throw trap; if (!RW(r) || CODE(r)) throw trap; if (!PRES(r)) throw TRAP(STACK_FAULT,(IDXTBL(selector)+(trap&1))); } else { if ((DPL(r) < PMAX(cpl,RPL(selector))) && (!CODE(r) || (CODE(r) && !CONF(r)))) throw trap; if (CODE(r) && !READ(r)) throw trap; if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(IDXTBL(selector)+(trap&1))); } if (offset+size) { if ((CODE(r) || !EXPDOWN(r)) && ((offset+size-1) > LIMIT(desc))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap; if (!CODE(r) && EXPDOWN(r) && ((offset <= LIMIT(desc)) || ((offset+size-1) > 0xffff))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap; } SET_ACC(desc); WriteWord(addr+4, desc[2]); cpustate->sregs[reg]=selector; cpustate->limit[reg]=LIMIT(desc); cpustate->base[reg]=BASE(desc); cpustate->rights[reg]=RIGHTS(desc); } else { cpustate->sregs[reg]=selector; cpustate->base[reg]=selector<<4; } cpustate->valid[reg]=1; }
/** * @brief AND each * * @param dataOut * @param dataIn * @param row * @param col * @param step * @param KernelArray * @param m * @param n */ void fandFilter (char *dataOut, char *dataIn, int row,int col,int step,int* KernelArray,int m,int n ) { unsigned char bits[9] ; int flag[3]; if(KernelArray == 0) return ; for(int rgb =0;rgb < 3;rgb++){ bits[0] = LIMIT(dataIn P(row-1,col-1,step,rgb)); bits[1] = LIMIT(dataIn P(row-1,col, step,rgb)); bits[2] = LIMIT(dataIn P(row-1,col+1,step,rgb)); bits[3] = LIMIT(dataIn P(row ,col-1,step,rgb)); bits[4] = LIMIT(dataIn P(row ,col ,step,rgb)); bits[5] = LIMIT(dataIn P(row ,col+1,step,rgb)); bits[6] = LIMIT(dataIn P(row+1,col-1,step,rgb)); bits[7] = LIMIT(dataIn P(row+1,col ,step,rgb)); bits[8] = LIMIT(dataIn P(row+1,col+1,step,rgb)); flag[rgb] = (bits[4] * KA[4] ) ^ ( ( bits[1] * KA[1] ) | ( bits[3] * KA[3] ) | ( bits[5] * KA[5] ) | ( bits[7] * KA[7] ) ); //if(flag) // dataOutP(row,col,step,rgb) = 255; //else // dataOutP(row,col,step,rgb) = 0; } if(flag[0] | flag[1] | flag[2]){ dataOutP(row,col,step,0) = 0; dataOutP(row,col,step,1) = 0; dataOutP(row,col,step,2) = 0; }else{ dataOutP(row,col,step,0) = dataInP(row,col,step,0); dataOutP(row,col,step,1) =dataInP(row,col,step,1); dataOutP(row,col,step,2) =dataInP(row,col,step,2); } }
unsigned int gamma_filter(unsigned int color, double gamma) { unsigned char comp[3]; gamma = 1.0 / gamma; decomp_color(color, comp); comp[0] = LIMIT(encode_srgb(comp[0], gamma), 0, 255); comp[1] = LIMIT(encode_srgb(comp[1], gamma), 0, 255); comp[2] = LIMIT(encode_srgb(comp[2], gamma), 0, 255); return (recomp_color(comp)); }
void SetPwm_5(int16_t pwm_3,int16_t pwm_4,s16 min,s16 max) { s16 pwm_tem_3,pwm_tem_4; pwm_tem_3 = pwm_3 ; pwm_tem_3 = LIMIT(pwm_tem_3,min,max); pwm_tem_4 = pwm_4 ; pwm_tem_4 = LIMIT(pwm_tem_4,min,max); TIM5->CCR4 = pwm_tem_4 + INIT_DUTY; //4 TIM5->CCR3 = pwm_tem_3 + INIT_DUTY; //3 }
void audio_callback(void* data, Uint8* stream, int length) { int j; SDL_AudioSpec spec = *((SDL_AudioSpec*)data); float factor = 126.f; if(stuff[i]) { int totl = spec.freq / (stuff[i]/2); switch(method) { case SQUARE: for(j = 0; j < length; ++j) { // half the period output MAX if(k < totl/2) { stream[j] = factor; // half output 0 } else { stream[j] = 0; } k = (k + 1) % totl; } break; case TRIANGLE: for(j = 0; j < length; ++j) { // first quarter-period, increasing linear function [0..MAX] if(k < totl/4) { stream[j] = (Uint8)LIMIT(factor * ((float)k / (totl/4.f))); // second and third quarters, decreasing linear function [MAX..-MAX] } else if(k < 3*totl/4) { stream[j] = (Uint8)LIMIT(factor * ( ((float)totl/2.f - (float)k)/(totl/4.f))); // fourth quarter, increasing linear function [-MAX..0] } else { stream[j] = (Uint8)LIMIT(factor * ( (float)(k - totl) / (totl/4.))); } k = (k + 1) % totl; } break; case SINE: for(j = 0; j < length; ++j) { // I don't understand what the deal with the frequency is // that I DON'T have to multiply by 2 here... // Anyway, compared with a reference sound and indeed this // is the correct frequency (somehow) stream[j] = (Uint8)(factor * sin(k * stuff[i] * M_PI / (float)spec.freq)); k = (k + 1) % totl; } break; } } else { // if we aren't supposed to output any sound, set the buffer to 0 memset(stream, 0, length); } }
void question(int x) { MIN(x++, 12); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: side effects in the 1st macro argument 'A' MIN(34, x++); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: side effects in the 2nd macro argument 'B' LIMIT(x++, 0, 100); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: side effects in the 1st macro argument 'X' LIMIT(20, x++, 100); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: side effects in the 2nd macro argument 'A' LIMIT(20, 0, x++); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: side effects in the 3rd macro argument 'B' }
unsigned int saturation(unsigned int color, double val) { double pert; unsigned char comp[3]; decomp_color(color, comp); pert = sqrt(comp[0] * comp[0] * 0.299 + comp[1] * comp[1] * 0.587 + comp[2] * comp[2] * 0.114); comp[0] = LIMIT(pert + (comp[0] - pert) * val, 0 , 255); comp[1] = LIMIT(pert + (comp[1] - pert) * val, 0 , 255); comp[2] = LIMIT(pert + (comp[2] - pert) * val, 0 , 255); return (recomp_color(comp)); }
unsigned int apply_contrast(unsigned int color, t_opt *opt) { unsigned char comp[3]; decomp_color(color, comp); comp[0] = LIMIT((((double)comp[0] / 255 - 0.5) * opt->contrast + 0.5) * 255, 0, 255); comp[1] = LIMIT((((double)comp[1] / 255 - 0.5) * opt->contrast + 0.5) * 255, 0, 255); comp[2] = LIMIT((((double)comp[2] / 255 - 0.5) * opt->contrast + 0.5) * 255, 0, 255); return (recomp_color(comp)); }
void SimpleVolumeMeter::setValue( float peak, float hold ) { LIMIT( peak, 0.f, 1.f ); LIMIT( hold, 0.f, 1.f ); if( m_bStereo || m_peak[0] != peak || m_hold[0] != hold ) { m_bStereo = false; m_peak[0] = peak; m_hold[0] = hold; _requestRender(); } }
unsigned int filter_grey(unsigned int color) { unsigned char comp[3]; unsigned char o_color[3]; decomp_color(color, comp); o_color[0]= LIMIT(comp[0] * 0.33 + comp[1] * 0.33 + comp[2] * 0.33, 0, 255); o_color[1]= LIMIT(comp[0] * 0.33 + comp[1] * 0.33 + comp[2] * 0.33, 0, 255); o_color[2]= LIMIT(comp[0] * 0.33 + comp[1] * 0.33 + comp[2] * 0.33, 0, 255); return (recomp_color(o_color)); }
unsigned int filter_sepia(unsigned int color) { unsigned char comp[3]; unsigned char o_color[3]; decomp_color(color, comp); o_color[0]= LIMIT(comp[0] * 0.393 + comp[1] * 0.769 + comp[2] * 0.189, 0, 255); o_color[1]= LIMIT(comp[0] * 0.349 + comp[1] * 0.686 + comp[2] * 0.168, 0, 255); o_color[2]= LIMIT(comp[0] * 0.272 + comp[1] * 0.534 + comp[2] * 0.131, 0, 255); return (recomp_color(o_color)); }
/* Swap two items on the playlist. */ static void plist_swap (struct plist *plist, const int a, const int b) { assert (plist != NULL); assert (LIMIT(a, plist->num)); assert (LIMIT(b, plist->num)); if (a != b) { struct plist_item t; t = plist->items[a]; plist->items[a] = plist->items[b]; plist->items[b] = t; } }
/* Set the time tags field for the item. */ void plist_set_item_time (struct plist *plist, const int num, const int time) { int old_time; assert (plist != NULL); assert (LIMIT(num, plist->num)); if (!plist->items[num].tags) { plist->items[num].tags = tags_new (); old_time = -1; } else if (plist->items[num].tags->time != -1) old_time = plist->items[num].tags->time; else old_time = -1; if (old_time != -1) { plist->total_time -= old_time; plist->items_with_time--; } if (time != -1) { plist->total_time += time; plist->items_with_time++; } plist->items[num].tags->time = time; plist->items[num].tags->filled |= TAGS_TIME; }
void Cannon_set_option(cannon_t *cannon, const char *name, const char *value) { Item_t item; const char *origname = name; /* Remove possible cannon prefix from option name. */ if (!strncasecmp(name, "cannon", 6)) name += 6; item = Item_by_option_name(name); if (item != NO_ITEM) { cannon->initial_items[item] = atoi(value); return; } if (!strcasecmp(name, "smartness")) { int smartness = atoi(value); LIMIT(smartness, 0, CANNON_SMARTNESS_MAX); cannon->smartness = smartness; return; } if (!strcasecmp(name, "shotspeed")) { float shot_speed = atof(value); /* limit ? */ cannon->shot_speed = shot_speed; return; } warn("This server doesn't support option %s for cannons.", origname); }
static void vMotorsApplyCommands(motors_command_t command) { const int PWML = LIMIT(COMMAND_TO_PWM(command.motor.left), MIN_PWM, MAX_PWM); const int PWMR = LIMIT(COMMAND_TO_PWM(command.motor.right), MIN_PWM, MAX_PWM); // Here we disable interrupts to ensure that the same command will // be applied to the two motors at the same time. Moreover for a // single motor we want the PWMs to be fully synchronized. portDISABLE_INTERRUPTS(); TIM_SetCompare1(TIM5, PWML); TIM_SetCompare2(TIM5, PWML); TIM_SetCompare3(TIM5, PWMR); TIM_SetCompare4(TIM5, PWMR); portENABLE_INTERRUPTS(); }
int evrow(XEvent *e) { int y = e->xbutton.y - borderpx; LIMIT(y, 0, win.th - 1); return y / win.ch; }
void Text::Draw() { if (textDyn.size() == 0) return; if (!this->IsVisible()) return; GXColor c = color; c.a = this->GetAlpha(); int newSize = (int) (size * GetScale()); if (newSize != currentSize) { currentSize = LIMIT(newSize, 1, 100); if (wText) textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize); } u16 lineheight = newSize + 6; for (u32 i = 0; i < textDyn.size(); i++) { if (!filling) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + i * lineheight, 0, textDyn[i], currentSize, c, style, 0, maxWidth); } }
void plist_set_tags (struct plist *plist, const int num, const struct file_tags *tags) { int old_time; assert (plist != NULL); assert (LIMIT(num, plist->num)); assert (tags != NULL); if (plist->items[num].tags && plist->items[num].tags->time != -1) old_time = plist->items[num].tags->time; else old_time = -1; if (plist->items[num].tags) tags_free (plist->items[num].tags); plist->items[num].tags = tags_dup (tags); if (old_time != -1) { plist->total_time -= old_time; plist->items_with_time--; } if (tags->time != -1) { plist->total_time += tags->time; plist->items_with_time++; } }
/* Given an index, return the string at that position in a list. */ char *lists_strs_at (const lists_t_strs *list, int index) { assert (list); assert (LIMIT(index, list->size)); return list->strs[index]; }
rgb color(double iter) { rgb res; double r, g, b, c; c = (iter - startiter) / (enditer - startiter); r = pow(c, er); g = pow(c, eg); b = pow(c, eb); res.r = LIMIT(r, 0.0, 1.0) * 255; res.g = LIMIT(g, 0.0, 1.0) * 255; res.b = LIMIT(b, 0.0, 1.0) * 255; return res; }
int evcol(XEvent *e) { int x = e->xbutton.x - borderpx; LIMIT(x, 0, win.tw - 1); return x / win.cw; }
void SimpleVolumeMeter::setValue( float leftPeak, float leftHold, float rightPeak, float rightHold ) { LIMIT( leftPeak, 0.f, 1.f ); LIMIT( leftHold, 0.f, 1.f ); LIMIT( rightPeak, 0.f, 1.f ); LIMIT( rightHold, 0.f, 1.f ); if( !m_bStereo || m_peak[0] != leftPeak || m_hold[0] != leftHold || m_peak[1] != rightPeak || m_hold[1] != rightHold ) { m_bStereo = true; m_peak[0] = leftPeak; m_peak[1] = rightPeak; m_hold[0] = leftHold; m_hold[1] = rightHold; _requestRender(); } }
/* Set tags title of an item. */ void plist_set_title_tags (struct plist *plist, const int num, const char *title) { assert (LIMIT(num, plist->num)); if (plist->items[num].title_tags) free (plist->items[num].title_tags); plist->items[num].title_tags = xstrdup (title); }
double falloff(int x, int y) { double fx = (x - 512.0) / 512.0; double fy = (y - 512.0) / 512.0; double f = ((islandSize - islandEdge) - sqrt(fx * fx + fy * fy)) / islandEdge; f = pow(f, 3.0) + 1.0; f = LIMIT(f, 0.0, 1.0); return f; }