void Demand_next_ak(Demand *unit, int inNumSamples)
{
	float *trig = ZIN(0);
	float zreset = IN0(1);

	float** out = unit->m_out;
	float *prevout = unit->m_prevout;

	for (int i=0; i<unit->mNumOutputs; ++i) {
		out[i] = OUT(i);
	}

	float prevtrig = unit->m_prevtrig;
	float prevreset = unit->m_prevreset;

	for (int i=0; i<inNumSamples; ++i) {
		float ztrig = ZXP(trig);
		if (zreset > 0.f && prevreset <= 0.f) {
			for (int j=2; j<unit->mNumInputs; ++j) {
				RESETINPUT(j);
			}
		}

		if (ztrig > 0.f && prevtrig <= 0.f) {
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				float x = DEMANDINPUT_A(j, i + 1);
				if (sc_isnan(x)) x = prevout[k];
				else prevout[k] = x;
				out[k][i] = x;
			}

		} else {
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				out[k][i] = prevout[k];
			}

		}
		prevtrig = ztrig;
		prevreset = zreset;
	}

	unit->m_prevtrig = prevtrig;
	unit->m_prevreset = prevreset;
}
Esempio n. 2
0
/** A basic client, note that he will create the sockets, not the server 
 * @param path Path to the server socket
 */
