/* resume file reading */ static void oggread_resume(t_oggread *x) { if(x->x_fd > 0) { x->x_stream = 1; clock_delay(x->x_clock, 0); post("oggread~: RESUME"); } else post("oggread~: encoder not initialised"); }
static void record_tick(t_record *x) { double timesince = clock_gettimesince(x->x_clocklasttick); if (timesince >= RECORD_REDRAWPAUSE) { arsic_redraw((t_arsic *)x); x->x_clocklasttick = clock_getlogicaltime(); } else clock_delay(x->x_clock, RECORD_REDRAWPAUSE - timesince); }
static void xeqithook_autodelay(t_xeqit *it, int argc, t_atom *argv) { t_xeq *x = (t_xeq *)it->i_owner; if (x->x_clock) { clock_delay(x->x_clock, x->x_clockdelay = it->i_playloc.l_delay * x->x_tempo); x->x_whenclockset = clock_getsystime(); } }
/*-----------------------------------------------------------------------------------*/ void beep_beep(int i) { if(onoroff == ON) { /* Beep. */ P2OUT |= BEEPER_BIT; clock_delay(i); P2OUT &= ~BEEPER_BIT; } }
static void *tcpclient_child_connect(void *w) { t_tcpclient *x = (t_tcpclient*) w; struct sockaddr_in server; struct hostent *hp; int sockfd; if (x->x_fd >= 0) { error("%s_child_connect: already connected", objName); return (x); } /* create a socket */ sockfd = socket(AF_INET, SOCK_STREAM, 0); #ifdef DEBUG post("%s: send socket %d\n", objName, sockfd); #endif if (sockfd < 0) { sys_sockerror("tcpclient: socket"); return (x); } /* connect socket using hostname provided in command line */ server.sin_family = AF_INET; hp = gethostbyname(x->x_hostname); if (hp == 0) { sys_sockerror("tcpclient: bad host?\n"); return (x); } memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length); /* assign client port number */ server.sin_port = htons((u_short)x->x_port); if (x->x_verbosity) post("%s: connecting socket %d to port %d", objName, sockfd, x->x_port); /* try to connect */ if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0) { sys_sockerror("tcpclient: connecting stream socket"); sys_closesocket(sockfd); return (x); } x->x_fd = sockfd; x->x_addr = ntohl(*(long *)hp->h_addr); /* outlet_float is not threadsafe ! */ // outlet_float(x->x_obj.ob_outlet, 1); x->x_connectstate = 1; x->x_blocked = 0; /* use callback instead to set outlet */ clock_delay(x->x_clock, 0); return (x); }
// 1/16th second LED blink. void blink_LEDs(unsigned char ledv) { unsigned char current_leds; current_leds = leds_get(); leds_on(ledv); clock_delay(125); if(current_leds == LEDS_RED) { leds_off(ledv & (~LEDS_RED)); } else { leds_off(ledv); } }
/*---------------------------------------------------------------------------*/ void cc2420_init(void) { uint16_t reg; { int s = splhigh(); cc2420_arch_init(); /* Initalize ports and SPI. */ DISABLE_FIFOP_INT(); FIFOP_INT_INIT(); splx(s); } /* Turn on voltage regulator and reset. */ SET_VREG_ACTIVE(); //clock_delay(250); OK SET_RESET_ACTIVE(); clock_delay(127); SET_RESET_INACTIVE(); //clock_delay(125); OK /* Turn on the crystal oscillator. */ strobe(CC2420_SXOSCON); /* Turn off automatic packet acknowledgment. */ reg = getreg(CC2420_MDMCTRL0); reg &= ~AUTOACK; setreg(CC2420_MDMCTRL0, reg); /* Turn off address decoding. */ reg = getreg(CC2420_MDMCTRL0); reg &= ~ADR_DECODE; setreg(CC2420_MDMCTRL0, reg); /* Change default values as recomended in the data sheet, */ /* correlation threshold = 20, RX bandpass filter = 1.3uA. */ setreg(CC2420_MDMCTRL1, CORR_THR(20)); reg = getreg(CC2420_RXCTRL1); reg |= RXBPF_LOCUR; setreg(CC2420_RXCTRL1, reg); /* Set the FIFOP threshold to maximum. */ setreg(CC2420_IOCFG0, FIFOP_THR(127)); /* Turn off "Security enable" (page 32). */ reg = getreg(CC2420_SECCTRL0); reg &= ~RXFIFO_PROTECTION; setreg(CC2420_SECCTRL0, reg); cc2420_set_pan_addr(0xffff, 0x0000, NULL); cc2420_set_channel(26); process_start(&cc2420_process, NULL); }
static void pipe_list(t_pipe *x, t_symbol *s, int ac, t_atom *av) { t_hang *h = (t_hang *) getbytes(sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec)); t_gpointer *gp, *gp2; t_pipeout *p; int i, n = x->x_n; t_atom *ap; t_word *w; h->h_gp = (t_gpointer *)getbytes(x->x_nptr * sizeof(t_gpointer)); if (ac > n) { if (av[n].a_type == A_FLOAT) x->x_deltime = av[n].a_w.w_float; else pd_error(x, "pipe: symbol or pointer in time inlet"); ac = n; } for (i = 0, gp = x->x_gp, p = x->x_vec, ap = av; i < ac; i++, p++, ap++) { switch (p->p_atom.a_type) { case A_FLOAT: p->p_atom.a_w.w_float = atom_getfloat(ap); break; case A_SYMBOL: p->p_atom.a_w.w_symbol = atom_getsymbol(ap); break; case A_POINTER: gpointer_unset(gp); if (ap->a_type != A_POINTER) pd_error(x, "pipe: bad pointer"); else { *gp = *(ap->a_w.w_gpointer); if (gp->gp_stub) gp->gp_stub->gs_refcount++; } gp++; default: break; } } for (i = 0, gp = x->x_gp, gp2 = h->h_gp, p = x->x_vec, w = h->h_vec; i < n; i++, p++, w++) { if (p->p_atom.a_type == A_POINTER) { if (gp->gp_stub) gp->gp_stub->gs_refcount++; w->w_gpointer = gp2; *gp2++ = *gp++; } else *w = p->p_atom.a_w; } h->h_next = x->x_hang; x->x_hang = h; h->h_owner = x; h->h_clock = clock_new(h, (t_method)hang_tick); clock_delay(h->h_clock, (x->x_deltime >= 0 ? x->x_deltime : 0)); }
static void imagebang_bang(t_imagebang *x) { t_glist* glist = glist_getcanvas(x->glist); if(x->flashing) { sys_vgui(".x%lx.c itemconfigure %lximage -image %lx_imagebang \n", glist, x,x->image_a); clock_delay(x->clock_brk, x->clockbrk); //x->flashed = 1; } else { sys_vgui(".x%lx.c itemconfigure %lximage -image %lx_imagebang \n", glist, x,x->image_b); x->flashing = 1; } clock_delay(x->clock_flash, x->clockflash); outlet_bang(x->outlet); if(x->send && x->send->s_thing ) pd_bang(x->send->s_thing); }
void magicGlass_updateText(t_magicGlass *x, int moved) { //fprintf(stderr,"magicglass_updateText\n"); int bgSize; x->x_display_font = sys_hostfontsize(glist_getfont(x->x_c)); if (x->x_visible) { if (!moved) { char *color; if (x->x_issignal || strcmp(x->x_old_string, x->x_string)) { color = "#ffffff"; } else { color = "#e87216"; clock_delay(x->x_flashClock, MG_CLOCK_FLASH_DELAY); } sys_vgui(".x%x.c itemconfigure magicGlassText -text {%s} -fill %s -font {{%s} -%d %s}\n", x->x_c, x->x_string, color, sys_font, x->x_display_font, sys_fontweight); } else { sys_vgui(".x%x.c itemconfigure magicGlassText -text {%s}\n", x->x_c, x->x_string); } if (strlen(x->x_string) > 0) { if (strlen(x->x_string) > x->x_maxSize) x->x_maxSize = strlen(x->x_string); } bgSize = x->x_x + (sys_fontwidth(x->x_display_font) * x->x_maxSize) + 26; //fprintf(stderr,"%d %d %d : %d %d\n", sys_fontheight(x->x_display_font), sys_fontwidth(x->x_display_font), x->x_maxSize, x->x_x, bgSize); sys_vgui(".x%x.c coords magicGlassText %d %d\n", x->x_c, x->x_x + 20, x->x_y); sys_vgui(".x%x.c coords magicGlassLine %d %d %d %d %d %d\n", x->x_c, x->x_x + 8, x->x_y, x->x_x + 13, x->x_y + 5, x->x_x + 13, x->x_y - 5); sys_vgui(".x%x.c coords magicGlassBg %d %d %d %d\n", x->x_c, x->x_x + 13, x->x_y - (int)(sys_fontheight(x->x_display_font)/2) - 3, bgSize, x->x_y + (int)(sys_fontheight(x->x_display_font)/2) + 3); } }
//---------------------------------------------------------------------------------------------------------------- // udmx_list: a list received in the main inlet // // update dmx buffer, send immediately if we can //---------------------------------------------------------------------------------------------------------------- void udmx_list(t_udmx *x, t_symbol *s, short ac, t_atom *av) { t_uint16 i,chan,val,change_min,change_max; change_min = 512; change_max = 0; for(i=0; i<ac; ++i,av++) { #ifdef PUREDATA // compiling for PUREDATA if (av->a_type==A_FLOAT) val = av->a_w.w_float; else val = 0; if (val > 255) val = 255; if (val < 255) val = 0; #else // compiling for MaxMSP if (av->a_type==A_LONG) val = MIN(MAX(av->a_w.w_long, 0), 255); else if (av->a_type==A_FLOAT) { val = MIN(MAX(av->a_w.w_float * 255., 0), 255); } else val = 0; #endif // Max/PD switch chan = x->channel+i; if (val != x->dmx_buffer[chan]) { x->dmx_buffer[chan] = val; if (change_min > chan) change_min = chan; if (change_max < chan) change_max = chan; } } if (change_min > change_max) return; // if there are no changes do nothing if (x->clock_running) { // we're over the speed limit, track changes for later if (change_min < x->channel_changed_min) x->channel_changed_min = change_min; if (change_max > x->channel_changed_max) x->channel_changed_max = change_max; } else { if (change_max - change_min) udmx_send_range(x,change_min,change_max); else udmx_send_single (x,change_min); if (x->speedlim) { // start clock -> prevent sending over speed limit #ifdef PUREDATA // compiling for PUREDATA clock_delay(x->m_clock,x->speedlim); #else // compiling for MaxMSP clock_fdelay(x->m_clock,x->speedlim); #endif // Max/PD switch x->clock_running = 1; } } }
void bang_output(t_bang *x, t_symbol* s, long argc, t_atom* argv) { x->f_active = 1; ebox_invalidate_layer((t_ebox *)x, gensym("background_layer")); ebox_redraw((t_ebox *)x); outlet_bang(x->f_out); if(ebox_getsender((t_ebox *) x)) pd_bang(ebox_getsender((t_ebox *) x)); clock_delay(x->f_clock, 100); }
void testsample_perform64(t_testsample *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam) { if (x->x_vectorcountdown) { x->x_vectorcountdown--; return; } if (!x->x_hasrun) { memcpy(x->x_samples, ins[0]+x->x_offset, sizeof(t_double) * x->x_samplecount); clock_delay(x->x_clock, 0); x->x_hasrun = true; } }
// Set the channel fast and discard the first wrong readings void my_set_channel(int ch) { int k, temp; SPI_SETCHANNEL_SUPERFAST(357+((ch-11)*5)); // Approx. 292 us // Discard first 16 bad readings CC2420_SPI_ENABLE(); for (k=0; k<=16; k++) { MY_FASTSPI_GETRSSI(temp); } clock_delay(1); CC2420_SPI_DISABLE(); }
t_int *centroid_perform(t_int *w) { t_float *in = (t_float *)(w[1]); t_centroid *x = (t_centroid *)(w[2]); t_int n = (int)(w[3]); t_int *myintin = (t_int *)in; t_int *myintBuf1 = (t_int *)(x->Buf1); t_int *myintBuf2 = (t_int *)(x->Buf2); t_int *myintBufFFT = (t_int *)(x->BufFFT); t_int i, index = 0, cpt = n, maxindex; t_int overlapindex = x->BufSize - x->c_overlap; t_float *TmpBuf = x->Buf1; // Copy input samples into FFT buffer while ((x->BufWritePos < x->BufSize) && (cpt > 0)) { myintBuf1[x->BufWritePos] = myintin[index]; x->BufWritePos++; index++; cpt--; } // When Buffer is full... if (x->BufWritePos >= x->BufSize) { // Save overlapping samples into Buffer 2 for (i=0; i<x->c_overlap; ++i) myintBuf2[i] = myintBuf1[overlapindex+i]; maxindex = n - index + x->c_overlap; // Copy the rest of incoming samples into Buffer 2 for (i=x->c_overlap; i<maxindex; ++i) { myintBuf2[i] = myintin[index]; index++; } x->BufWritePos = maxindex; // Make a copy of Buffer 1 into Buffer FFT for computation outside the perform function for (i=0; i<x->BufSize; ++i) myintBufFFT[i] = myintBuf1[i]; // Go for the FFT outside the perform function with a delay of 0 ms! clock_delay(x->c_clock,0); // Swap buffers x->Buf1 = x->Buf2; x->Buf2 = TmpBuf; } return (w+4); }
void thresh_list(t_thresh *x, t_symbol *s, short ac, t_atom *av) { short i,upto; x->t_time = gettime(); upto = MIN(ac+x->t_ac,MAXSIZE); for (i=x->t_ac; i < upto; i++,av++) { x->t_av[i] = *av; } x->t_ac = upto; clock_delay(x->t_clock,x->t_interval); }
static t_int *train_perform(t_int *w) { t_train *x = (t_train *)(w[1]); int nblock = (int)(w[2]); t_float *in1 = (t_float *)(w[3]); t_float *in2 = (t_float *)(w[4]); t_float *in3 = (t_float *)(w[5]); t_float *out = (t_float *)(w[6]); float rcpksr = x->x_rcpksr; double ph = x->x_phase; double tfph = ph + SHARED_UNITBIT32; t_shared_wrappy wrappy; int32_t normhipart; int on = x->x_on; int edge = 0; wrappy.w_d = SHARED_UNITBIT32; normhipart = wrappy.w_i[SHARED_HIOFFSET]; while (nblock--) { double onph, offph; float period = *in1++; wrappy.w_d = *in3++ + SHARED_UNITBIT32; wrappy.w_i[SHARED_HIOFFSET] = normhipart; onph = wrappy.w_d - SHARED_UNITBIT32; wrappy.w_d = onph + *in2++ + SHARED_UNITBIT32; wrappy.w_i[SHARED_HIOFFSET] = normhipart; offph = wrappy.w_d - SHARED_UNITBIT32; if (offph > onph ? ph < offph && ph >= onph : ph < offph || ph >= onph) { if (!on) on = edge = 1; *out++ = 1.; } else { on = 0; *out++ = 0.; } if (period > rcpksr) /* LATER rethink */ tfph += rcpksr / period; /* LATER revisit (profiling?) */ wrappy.w_d = tfph; wrappy.w_i[SHARED_HIOFFSET] = normhipart; ph = wrappy.w_d - SHARED_UNITBIT32; } x->x_phase = ph; x->x_on = on; if (edge) clock_delay(x->x_clock, 0); return (w + 7); }
static void t3_delay_float(t_t3_delay *x, t_floatarg t3_bang) { double dticks; int iticks; if(t3_bang < 0) t3_bang = 0; dticks = (x->x_deltime + (double)t3_bang)/x->x_ticks2ms; iticks = (int)dticks; x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); }
void enter_ISCP_simple() { enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate PGDlow(); // initial value for programming mode PGClow(); // initial value for programming mode clock_delay(); // dummy tempo VDDon(); //high, (inverted) DelayMs( 100 ); VPPon(); //high, (inverted) DelayMs( 100 ); }
/*---------------------------------------------------------------------------*/ void leds_blink(void) { /* Blink all leds. */ unsigned char inv; inv = ~(leds ^ invert); leds_invert(inv); clock_delay(400); leds_invert(inv); }
void xeq_start(t_xeq *x) { if (x->x_clock) { #if 0 post ("start delay %f", x->x_autoit.i_playloc.l_delay); #endif clock_delay(x->x_clock, x->x_clockdelay = x->x_autoit.i_playloc.l_delay * x->x_tempo); x->x_whenclockset = clock_getsystime(); } }
/*------------------------------------ spaceballCreate ---*/ static void * spaceballCreate(t_symbol * addOrDelta, const long pollRate) { SpaceballData * xx = static_cast<SpaceballData *>(object_alloc(gClass)); if (xx) { xx->fPollClock = NULL; xx->fPollQueue = NULL; xx->fBufferPos = xx->fDelayCounter = 0; xx->fButtons = 0; xx->fChunkPulseSent = xx->fInited = xx->fNextCharEscaped = xx->fOutputBlocked = false; xx->fReset = xx->fSkipping = xx->fModeDelta = xx->fStopping = false; if ((0 > pollRate) || (MAX_POLL_RATE < pollRate)) { LOG_ERROR_2(xx, OUTPUT_PREFIX "invalid polling rate (%ld) for device", pollRate) xx->fPollRate = SER_SAMPLE_RATE; } else { xx->fPollRate = (pollRate ? pollRate : SER_SAMPLE_RATE); } /* Set up our connections and private data */ xx->fProxy = proxy_new(xx, 1L, &xx->fInletNumber); xx->fErrorBangOut = static_cast<t_outlet *>(bangout(xx)); xx->fChunkSendOut = static_cast<t_outlet *>(bangout(xx)); xx->fDataSendOut = static_cast<t_outlet *>(outlet_new(xx, 0L)); /* list, int */ xx->fSampleBangOut = static_cast<t_outlet *>(bangout(xx)); xx->fDataOut = static_cast<t_outlet *>(outlet_new(xx, 0L)); /* normally just a list */ xx->fPollClock = MAKE_CLOCK(xx, spaceballProcessClock); xx->fPollQueue = MAKE_QELEM(xx, spaceballProcessQueue); if (! (xx->fProxy && xx->fErrorBangOut && xx->fDataSendOut && xx->fChunkSendOut && xx->fSampleBangOut && xx->fDataOut && xx->fPollClock && xx->fPollQueue)) { LOG_ERROR_1(xx, OUTPUT_PREFIX "unable to create port or clock for device") freeobject(reinterpret_cast<t_object *>(xx)); xx = NULL; } else { xx->fResetDuration = ((2000 + xx->fPollRate - 1) / xx->fPollRate); xx->fInitDuration = ((1000 + xx->fPollRate - 1) / xx->fPollRate); if (addOrDelta != gEmptySymbol) { spaceballSetMode(xx, addOrDelta); } clock_delay(xx->fPollClock, xx->fPollRate); } } return xx; } // spaceballCreate
void hoa_3d_scope_perform64(t_hoa_3d_scope *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam) { for(long i = 0; i < numins; i++) { Signal<t_sample>::copy(sampleframes, ins[i], 1, x->f_signals+i, numins); } Signal<t_sample>::scale(numins * sampleframes, x->f_gain, x->f_signals); if(x->f_startclock) { x->f_startclock = 0; clock_delay(x->f_clock, 0); } }
static void t3_metro_float(t_t3_metro *x, t_floatarg t3_bang) { double dticks; int iticks; if(t3_bang < 0) t3_bang = 0; dticks = (double)t3_bang/x->x_ticks2ms; iticks = (int)dticks; x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); x->x_hit = 1; }
void hammerpanel_save(t_hammerfile *f, t_symbol *inidir, t_symbol *inifile) { if (f = f->f_savepanel) { if (inidir) f->f_inidir = inidir; else /* LATER ask if we can rely on s_ pointing to "" */ f->f_inidir = (f->f_currentdir ? f->f_currentdir : &s_); f->f_inifile = (inifile ? inifile : &s_); clock_delay(f->f_panelclock, 0); } }
int adxl_enable(void) { // enable adc adc_on(); ADC12CTL0 |= MSC; clock_delay(20000); ADC12CTL0 |= REFON; // 1.5V reference ADC12CTL1 |= CONSEQ_1; // sequence of channels clock_delay(20000); // configure adc channels ADC12MCTL0 = 0 + SREF_0; //channel 0, x axis, A1 ADC12MCTL1 = 1 + SREF_0; //channel 1, y axis, A2 ADC12MCTL2 = 2 + SREF_0; //channel 2, z axis, A3 ADC12MCTL3 = INCH_11 + EOS + SREF_0; // channel 3, (AVcc-AVss)/2 printf("%d,%d,%d,%d\n",ADC12MCTL0,ADC12MCTL1,ADC12MCTL2,ADC12MCTL3); return 1; }
/*! \param tm relative time between periodic events (in seconds) \param data user data \return true on success \note the first event will be delayed by tm */ bool flext::Timer::Periodic(double tm,void *data) { userdata = data; period = tm; #if FLEXT_SYS == FLEXT_SYS_PD clock_delay(clk,tm*1000.); #elif FLEXT_SYS == FLEXT_SYS_MAX clock_fdelay(clk,tm*1000.); #else #error Not implemented #endif return true; }
void enter_ISCP_P16_Vpp() { // P16F62X, P16F62XA, P12F629, P12F6XX, P16F87; //VPP first enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate PGDlow(); // initial value for programming mode PGClow(); // initial value for programming mode clock_delay(); // dummy tempo VPPon(); DelayMs( 100 ); VDDon(); DelayMs( 100 ); }
static void rvu_tilde_float(t_rvu_tilde *x, t_floatarg f) { if(f == 0.0f) { clock_unset(x->x_clock_metro); x->x_started = 0; } else { clock_delay(x->x_clock_metro, x->x_metro_time); x->x_started = 1; } }
static t_int *threshold_tilde_perform(t_int *w) { t_sample *in1 = (t_sample *)(w[1]); t_threshold_tilde *x = (t_threshold_tilde *)(w[2]); int n = (t_int)(w[3]); if (x->x_deadwait > 0) x->x_deadwait -= x->x_msecpertick; else if (x->x_state) { /* we're high; look for low sample */ for (; n--; in1++) { if (*in1 < x->x_lothresh) { clock_delay(x->x_clock, 0L); x->x_state = 0; x->x_deadwait = x->x_lodeadtime; goto done; } } } else { /* we're low; look for high sample */ for (; n--; in1++) { if (*in1 >= x->x_hithresh) { clock_delay(x->x_clock, 0L); x->x_state = 1; x->x_deadwait = x->x_hideadtime; goto done; } } } done: return (w+4); }