// <stat> -> <in> | <out> | <block> | <if> | <loop> | <assign> APTNode* STAT(void) { //printf("STAT node with sym = %s and text = %s \n", currentTok.sym, currentTok.selection); APTNode* parentStatNode = createNonIdAPTNode("<STATtk>"); APTNode* childNode; if (strcmp(currentTok.sym, "SCANFtk") == 0) { childNode = IN(); } else if (strcmp(currentTok.sym, "PRINTFtk") == 0) { childNode = OUT(); } else if (strcmp(currentTok.sym, "IFtk") == 0) { childNode = IF(); } else if (strcmp(currentTok.sym, "LOOPtk") == 0) { childNode = LOOP(); } else if (strcmp(currentTok.sym, "IDtk") == 0) { childNode = ASSIGN(); } else if (strcmp(currentTok.sym, "BEGINtk") == 0) { childNode = BLOCK(); } else errMsg("STATEMENT tok"); addChildNode(parentStatNode, childNode); return parentStatNode; }
void FFT_next(FFT *unit, int wrongNumSamples) { float *in = IN(1); float *out = unit->m_inbuf + unit->m_pos + unit->m_shuntsize; // int numSamples = unit->mWorld->mFullRate.mBufLength; int numSamples = unit->m_numSamples; // copy input memcpy(out, in, numSamples * sizeof(float)); unit->m_pos += numSamples; bool gate = ZIN0(4) > 0.f; // Buffer shunting continues, but no FFTing if (unit->m_pos != unit->m_hopsize || !unit->m_fftsndbuf->data || unit->m_fftsndbuf->samples != unit->m_fullbufsize) { if(unit->m_pos == unit->m_hopsize){ unit->m_pos = 0; } ZOUT0(0) = -1.f; } else { unit->m_pos = 0; if(gate){ scfft_dofft(unit->m_scfft); unit->m_fftsndbuf->coord = coord_Complex; ZOUT0(0) = unit->m_fftbufnum; } else { ZOUT0(0) = -1; } // Shunt input buf down memcpy(unit->m_inbuf, unit->m_inbuf + unit->m_hopsize, unit->m_shuntsize * sizeof(float)); } }
bool Client::network_IN(float dt) { IN(con, conID); if (con->isConnected()) return true; return false; }
static void exit_handler(int32_t signum) { IN(DEBUG_MODEL_MISC, "signum %d", signum); if(_gExitFlag) return; _gExitFlag=1; cmd_queue_release(); menu_release(); menu_queue_release(); i2c_release(); pipe_uninit(); #if(_DEBUG_ == 1 && _DEBUG_TO_FILE_ == 1) if(gDebugToFile == 1) util_debug_file_uninit(); #endif if(SIGQUIT == signum && _gQuitHandler) _gQuitHandler(signum); else if(SIGKILL == signum && _gKillHandler) _gKillHandler(signum); else if(SIGTERM == signum && _gTermHandler) _gTermHandler(signum); else if(SIGINT == signum && _gIntHandler) { debug_print(DEBUG_MODEL_MISC, "kekeke\n"); _gIntHandler(signum); } exit(0); }
// verify a signature against a public sas key. int crypto_verify_signature(unsigned char *sas_key, unsigned char *content, int content_len, unsigned char *signature_block, int signature_len) { IN(); if (signature_len!=SIGNATURE_BYTES) RETURN(WHY("Invalid signature length")); /* reconstitute signed message by putting hash at end of signature */ unsigned char reassembled[signature_len + content_len]; bcopy(signature_block, reassembled, signature_len); bcopy(content, &reassembled[signature_len], content_len); /* verify signature. Note that crypto_sign_open requires m to be as large as signature, even though it will not need the whole length eventually -- it does use the full length and will overwrite the end of a short buffer. */ unsigned char message[sizeof(reassembled)+64]; unsigned long long mlen=0; int result =crypto_sign_edwards25519sha512batch_open(message,&mlen, reassembled,sizeof(reassembled), sas_key); if (result) RETURN(WHY("Signature verification failed")); RETURN(0); }
int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now) { IN(); /* Take frame source and destination and use them to populate mdp->in->{src,dst} SIDs. Take ports from mdp frame itself. Take payload from mdp frame itself. */ overlay_mdp_frame mdp; bzero(&mdp, sizeof(overlay_mdp_frame)); mdp.in.queue = f->queue; mdp.in.ttl = f->ttl; /* Get source and destination addresses */ if (f->destination) bcopy(f->destination->sid,mdp.in.dst.sid,SID_SIZE); else{ // pack the broadcast address into the mdp structure, note that we no longer care about the broadcast id memset(mdp.in.dst.sid, 0xFF, SID_SIZE); } bcopy(f->source->sid,mdp.in.src.sid,SID_SIZE); /* copy crypto flags from frame so that we know if we need to decrypt or verify it */ if (overlay_mdp_decrypt(f,&mdp)) RETURN(-1); /* and do something with it! */ RETURN(overlay_saw_mdp_frame(f, &mdp,now)); OUT(); }
//======================= // PRIVATE //======================= void WebSocket::EvaluateREST(QString msg){ //Parse the message into it's elements and proceed to the main data evaluation RestInputStruct IN(msg); //NOTE: All the REST functionality is disabled for the moment, until we decide to turn it on again at a later time (just need websockets right now - not full REST) if(DEBUG){ qDebug() << "New REST Message:"; qDebug() << " VERB:" << IN.VERB << "URI:" << IN.URI; qDebug() << " HEADERS:" << IN.Header; qDebug() << " BODY:" << IN.Body; } //Now check for the REST-specific verbs/actions if(IN.VERB == "OPTIONS" || IN.VERB == "HEAD"){ RestOutputStruct out; out.CODE = RestOutputStruct::OK; if(IN.VERB=="HEAD"){ }else{ //OPTIONS out.Header << "Allow: HEAD, GET"; out.Header << "Hosts: /syscache"; } out.Header << "Accept: text/json"; out.Header << "Content-Type: text/json; charset=utf-8"; SOCKET->sendTextMessage(out.assembleMessage()); }else{ EvaluateRequest(IN); } }
static void dump_input_buffer(pty_t * pty) { char * c = pty->canon_buffer; while (pty->canon_buflen > 0) { IN(*c); pty->canon_buflen--; c++; } }
void compute() { double * RESTRICT in = this->in; double * RESTRICT out = this->out; int ii, jj; for (int j=MAX(jstart,RADIUS); j<=MIN(n-1-RADIUS,jend); j++) { for (int i=MAX(istart,RADIUS); i<=MIN(n-1-RADIUS,iend); i++) { #if LOOPGEN #include "loop_body_star.incl" #else for (jj=-RADIUS; jj<=RADIUS; jj++) OUT(i,j) += WEIGHT(0,jj)*IN(i,j+jj); for (ii=-RADIUS; ii<0; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); for (ii=1; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); #endif } } }
void NearestN_next(NearestN *unit, int inNumSamples) { GET_BUF int ndims = unit->m_ndims; if((int)bufChannels != (ndims + 3)) { Print("NearestN: number of channels in buffer (%i) != number of input dimensions (%i) + 3\n", bufChannels, ndims); SETCALC(*ClearUnitOutputs); return; } int num = unit->m_num; float* bestlist = unit->m_bestlist; float* inputdata = unit->m_inputdata; for(int i=0; i<inNumSamples; ++i) { if(IN(1)[i] > 0.f) { // If gate > 0 // Get data inputs, ALSO checking whether they've changed bool inputchanged=false; float chanval; for(int chan=0; chan<ndims; ++chan) { chanval = IN(chan + 3)[i]; if(inputdata[chan] != chanval) { inputdata[chan] = chanval; inputchanged = true; } } if(inputchanged) { // init the search: must set the results array to infinitely bad for(int j=0; j<num; ++j) { bestlist[3 * j ] = -1; bestlist[3 * j + 1] = FLT_MAX; bestlist[3 * j + 2] = -1; } // First, recurse from very top to get to the 'first guess' leaf. int firstLeaf = NearestN_descend(1, ndims, inputdata, bufData, bufChannels, bufFrames); // Then ascend back up the full tree (which may itself involve more descend+ascend loops) NearestN_ascend(firstLeaf, 0, ndims, inputdata, bufData, bestlist, num, bufChannels, bufFrames); } } // End gate check // The results should now be in 'bestlist' - let's write them to the output for(int j=0; j< (num*3); ++j) { OUT(j)[i] = bestlist[j]; } } // end loop inNumSamples }
int draw_bitmap(TTF_Bitmap *canvas, TTF_Bitmap *bitmap, int x, int y) { CHECKPTR(canvas); CHECKPTR(bitmap); if (!IN(x, 0, canvas->w-1) || !IN(y, 0, canvas->h-1)) { warn("failed to draw bitmap out of bounds"); return FAILURE; } /* Out of bounds checking is also done in bitmap_set,_get() */ for (int yb = 0; yb < bitmap->h; yb++) { for (int xb = 0; xb < bitmap->w; xb++) { bitmap_set(canvas, x+xb, y+yb, bitmap_get(bitmap, xb, yb)); } } return SUCCESS; }
static size_t redir_lenth(char *s) { size_t n; n = IN(s[0], "012"); n += 1; if (s[n] != '&' || s[n - 1] == '<') return (n + IN(s[n], "<>")); n += 1; if (IN(s[n], "012")) { if (IN(s[n + 1], " \t\"'|&;()`") || !s[n + 1]) return (n + 1); else return (n - 1); } return (n - 1); }
static void I2CswSendBit(uint8_t bit) { if (bit) IN(I2C_SDA); // Pullup SDA = 1 else OUT(I2C_SDA); // Active SDA = 0 I2CswGetBit(); }
int main() { int i,T,n,m=0; ll A[MAX]; ll B[MAX]; scanf("%d",&T); while(T--){ m=0; IN(n); FOR(i,n) IN(A[i]); FOR(i,n) IN(B[i]); FOR(i,n) m=max(m,monkiness(B,A[i],n)-i); printf("%d\n",m); } }
bool CRaspiProcessInterface::readPin(){ if(-1 != mPinNumber){ IN() = digitalRead(mPinNumber); return true; }else{ STATUS() = scmNotInitialised; } return false; }
void compute() { double * RESTRICT in = this->in; double * RESTRICT out = this->out; for (int j=MAX(jstart,RADIUS); j<=MIN(n-1-RADIUS,jend); j++) { for (int i=MAX(istart,RADIUS); i<=MIN(n-1-RADIUS,iend); i++) { for (int jj=-RADIUS; jj<=RADIUS; jj++) { OUT(i-istart,j-jstart) += WEIGHT(0,jj)*IN(i-istart,j-jstart+jj); } for (int ii=-RADIUS; ii<0; ii++) { OUT(i-istart,j-jstart) += WEIGHT(ii,0)*IN(i-istart+ii,j-jstart); } for (int ii=1; ii<=RADIUS; ii++) { OUT(i-istart,j-jstart) += WEIGHT(ii,0)*IN(i-istart+ii,j-jstart); } } } }
void MatchingPResynth_next(MatchingPResynth *unit, int inNumSamples) { GET_BUF int audioplaybackpos = unit->m_audioplaybackpos; float* audiobuf = unit->m_audiobuf; int nactivs = unit->m_nactivs; float* triggerinput = IN(3); float* residualinput = IN(4); for (int i=0; i < inNumSamples; ++i) { // Ensure we keep within internal buffer limit if (audioplaybackpos == bufFrames){ // Shunt the top half down to the start memmove(audiobuf, audiobuf + bufFrames, bufFrames * sizeof(float)); audioplaybackpos = 0; // Clear the 'new' top half Clear(bufFrames, audiobuf + bufFrames); } // If trigger, add the activations to the output buffer if (triggerinput[i] > 0.f){ //printf("Triggered\n"); for(int which=0; which<nactivs; ++which){ int whichchannel = static_cast<int>(IN(5 + which + which )[i]); float magnitude = IN(5 + which + which + 1)[i]; //printf("Outputting channel %i at magnitude %g\n", whichchannel, magnitude); float *readpos = buf->data + whichchannel; for(int j=0; j<bufFrames; ++j){ audiobuf[audioplaybackpos + j] += (*readpos) * magnitude; readpos += bufChannels; } } } // Output the reconstructed version plus residual float residualval = residualinput[i]; OUT(0)[i] = audiobuf[audioplaybackpos] + residualval; ++audioplaybackpos; } unit->m_audioplaybackpos = audioplaybackpos; }
static size_t work_on_quote(char *s, char **bad_sintax) { char quote[3]; quote[0] = s[0]; quote[1] = '\''; quote[2] = 0; if (!IN(quote[0], s + 1)) *bad_sintax = my_strcat(UNMATCHED_TOKEN, quote); return (my_strilen(s + 1, quote[0]) + 2); }
void UGEN_NAME_next( UGEN_NAME* unit, int inNumSamples ){ float *in = IN(0); float *out = OUT(0); for(int i=0; i< inNumSamples; ++i){ val = in[i]; out[i] = val; } }
double R(double x){ //Mills Ratio if (x > 4){ return 1.0 / x; } double N = IC(x); double D = IN(x); if (D < pow(10,-15)){ //machine epsilon return 1.0 / pow(10,-15); } return exp(log(1. - N)-log(D)); }
static uint8_t I2CswGetBit(void) { uint8_t ret; _delay_us(5); IN(I2C_SCL); // Pullup SCL = 1 _delay_us(5); ret = READ(I2C_SDA); OUT(I2C_SCL); // Active SCL = 0 return ret; }
static char *get(char *type, char *line, int itype, int n) { int l; l = hempty(line) + my_strlen(type) + hempty(line + hempty(line) + my_strlen(type)); if (line[l] != '"') lerror(INVALID(itype), n); if (!IN(line + l + 1, '"')) lerror(INVALID(itype), n); return (my_strndup(line + l + 1, my_strilen(line + l + 1, '"'))); }
void FORTE_FB_FT_TN64::alg_REQ(void){ if((cnt() == length()-1)){ cnt() = 0; } else{ cnt() = cnt()+1; }; OUT() = X()[cnt()]; X()[cnt()] = IN(); last() = tx(); }
void buttons_handler__run(void) { uint8_t state = IN(IN__BUTTONS) & (_BV(IN__BUTTON1__PIN) | _BV(IN__BUTTON2__PIN) | _BV(IN__BUTTON3__PIN) | _BV(IN__BUTTON4__PIN)); if ((state & buttons_handler__state) < buttons_handler__state) { // Some button was pressed wdt__reset(); wdt__enable_interrupt(); } else { // Some button was pressed wdt__disable_interrupt(); } buttons_handler__state = state; }
void FORTE_FB_HYST_3::alg_REQ(void){ CIEC_REAL X; X = HYS()*0.5f; if((IN() < VAL1()-X)){ Q1() = true; } else if((IN() > VAL1() + X)){ Q1() = false; }; if((IN() < VAL2()-X)){ Q2() = false; } else if((IN() > VAL2()+X)){ Q2() = true; }; }
int main(void) { ENABLE_PULLUP(IN__BUTTON1); ENABLE_PULLUP(IN__BUTTON2); ENABLE_PULLUP(IN__BUTTON3); ENABLE_PULLUP(IN__BUTTON4); ENABLE_PULLUP(IN__BUTTON5); ENABLE_PULLUP(IN__BUTTON6); ENABLE_PULLUP(UNUSED_D0); ENABLE_PULLUP(UNUSED_D1); led1__init(); led2__init(); led3__init(); while(1) { uint8_t state = IN(IN__BUTTONS) & (_BV(IN__BUTTON1__PIN) | _BV(IN__BUTTON2__PIN) | _BV(IN__BUTTON3__PIN) | _BV(IN__BUTTON4__PIN) | _BV(IN__BUTTON5__PIN) | _BV(IN__BUTTON6__PIN)); if (!(state & _BV(IN__BUTTON1__PIN))) { led1__set(1); led2__set(0); led3__set(0); } else if (!(state & _BV(IN__BUTTON2__PIN))) { led1__set(0); led2__set(1); led3__set(0); } else if (!(state & _BV(IN__BUTTON3__PIN))) { led1__set(1); led2__set(1); led3__set(0); } else if (!(state & _BV(IN__BUTTON4__PIN))) { led1__set(0); led2__set(0); led3__set(1); } else if (!(state & _BV(IN__BUTTON5__PIN))) { led1__set(1); led2__set(0); led3__set(1); } else if (!(state & _BV(IN__BUTTON6__PIN))) { led1__set(0); led2__set(1); led3__set(1); } else { led1__set(0); led2__set(0); led3__set(0); } _delay_ms(50); } }
void MedianTriggered_next_xk(MedianTriggered* unit, int inNumSamples) { float *out = OUT(0); float *in = IN(0); float trig = IN0(1); // Get state and instance variables from the struct float* circbuf = unit->m_circbuf; float* sortbuf = unit->m_sortbuf; int circbufpos = unit->m_circbufpos; int length = unit->m_length; bool length_is_odd = unit->m_length_is_odd; int medianpos = unit->m_medianpos; // This may or may not be recalculated as we go through the loop, depending on triggering float median = unit->m_outval; float curr; int i; for(i=0; i<inNumSamples; ++i){ if(trig > 0.f){ curr = in[i]; circbuf[circbufpos] = curr; circbufpos++; if(circbufpos==length){ circbufpos = 0; } // NOW CALCULATE THE MEDIAN // Copy the data into the buffer for sorting // TODO: Implement the copy more efficiently using memcpy for(int i=0; i<length; ++i){ sortbuf[i] = circbuf[i]; } // Then sort MedianTriggered_SelectionSort(sortbuf, length); // Then update the median median = length_is_odd ? sortbuf[medianpos] : ((sortbuf[medianpos] + sortbuf[medianpos+1]) * 0.5f); } *(out++) = median; } // Store state variables back unit->m_circbufpos = circbufpos; unit->m_outval = median; }
void MeanTriggered_next_xa(MeanTriggered* unit, int inNumSamples) { float *out = OUT(0); float *in = IN(0); float *trig = IN(1); // Get state and instance variables from the struct float* circbuf = unit->m_circbuf; int circbufpos = unit->m_circbufpos; int length = unit->m_length; // This may or may not be recalculated as we go through the loop, depending on triggering float mean = unit->m_mean; float curr; int i, j; for(i=0; i<inNumSamples; ++i){ if(*(trig++) > 0.f){ curr = in[i]; //printf("%g, ", curr); circbuf[circbufpos] = curr; circbufpos++; if(circbufpos==length){ circbufpos = 0; } double total = 0.; for(j=0; j<length; ++j) total += circbuf[j]; mean = (float)(total / length); } *(out++) = mean; } // Store state variables back unit->m_circbufpos = circbufpos; unit->m_mean = mean; }
double* cholesky(double *A, int n) { register int i, j, k; double *L = (double*)calloc(n * n, sizeof(double)); for (i = 0; i < n; ++i) { for (j = 0; j < i; ++j) { L[LIN(i, j)] = A[IN(i, j)]; for (k = 0; k < j; ++k) { L[LIN(i, j)] -= L[LIN(i, k)] * L[LIN(j, k)]; } L[LIN(i, j)] /= L[LIN(j, j)]; } L[LIN(j, j)] = A[IN(j, j)]; for (k = 0; k < i; ++k) { L[LIN(i, i)] -= L[LIN(i, k)] * L[LIN(i, k)]; } L[LIN(i, i)] = sqrt(L[LIN(i, i)]); } return L; }
void mTimerInit(void) { #if defined(_atmega8) TIMSK |= (1 << TOIE0); // Enable Timer0 overflow interrupt TCCR0 = (1 << CS02) | (0 << CS01) | (0 << CS00); // Set timer prescaller to 256 (31250Hz) #else TIMSK0 |= (1 << TOIE0); // Enable Timer0 overflow interrupt TCCR0B = (1 << CS02) | (0 << CS01) | (0 << CS00); // Set timer prescaller to 256 (31250Hz) #endif OUT(BEEPER); SET(BEEPER); // Setup buttons as inputs with pull-up resistors IN(BUTTON_1); IN(BUTTON_2); IN(BUTTON_3); SET(BUTTON_1); SET(BUTTON_2); SET(BUTTON_3); cmdBuf = BTN_STATE_0; }