void client_socket(char *path){
	lsocket*main_socket=make_socket(path);
	
	/* Connect to the given socket address */
	open_socket(main_socket,S_IWUSR); 
	
	/* Creation of the two sockets */
	sockets=open_communication();
	
	/* Send the socket to listen to */
	if (handshake(main_socket,sockets)<0) OUT("The server didn't accepted connection");
	
	/* Acknoledge user requests */
	bor_signal(SIGINT,gotcha,0);
	while (user_request(sockets));
	
	/* Properly close connection */
	self_terminate();
}
int
main(int argc, char *argv[])
{
	int i, j;
	size_t size;

	START(argc, argv, "vmmalloc_check_allocations");

	for (size = MAX_SIZE; size >= MIN_SIZE; size /= 2) {
		OUT("size %zu", size);

		memset(allocs, 0, sizeof (allocs));

		for (i = 0; i < MAX_ALLOCS; ++i) {
			allocs[i] =  malloc(size);
			if (allocs[i] == NULL) {
				/* out of memory in pool */
				break;
			}

			/* fill each allocation with a unique value */
			memset(allocs[i], (char)i, size);
		}

		/* at least one allocation for each size must succeed */
		ASSERT(i > 0);

		/* check for unexpected modifications of the data */
		for (i = 0; i < MAX_ALLOCS && allocs[i] != NULL; ++i) {
			char *buffer = allocs[i];
			for (j = 0; j < size; ++j) {
				if (buffer[j] != (char)i)
					FATAL("Content of data object was "
						"modified unexpectedly for "
						"object size: %zu, id: %d",
						size, j);
			}
			free(allocs[i]);
		}
	}

	DONE(NULL);
}
void Duty_next_dd(Duty *unit, int inNumSamples)
{
	float *out = OUT(0);
	float prevout = unit->m_prevout;
	float count = unit->m_count;
	float reset = unit->m_prevreset;
	float sr = (float) SAMPLERATE;

	for (int i=0; i<inNumSamples; ++i) {

		if (reset <= 0.f) {
			RESETINPUT(duty_level);
			RESETINPUT(duty_dur);
			count = 0.f;
			reset = DEMANDINPUT_A(duty_reset, i + 1) * sr + reset;
		} else {
			reset--;
		}
		if (count <= 0.f) {
			count = DEMANDINPUT_A(duty_dur, i + 1) * sr + count;
			if(sc_isnan(count)) {
				int doneAction = (int)ZIN0(duty_doneAction);
				DoneAction(doneAction, unit);
			}
			float x = DEMANDINPUT_A(duty_level, i + 1);
			//printf("in  %d %g\n", k, x);
			if(sc_isnan(x)) {
				x = prevout;
				int doneAction = (int)ZIN0(duty_doneAction);
				DoneAction(doneAction, unit);
			} else {
				prevout = x;
			}
		}

		out[i] = prevout;
		count--;
	}

	unit->m_count = count;
	unit->m_prevreset = reset;
	unit->m_prevout = prevout;
}
Esempio n. 5
0
void free_CSG(CSG *csg)
{
	int i = 0;
	//int t = 0;
	int j = 0;
	int nout = 0;
	CSG_Node *actual;
	CSG_Node *base = csg->node;

	for (i = 0; i < csg->last_state; i++) {
	  actual = base + i;
	  nout = OUT(actual);

		if (0 && nout==1) {
		  if (((CSG_Node *)actual->arc <= base) 
			  ||((CSG_Node *)actual->arc >= (base + csg->last_state))) {
		    if(actual != NULL)
				free(actual);
				//printf("%s \n","uo");
		  }
	  }	
	  else { 
		  for(j=0;j<nout;j++) {
				CSG_Node *act = actual->arc[j];
				if (0 && ((act <= base) || (act >= (base + csg->last_state)))) {
				  if(act != NULL)
					free(act);
				}
				
			}
		    if(nout>2)
		      {
			if (csg->node[i].arc != NULL)
				free(csg->node[i].arc);
		      }
		}
	}
        if (csg->node != NULL)
   	    free((void *)csg->node);	
        if (csg != NULL)
    	    free((void *)csg);
}
void Demand_next_aa(Demand *unit, int inNumSamples)
{
	float *trig = ZIN(0);
	float *reset = ZIN(1);

	float** out = unit->m_out;
	float* prevout = unit->m_prevout;

	for (int i=0; i<unit->mNumOutputs; ++i) {
		out[i] = OUT(i);
	}

	float prevtrig = unit->m_prevtrig;
	float prevreset = unit->m_prevreset;

	//Print("Demand_next_aa %d  %g\n", inNumSamples, prevtrig);
	for (int i=0; i<inNumSamples; ++i) {
		float ztrig = ZXP(trig);
		float zreset = ZXP(reset);
		if (zreset > 0.f && prevreset <= 0.f) {
			for (int j=2; j<unit->mNumInputs; ++j) {
				RESETINPUT(j);
			}
		}
		if (ztrig > 0.f && prevtrig <= 0.f) {
			//Print("triggered\n");
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				float x = DEMANDINPUT_A(j, i + 1);
				//printf("in  %d %g\n", k, x);
				if (sc_isnan(x)) x = prevout[k];
				else prevout[k] = x;
				out[k][i] = x;
			}
		} else {
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				out[k][i] = prevout[k];
			}
		}
		prevtrig = ztrig;
		prevreset = zreset;
	}
}
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;
}
Esempio n. 8
0
int8_t cmd_rping(uint8_t argc, char **argv)
{
    node_id_t recipient;
    uint8_t token;
    int8_t rc;

    if (argc != 2 && argc != 3) {
        OUT("usage: rping <recipient> [<token>]\r\n");
        return NRK_ERROR;
    }

    recipient = atoi(argv[1]);
    token = argc == 3 ? atoi(argv[2]) : 0;

    nrk_led_set(led_awaiting_pong);
    rc = rpc_ping(recipient, token);
    nrk_led_clr(led_awaiting_pong);

    return rc;
}
Esempio n. 9
0
A8(PRIVATE, void, scodydxx1x2, register LONGINT, y1, register INTEGER, x1,
	    INTEGER, dy, INTEGER, dx, INTEGER **, opp, INTEGER **, opp2,
				register INTEGER, offy, register INTEGER, offx)
{
    register INTEGER *op, *op2;
    register INTEGER x2;
    register LONGINT incr;

    op  = *opp;
    op2 = *opp2;
    x2 = x1 - dx;
    if (dy > dx) {
	incr = ((LONGINT) dy << 16) / (dx+1) + 1;
	OUT(y1, x1);
	y1 = (y1 << 16) | (1L << 15);
	while (x1 != x2) {
	    y1 += incr;
	    OUT(y1 >> 16, --x1);
	}
    } else {
Esempio n. 10
0
void TaxMan(void)
{
	double tax;
	int i;
	char c;

	JOUST(PLAYER.Level);
	d *= 1000.;
	if(PLAYER.Gold + PLAYER.Bank > d) {
		NL;
		tax = PLAYER.Gold + PLAYER.Bank - d;
		sprintf(outbuf, "%s, the tax collector, looks at your bulging money purse", IRSREC->Handle);
		OUT(outbuf); NL;
		OUT("and says, \"Ah, it is time to pay your taxes!\"  You check out the two burly"); NL;
		sprintf(outbuf, "guards who stand ready to enforce %s's will.", SYSREC->Handle);
		OUT(outbuf); NL; NL;
		Delay(100);
		sprintf(outbuf, "The tax will cost you %s.", money(tax,ANSI));
		OUT(outbuf); NL; NL;
		Delay(100);
		sprintf(prompt, "%sWill you pay the tax (Y/N)? ", fore(CYN));
		do {
			OUT(prompt);
			c = inkey('Y', 'Y');
			NL;
		} while(c != 'Y' && c != 'N');
		NL;
		if(c == 'N') {
			sound2("taxman", 0);
			OUT("The tax collector orders his guards, \"Run this outlaw through!\""); NL; NL;
			Delay(100);
			for(i = 0; i < 2; i++) {
				memset(RPC[1][i], 0, sizeof(struct RPC));
				sprintf(RPC[1][i]->user.Handle, "City Guard #%d", i + 1);
				sprintf(RPC[1][i]->user.Class, "%s.%s", table->class[0]->Origin, table->class[0]->Character[dice(MAXCLASS(0))-1]->Name);
				RPC[1][i]->user.Level = PLAYER.Level / 2 + 1;
				RPC[1][i]->user.Sex = 'I';
				sprintf(RPC[1][i]->user.Weapon, "NATURAL.%u", RPC[1][i]->user.Level/2 + dice(RPC[1][i]->user.Level/2));
				sprintf(RPC[1][i]->user.Armor, "NATURAL.%u", RPC[1][i]->user.Level/4 + dice(RPC[1][i]->user.Level/4));
				CreateRPC(RPC[1][i]);
				RPC[1][i]->user.Poison = (UWORD)~0;
				if(RPC[1][i]->SP)
					RPC[1][i]->user.Spell = HEAL_SPELL | BLAST_SPELL;
			}
			from = '\0';
			Battle();
			if(RPC[1][0]->HP > 0 || RPC[1][1]->HP > 0 || !ONLINE->HP)
				c = 'Y';
		}
Esempio n. 11
0
int8_t cmd_localize(uint8_t argc, char **argv)
{
    int8_t rc;
    ir_graph_t *ir_graph;
    node_id_t ref_node = this_node_id;

    if (!(argc == 1 || argc == 2)) {
        OUT("usage: loc [<ref_node>]\r\n");
        return NRK_ERROR;
    }

    if (argc == 2)
        ref_node = atoi(argv[1]);

    ir_graph = get_ir_graph();

    rc = localize(ir_graph, ref_node);
    if (rc == NRK_OK)
        print_locations();
    return rc;
}
Esempio n. 12
0
void XS1S(){
  
  TFile *f = new TFile("Upsilon_2D_10ptbins.root");
  TH2D *H;
  H = (TH2D*)gFile->Get("fXS");
  double tot(0.); double totE(0.); 
  
  ofstream OUT("XS_1S.tex");
  OUT << "% ----------------------------------------------------------------------" << endl;
  OUT << "% -- XSections" << endl;
  
  for ( int x = 1; x <= H->GetNbinsX(); ++x ){
    for ( int y = 1; y <= H->GetNbinsY(); ++y ){
      OUT << Form("\\vdef{XS%iS_bin%i_%iContent} {\\ensuremath{ {%.4f } } }",1, x, y, H->GetCellContent(x,y) ) << endl;
      OUT << Form("\\vdef{XS%iS_bin%i_%iError} {\\ensuremath{ {%.4f } } }",1, x, y, H->GetCellError(x,y) ) << endl;
    }  
  }
  
  OUT.close();
  
}
Esempio n. 13
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "pmem_is_pmem_proc");

	if (argc < 4 || argc % 2)
		FATAL("usage: %s file addr len [addr len]...", argv[0]);

	Sfile = argv[1];

	for (int arg = 2; arg < argc; arg += 2) {
		void *addr;
		size_t len;

		addr = (void *)strtoull(argv[arg], NULL, 16);
		len = (size_t)strtoull(argv[arg + 1], NULL, 10);
		OUT("addr %p, len %zu: %d", addr, len, pmem_is_pmem(addr, len));
	}

	DONE(NULL);
}
void TDuty_next_da(TDuty *unit, int inNumSamples)
{

	float *reset = ZIN(duty_reset);
	float *out = OUT(0);

	float count = unit->m_count;
	float prevreset = unit->m_prevreset;
	float sr = (float) SAMPLERATE;

	for (int i=0; i<inNumSamples; ++i) {

		float zreset = ZXP(reset);
		if (zreset > 0.f && prevreset <= 0.f) {

			RESETINPUT(duty_level);
			RESETINPUT(duty_dur);
			count = 0.f;
		}
		if (count <= 0.f) {
			count = DEMANDINPUT_A(duty_dur, i + 1) * sr + count;
			if(sc_isnan(count)) {
				int doneAction = (int)ZIN0(2);
				DoneAction(doneAction, unit);
			}
			float x = DEMANDINPUT_A(duty_level, i + 1);
			//printf("in  %d %g\n", k, x);
			if (sc_isnan(x)) x = 0.f;
			out[i] = x;
		} else {
			out[i] = 0.f;
		}
		count--;
		prevreset = zreset;
	}

	unit->m_count = count;
	unit->m_prevreset = prevreset;

}
Esempio n. 15
0
ParseTree* Parser::STMT()
{
	ParseTree* retTree = new ParseTree();
    
	if((*parser).get().token == ID)
    {
		(*retTree).SetLeaf1(ASSIGN()->getLeaf());
		(*retTree).setAlt(1);
	}
    else if((*parser).get().token == IF)
    {
		(*retTree).SetLeaf1(IFF()->getLeaf());
		(*retTree).setAlt(2);
	}
    else if((*parser).get().token == DO)
    {
		(*retTree).SetLeaf1(DOWHILE()->getLeaf());
		(*retTree).setAlt(3);
	}
    else if((*parser).get().token == INPUT)
    {
		(*retTree).SetLeaf1(IN()->getLeaf());
		(*retTree).setAlt(4);
	}
    else if((*parser).get().token == OUTPUT)
    {
		(*retTree).SetLeaf1(OUT()->getLeaf());
		(*retTree).setAlt(5);
	}
    else if((*parser).get().token == CASE)
    {
		(*retTree).SetLeaf1(CASE_STMT()->getLeaf());
		(*retTree).setAlt(6);
	}
    else
    {
		ThrowParserError();
	}
	return retTree;
}
Esempio n. 16
0
/*----------------------------------------------------------------------------*/
status_t
sys_get_sem_info(krnl_sem_msg_t *msg, krnl_sem_msg_t *reply) {

	sys_sem_info_t *s_info = NULL;

	acquire_sem_priv(_sem_list_sem);
	s_info = _sem_list;
	while(s_info) {
		if(s_info->info.sem == msg->info.sem) {
			memcpy(&(reply->info), &(s_info->info), sizeof(sem_info));
			release_sem_priv(_sem_list_sem);

			DBG(OUT("Retrieved info about semaphore %d\n", s_info->info.sem));
			return B_OK;
		}

		s_info = s_info->next;
	}

	release_sem_priv(_sem_list_sem);
	return B_BAD_VALUE;
}
Esempio n. 17
0
int main() {
    Erato e(48);
    LOG(INFO) << OUT(e.primes_);
    set<uint64_t> q;
    q.insert(1);
    uint64_t prev = 0;
    uint64_t sum = 0;
    while (q.size() < 400000000) {
        auto now = *(q.begin());
        q.erase(q.begin());
        if (now == prev + 1) {
            sum += prev;
            cout << prev << " " << now << " " << sum << endl;
        }
        LOG_EVERY_MS(INFO, 10000) << q.size() << " " << *(q.begin());
        prev = now;
        for (int p : e.primes_) {
            q.insert(p*now);
        }
    }
    return 0;
}
Esempio n. 18
0
/* Collection of unicast echo responses to detect working links */
int
overlay_mdp_service_probe(overlay_mdp_frame *mdp)
{
  IN();
  if (mdp->out.src.port!=MDP_PORT_ECHO || mdp->out.payload_length != sizeof(struct probe_contents)){
    WARN("Probe packets should be returned from remote echo port");
    RETURN(-1);
  }
  
  struct subscriber *peer = find_subscriber(mdp->out.src.sid, SID_SIZE, 0);
  if (peer->reachable == REACHABLE_SELF)
    RETURN(0);
  
  struct probe_contents probe;
  bcopy(&mdp->out.payload, &probe, sizeof(struct probe_contents));
  if (probe.addr.sin_family!=AF_INET)
    RETURN(WHY("Unsupported address family"));
  
  struct overlay_interface *interface = &overlay_interfaces[probe.interface];
  // if a peer is already reachable, and this probe would change the interface, ignore it
  // TODO track unicast links better in route_link.c
  if (peer->reachable & REACHABLE_INDIRECT)
    RETURN(0);
  if (peer->reachable & REACHABLE_DIRECT && peer->interface && peer->interface != interface)
    RETURN(0);

  peer->last_probe_response = gettime_ms();
  peer->interface = &overlay_interfaces[probe.interface];
  peer->address.sin_family = AF_INET;
  peer->address.sin_addr = probe.addr.sin_addr;
  peer->address.sin_port = probe.addr.sin_port;
  int r=REACHABLE_UNICAST;
  // Don't turn assumed|broadcast into unicast|broadcast
  if (!(peer->reachable & REACHABLE_ASSUMED))
    r |= (peer->reachable & REACHABLE_DIRECT);
  set_reachable(peer, r);
  RETURN(0);
  OUT();
}
Esempio n. 19
0
static int RENAME(resample_common)(ResampleContext *c,
                                   void *dest, const void *source,
                                   int n, int update_ctx)
{
    DELEM *dst = dest;
    const DELEM *src = source;
    int dst_index;
    int index= c->index;
    int frac= c->frac;
    int sample_index = index >> c->phase_shift;

    index &= c->phase_mask;
    for (dst_index = 0; dst_index < n; dst_index++) {
        FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;

        FELEM2 val=0;
        int i;
        for (i = 0; i < c->filter_length; i++) {
            val += src[sample_index + i] * (FELEM2)filter[i];
        }
        OUT(dst[dst_index], val);

        frac  += c->dst_incr_mod;
        index += c->dst_incr_div;
        if (frac >= c->src_incr) {
            frac -= c->src_incr;
            index++;
        }
        sample_index += index >> c->phase_shift;
        index &= c->phase_mask;
    }

    if(update_ctx){
        c->frac= frac;
        c->index= index;
    }

    return sample_index;
}
Esempio n. 20
0
void XS1S_Rap(){
  
  TFile *f = new TFile("XSection.root");
  TH1D *H;
  H = (TH1D*)gFile->Get("S1YieldEta");
  double tot(0.); double totE(0.); 
  
  ofstream OUT("XS_1S_rap.tex");
  OUT << "% ----------------------------------------------------------------------" << endl;
  OUT << "% -- Yields" << endl;
  for ( int x = 1; x <= H->GetNbinsX(); ++x ){
    OUT << Form("\\vdef{XS_rap%iS_bin%iContent} {\\ensuremath{ {%.3f } } }",1, x, H->GetBinContent(x)*H->GetBinWidth(x) ) << endl;
    OUT << Form("\\vdef{XS_rap%iS_bin%iError} {\\ensuremath{ {%.3f } } }",1, x, H->GetBinError(x)*H->GetBinWidth(x) ) << endl;
    tot += H->GetBinContent(x)*H->GetBinWidth(x);
    totE += (H->GetBinError(x)*H->GetBinWidth(x)*H->GetBinWidth(x)*H->GetBinError(x));
  }
		
  OUT << Form("\\vdef{sum%iS} {\\ensuremath{ {%.4f } } }",1, tot) << endl;
  OUT << Form("\\vdef{sum%iSError} {\\ensuremath{ {%.4f } } }",1 , TMath::Sqrt(totE) ) << endl;
  OUT.close();
  
}
Esempio n. 21
0
/*----------------------------------------------------------------------------*/
int main(int argc, char **argv) {

    /*	make sure proper termination takes place on interruption/abortion */
    signal(SIGINT, sig_catcher);
    signal(SIGQUIT, sig_catcher);
    signal(SIGABRT, sig_catcher);
    signal(SIGTERM, sig_catcher);

    /* initialization */
    if(init() < 0) {
        DBG(OUT("Error during initialization...bailing out\n"));
        cleanup();
        exit(-1);
    }

    /* listen to incoming requests */
    listen();

    /* terminate */
    cleanup();
    exit(0);
}
void port_button_task(void) {
    uint8_t i;
    for (i = 0; i < NUM_PORT; i++) {
        // ボタンが押されていたらLED点灯
        if (port[i].ctmu.flag.pressing) {
            LED_output(i, 1);
        } else if (port[i].flag.led_indicator_ON == 0 && port[i].flag.led_flag == 1) {
            LED_output(i, 0);
        }
        // シングルタップ
        if (port[i].ctmu.flag.press) {
            port[i].ctmu.flags = 0;
            LED_output(i, 0);
            // 表示ポートと一致していれば、表示循環
            // 表示ポートと一致していなければ、一致させる
            if (print_port == i) {
                switch (data_item) {
                    case CURRENT:
                        data_item = INTEGRATED_CURRENT;
                        break;
                    case INTEGRATED_CURRENT:
                        data_item = INTEGRATED_TIME;
                        break;
                    case INTEGRATED_TIME:
                    default:
                        data_item = CURRENT;
                        break;
                }
            } else {
                print_port = i;
            }
            display(PRINT_DATA, "", "");
            // 充電開始
            OUT(i, 1);
            port[i].cut_cnt = 0;
        }
    }
}
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;
}
Esempio n. 24
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_poolset_foreach");

	out_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
			MAJOR_VERSION, MINOR_VERSION);
	util_init();

	if (argc < 2)
		FATAL("usage: %s file...",
			argv[0]);

	for (int i = 1; i < argc; i++) {
		char *fname = argv[i];
		int ret = util_poolset_foreach_part(fname, cb, fname);

		OUT("util_poolset_foreach_part(%s): %d", fname, ret);
	}
	out_fini();

	DONE(NULL);
}
void Block_Down_Sample<T, N>::print_output_img(){

	co_index img_index;
	std::fill( img_index.begin(), img_index.end(), 0);
	cout << "====== output img =======\n";
	int counter[N] = {0};
	for (int i = 0; i < OUT_size; ++i) {
		for (int i = 0; i < N - 1; ++i)
			cout << img_index[i] << ",";
		cout << img_index[N-1] << " : ";
		cout << OUT(img_index) << "\n";
		img_index[N-1]++;
		for (int j = N-1; j >= 0; --j) {
			img_index[j] += counter[j];
			counter[j] = 0;
			if (img_index[j] >= d[j]) {
				img_index[j] = 0;
				counter[j - 1] = 1;
			}
		}
	}
	cout << "====== end output img =====\n";
};
Esempio n. 26
0
int resolve_name(const char *name, struct in_addr *addr){
  // TODO this can block, move to worker thread.
  IN();
  int ret=0;
  struct addrinfo hint={
    .ai_family=AF_INET,
  };
  struct addrinfo *addresses=NULL;
  if (getaddrinfo(name, NULL, &hint, &addresses))
    RETURN(WHYF("Failed to resolve %s",name));
  
  if (addresses->ai_addr->sa_family==AF_INET){
    *addr = ((struct sockaddr_in *)addresses->ai_addr)->sin_addr;
    if (config.debug.overlayrouting)
      DEBUGF("Resolved %s into %s", name, inet_ntoa(*addr));
    
  }else
    ret=WHY("Ignoring non IPv4 address");
  
  freeaddrinfo(addresses);
  RETURN(ret);
  OUT();
}
Esempio n. 27
0
/*----------------------------------------------------------------------------*/
status_t
rename_thread(thread_id thread, const char *name)
{
	sys_thread_info_t *th = NULL;
	
	if(acquire_sem(_thread_list_sem) == B_OK) {
		th = _thread_list;
		
		while(th) {
			if(th->info.thread == thread) {
				DBG(OUT("Thread %d (%s) renamed to (%s)\n", thread, th->info.name, name));
				sprintf(th->info.name, "%s", name);
				release_sem(_thread_list_sem);
				return B_OK;
			}
			th = th->next;
		}
		
		release_sem(_thread_list_sem);
	}
	
	return B_BAD_THREAD_ID;
}
Esempio n. 28
0
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;
}
Esempio n. 29
0
void DWGPlucked_next(DWGPlucked *unit, int inNumSamples)
{

	float *out = OUT(0);
	float freq = ZIN0(0);
	float amp = ZIN0(1);
	float trig = ZIN0(2);
	float pos = ZIN0(3);

	float c1 = ZIN0(4);
	float c3 = std::max(ZIN0(5),(float)1e-9);
	float *in = IN(6);
	
	unit->Loss.setcoeffs(freq,c1,c3);
	float lossdelay = unit->Loss.groupdelay(freq,SAMPLERATE);
	float deltot = SAMPLERATE/freq;
	float del1 = (deltot - lossdelay )*0.5 - 1;

	float PMAS,PMAS2;
	float PMENOS;
	for (int i=0; i < inNumSamples; ++i)
	{
		unit->DWGF[0].add(in[i],pos*del1);
		unit->DWGF[1].add(in[i],del1*(1-pos));
		
		PMAS = unit->DWGF[0].delay(del1);
		PMAS2 = unit->Loss.filter(PMAS);
		PMENOS = unit->DWGF[1].delay(del1);
		
		unit->DWGF[1].push(-PMAS2);
		unit->DWGF[0].push(-PMENOS);
		
		out[i] = PMAS + PMAS2;
			
	}
	unit->Release(trig,out,inNumSamples);
}
Esempio n. 30
0
/*----------------------------------------------------------------------------*/
status_t
kill_thread(thread_id thread)
{
	sys_thread_info_t *curr_th = NULL;
	sys_thread_info_t **prev_th = NULL;
	int status;
	
	if(acquire_sem(_thread_list_sem) == B_OK) {
		curr_th = _thread_list;
		prev_th = &_thread_list;
		
		while(curr_th) {
			if(curr_th->info.thread == thread) {
				/* thread found, remove it... */
				*prev_th = curr_th->next;
				status = pthread_cancel((pthread_t)thread);
				DBG(OUT("Killed thread %d (%s)\n", thread, curr_th->info.name));
				delete_thread(curr_th);
				release_sem(_thread_list_sem);
				if(status != 0) {
					switch(errno) {
						case EINVAL:
						case ESRCH: return B_BAD_THREAD_ID;
					}
				}
				return B_OK;
			}
			
			prev_th = &(curr_th->next);
			curr_th = curr_th->next;
		}
		
		release_sem(_thread_list_sem);
	}
	
	return B_BAD_THREAD_ID;
}