Example #1
0
/**
 * Init predictable scheme
 */
Bool
InitPredictableAccelerationScheme(DeviceIntPtr dev,
                                  ValuatorAccelerationPtr protoScheme)
{
    DeviceVelocityPtr vel;
    ValuatorAccelerationRec scheme;
    PredictableAccelSchemePtr schemeData;

    scheme = *protoScheme;
    vel = calloc(1, sizeof(DeviceVelocityRec));
    schemeData = calloc(1, sizeof(PredictableAccelSchemeRec));
    if (!vel || !schemeData) {
        free(vel);
        free(schemeData);
        return FALSE;
    }
    InitVelocityData(vel);
    schemeData->vel = vel;
    scheme.accelData = schemeData;
    if (!InitializePredictableAccelerationProperties(dev, vel, schemeData)) {
        free(vel);
        free(schemeData);
        return FALSE;
    }
    /* all fine, assign scheme to device */
    dev->valuator->accelScheme = scheme;
    return TRUE;
}
Example #2
0
static void handle_connreq(struct poll_fd_mgr *poll_mgr,
			   struct poll_fd_info *poll_info)
{
	struct tcpx_conn_handle *handle;
	struct tcpx_pep *pep;
	struct fi_eq_cm_entry *cm_entry;
	struct ofi_ctrl_hdr conn_req;
	SOCKET sock;
	int ret;

	assert(poll_info->fid->fclass == FI_CLASS_PEP);
	pep = container_of(poll_info->fid, struct tcpx_pep, util_pep.pep_fid.fid);

	sock = accept(pep->sock, NULL, 0);
	if (sock < 0) {
		FI_WARN(&tcpx_prov, FI_LOG_EP_CTRL, "accept error: %d\n",
			ofi_sockerr());
		return;
	}
	ret = rx_cm_data(sock, &conn_req, ofi_ctrl_connreq, poll_info);
	if (ret) {
		FI_WARN(&tcpx_prov, FI_LOG_EP_CTRL, "cm data recv failed \n");
		goto err1;
	}

	handle = calloc(1, sizeof(*handle));
	if (!handle)
		goto err1;

	cm_entry = calloc(1, sizeof(*cm_entry) + poll_info->cm_data_sz);
	if (!cm_entry)
		goto err2;

	handle->conn_fd = sock;
	cm_entry->fid = poll_info->fid;
	cm_entry->info = fi_dupinfo(&pep->info);
	if (!cm_entry->info)
		goto err3;

	cm_entry->info->handle = &handle->handle;
	memcpy(cm_entry->data, poll_info->cm_data, poll_info->cm_data_sz);

	ret = (int) fi_eq_write(&pep->util_pep.eq->eq_fid, FI_CONNREQ, cm_entry,
				sizeof(*cm_entry) + poll_info->cm_data_sz, 0);
	if (ret < 0) {
		FI_WARN(&tcpx_prov, FI_LOG_EP_CTRL, "Error writing to EQ\n");
		goto err4;
	}

	free(cm_entry);
	return;
err4:
	fi_freeinfo(cm_entry->info);
err3:
	free(cm_entry);
err2:
	free(handle);
err1:
	ofi_close_socket(sock);
}
Example #3
0
static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  int i;
  int vendorlen=oggpack_read1(opb,32);
    
  //int vendorlen=oggpack_read(opb,32);

  if(vendorlen<0)goto err_out;
  vc->vendor=(char *)calloc(vendorlen+1,1);
  _v_readstring(opb,vc->vendor,vendorlen);
  vc->comments=oggpack_read1(opb,32);    
  //vc->comments=oggpack_read(opb,32);

  if(vc->comments<0)goto err_out;
  vc->user_comments=(char **)calloc(vc->comments+1,sizeof(*vc->user_comments));
  vc->comment_lengths=(int *)calloc(vc->comments+1, sizeof(*vc->comment_lengths));
	    
  for(i=0;i<vc->comments;i++){
    int len=oggpack_read1(opb,32);         
     //int len=oggpack_read(opb,32);

    if(len<0)goto err_out;
	vc->comment_lengths[i]=len;
    vc->user_comments[i]=(char *)calloc(len+1,1);
    _v_readstring(opb,vc->user_comments[i],len);
  }	  
  if(oggpack_read1(opb,1)!=1)goto err_out; /* EOP check */
  //if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */

  return(0);
 err_out:
  vorbis_comment_clear(vc);
  return(OV_EBADHEADER);
}
Example #4
0
int httpauth_keyvalue_buffer_append(httpauth_keyvalue_buffer *kvb, const char *key, const char *realm, httpauth_type type) {
	size_t i;
	if (kvb->size == 0) {
		kvb->size = 4;

		kvb->kv = malloc(kvb->size * sizeof(*kvb->kv));

		for(i = 0; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	} else if (kvb->used == kvb->size) {
		kvb->size += 4;

		kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv));

		for(i = kvb->used; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	}

	kvb->kv[kvb->used]->key = strdup(key);
	kvb->kv[kvb->used]->realm = strdup(realm);
	kvb->kv[kvb->used]->type = type;

	kvb->used++;

	return 0;
}
static char* test_encode_and_decode_base64()
{
    load_histograms();

    uint8_t* buffer = NULL;
    uint8_t* decoded = NULL;
    char* encoded = NULL;
    size_t len = 0;
    int rc = 0;

    rc = hdr_encode_compressed(cor_histogram, &buffer, &len);
    mu_assert("Did not encode", validate_return_code(rc));

    size_t encoded_len = hdr_base64_encoded_len(len);
    size_t decoded_len = hdr_base64_decoded_len(encoded_len);
    encoded = calloc(encoded_len + 1, sizeof(char));
    decoded = calloc(decoded_len, sizeof(uint8_t));

    hdr_base64_encode(buffer, len, encoded, encoded_len);
    hdr_base64_decode(encoded, encoded_len, decoded, decoded_len);

    mu_assert("Should be same", memcmp(buffer, decoded, len) == 0);

    return 0;
}
/*   Takes a list of pointers to frames */
st_animation *ST_AnimationCreateAnimation(s16 fpf, u16 loopFrame,
  u16 length, ...)
{
  u16 i;
  va_list ap;

  st_animation *tempanim = calloc(sizeof(st_animation), 1);
  if (!tempanim)
    return 0;

  tempanim->fpf = fpf;
  tempanim->ftn = 0;

  if (loopFrame < length)
    tempanim->loopFrame = loopFrame;
  else
    tempanim->loopFrame = length - 1;
  tempanim->length = length;
  tempanim->frames = calloc(sizeof(st_frame*), length);
  tempanim->currentFrame = 0;


  va_start(ap, length);

  for (i = 0; i < length; i++)
    tempanim->frames[i] = va_arg(ap, st_frame*);

  va_end (ap);

  return tempanim;
}
Example #7
0
MLModel *mlLoadObjFile(const char *objFileName) {
 FILE *stream;
 char line[256];
 MLVertex *mlVertex;
 MLModel *mlModel;
 unsigned int newSize = ML_INITIAL_NUM_OF_VERTICES;

 stream = fopen(objFileName, "r");
 
 if(stream == NULL) {
  return NULL;
 }
 
 mlModel = (MLModel *)calloc(1, sizeof(MLModel));
 mlModel->vertices = (MLVertex **)malloc(sizeof(MLVertex *) * newSize);
 
 do {
  if(line[0] == 'v' && line[1] == ' ') {
   mlVertex = (MLVertex *)calloc(1, sizeof(MLVertex));
   sscanf(line, "v %lf %lf %lf", &mlVertex->x, &mlVertex->y, &mlVertex->z);
   mlVertex->w = 1;
   mlModel->vertices[mlModel->numberOfVertices] = mlVertex;
   mlModel->numberOfVertices++;
   if(mlModel->numberOfVertices == newSize) {
    newSize += ML_INITIAL_NUM_OF_VERTICES;
    mlModel->vertices = (MLVertex **)realloc(mlModel->vertices, sizeof(MLVertex *) * newSize);
   }
  }   
 } while(fgets(line, 256, stream) != NULL);
 
 fclose(stream);
 
 return mlModel;
}
Example #8
0
int tpool_create(int max_thr_num) {
    int i;

    tpool = calloc(1, sizeof(tpool_t));
    if(!tpool) {
        printf("calloc failed\n");
        exit(1);
    }

    tpool->max_thr_num = max_thr_num;
    tpool->shutdown = 0;
    tpool->queue_head = NULL;
    if(pthread_mutex_init(&tpool->queue_lock, NULL) != 0) {
           printf("pthread_mutex_init failed, errno:%d, error:%s\n", errno, strerror(errno));
           exit(1);
    }
    if(pthread_cond_init(&tpool->queue_ready, NULL) != 0) {
        printf("pthread_cond_init failed, errno:%d, error:%s\n", errno, strerror(errno));
        exit(1);
    }
    tpool->thr_id = calloc(max_thr_num, sizeof(pthread_t));
    if(!tpool->thr_id) {
        printf("calloc failed\n");
        exit(1);
    }
    for(i = 0; i < max_thr_num; i++) {
        if(pthread_create(&tpool->thr_id[i], NULL, thread_routine, NULL) != 0) {
            printf("pthread_create failed, errno:%d, error:%s\n", errno, strerror(errno));
            exit(1);
        }
    }
    return 0;
}
Example #9
0
static tagFile *initialize (const char *const filePath, tagFileInfo *const info)
{
	tagFile *result = (tagFile*) calloc ((size_t) 1, sizeof (tagFile));
	if (result != NULL)
	{
		growString (&result->line);
		growString (&result->name);
		result->fields.max = 20;
		result->fields.list = (tagExtensionField*) calloc (
			result->fields.max, sizeof (tagExtensionField));
		result->fp = fopen (filePath, "rb");
		if (result->fp == NULL)
		{
			free (result);
			result = NULL;
			info->status.error_number = errno;
		}
		else
		{
			fseek (result->fp, 0, SEEK_END);
			result->size = ftell (result->fp);
			rewind (result->fp);
			readPseudoTags (result, info);
			info->status.opened = 1;
			result->initialized = 1;
		}
	}
	return result;
}
Example #10
0
/*
 * Create a new content_types object.
 */
lxw_content_types *
_new_content_types()
{
    lxw_content_types *content_types = calloc(1, sizeof(lxw_content_types));
    GOTO_LABEL_ON_MEM_ERROR(content_types, mem_error);

    content_types->default_types = calloc(1, sizeof(struct lxw_tuples));
    GOTO_LABEL_ON_MEM_ERROR(content_types->default_types, mem_error);
    STAILQ_INIT(content_types->default_types);

    content_types->overrides = calloc(1, sizeof(struct lxw_tuples));
    GOTO_LABEL_ON_MEM_ERROR(content_types->overrides, mem_error);
    STAILQ_INIT(content_types->overrides);

    _ct_add_default(content_types, "rels",
                    LXW_APP_PACKAGE "relationships+xml");
    _ct_add_default(content_types, "xml", "application/xml");

    _ct_add_override(content_types, "/docProps/app.xml",
                     LXW_APP_DOCUMENT "extended-properties+xml");
    _ct_add_override(content_types, "/docProps/core.xml",
                     LXW_APP_PACKAGE "core-properties+xml");
    _ct_add_override(content_types, "/xl/styles.xml",
                     LXW_APP_DOCUMENT "spreadsheetml.styles+xml");
    _ct_add_override(content_types, "/xl/theme/theme1.xml",
                     LXW_APP_DOCUMENT "theme+xml");
    _ct_add_override(content_types, "/xl/workbook.xml",
                     LXW_APP_DOCUMENT "spreadsheetml.sheet.main+xml");

    return content_types;

mem_error:
    _free_content_types(content_types);
    return NULL;
}
Example #11
0
/*---------------------------------------------------------------
  Name     : SetJoystick
  Argument : void
  Return   : 0 (succeed), other (failed)
  About    : Set up the Joystick controler
  Version  : Ver 1.0
  Date     : 2014/03/21
  Author   : Ryodo Tanaka (Kyushu Institute of Technology)
----------------------------------------------------------------- */
int SetJoystick(void)
{
  //File open
  if( (JSfd=open(PORT, O_RDONLY)) == -1){
    printLOG("File Open JoyStick");
    return 1;
  }

  //Get JoyStick information
  ioctl(JSfd, JSIOCGAXES, &num_of_axis);
  ioctl(JSfd, JSIOCGBUTTONS, &num_of_buttons);
  ioctl(JSfd, JSIOCGNAME(80), &JSname);

  //Get data space for axis & buttons
  axis = (int*)calloc(num_of_axis, sizeof(int));
  if(!axis){
    printLOG("calloc JoyStick axis");
    return 2;
  }
  button = (char*)calloc(num_of_buttons, sizeof(char));
  if(!button){
    printLOG("calloc JoyStick axis");
    return 3;
  }

  //Use non-blocking mode
  fcntl(JSfd, F_SETFL, O_NONBLOCK);

  printf("%s\tis Connected ...\n", JSname);
  
  return 0;

}
Example #12
0
int invm (const double *a, int N, double *y) {
     /* Inverse of a real matrix a[0..N-1][0..N-1].
	Input:
		a[0..N-1][0..N-1] - given matrix (saved on exit)
		N	      - number of rows and columns of a
        Output:
		y[0..N-1][0..N-1] - inverse of a
     */

  double d, *col, *al;
  int i, j, *indx;

  al = (double *) calloc (sqr(N), sizeof (double));
  indx = (int *) calloc (N, sizeof (int));
  col = (double *) calloc (N, sizeof (double));
  for (i=0; i<sqr(N); i++)
    al[i] = a[i];
  if (ludcmp (al, N, indx, &d))
    return 1;
  for (j=0; j<N; j++) {
    for (i=0; i<N; i++)
      col[i] = 0.0;
    col[j] = 1.0;
    lubksb (al, N, indx, col);
    for (i=0; i<N; i++)
      y[N*i+j] = col[i];
  }
  free (col);
  free (indx);
  free (al);
  return 0;
} /* invm() */
Example #13
0
/*
 * Perform the ioctl
 */
static int cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen,
			  BIGNUM *s)
{
	int ret = -1;

	if (r) {
		kop->crk_param[kop->crk_iparams].crp_p =
			calloc(rlen, sizeof(char));
		kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8;
		kop->crk_oparams++;
	}
	if (s) {
		kop->crk_param[kop->crk_iparams + 1].crp_p = calloc(slen,
								    sizeof(char));
		kop->crk_param[kop->crk_iparams + 1].crp_nbits = slen * 8;
		kop->crk_oparams++;
	}

	if (ioctl(cryptodev_fd, CIOCKEY, kop) == 0) {
		if (r)
			crparam2bn(&kop->crk_param[kop->crk_iparams], r);
		if (s)
			crparam2bn(&kop->crk_param[kop->crk_iparams + 1], s);
		ret = 0;
	}

	return ret;
}
Example #14
0
ssize_t readFromFd(int fd, char ** outputBuffer) {
    size_t outputLength = 0;
    size_t requestLength = REQUEST_LENGTH;
    char * output = calloc(sizeof(char), requestLength);
    char * readBuffer = calloc(sizeof(char), requestLength);
    int done = 0;
    while (!done) {
        memset(readBuffer, 0, requestLength);
        ssize_t charactersRead = read(fd, readBuffer, requestLength);
        size_t oldOutputLength = outputLength;
        outputLength += charactersRead;
        if (charactersRead < 0) {
            perror("");
            done = 1;
        } else {
            output = realloc(output, outputLength + 1);
            memcpy(output+oldOutputLength, readBuffer, charactersRead);
        }
    }
    if (outputLength > 0) {
        output[outputLength] = '\0';
        *outputBuffer = output;
    } else {
        return -1;
    }
    free(readBuffer);
    return outputLength;
}
Example #15
0
static struct JitterBuffer *jbuf_new(uint32_t capacity)
{
    unsigned int size = 1;

    while (size <= (capacity * 4)) {
        size *= 2;
    }

    struct JitterBuffer *q = (struct JitterBuffer *)calloc(sizeof(struct JitterBuffer), 1);

    if (!q) {
        return NULL;
    }

    q->queue = (struct RTPMessage **)calloc(sizeof(struct RTPMessage *), size);

    if (!q->queue) {
        free(q);
        return NULL;
    }

    q->size = size;
    q->capacity = capacity;
    return q;
}
Example #16
0
void runSuccess() {
    calloc(1,5);
    calloc(10,7);
    calloc(0,1);
    calloc(INT_MAX,0);
    calloc(anysize(),anysize());
}
Example #17
0
struct ts_pat *ts_pat_alloc() {
	struct ts_pat *pat = calloc(1, sizeof(struct ts_pat));
	pat->section_header	= ts_section_data_alloc();
	pat->programs_max	= 128;
	pat->programs		= calloc(pat->programs_max, sizeof(void *));
	return pat;
}
bool task_push_dbscan(const char *fullpath,
      bool directory, retro_task_callback_t cb)
{
   retro_task_t *t   = (retro_task_t*)calloc(1, sizeof(*t));
   db_handle_t *db   = (db_handle_t*)calloc(1, sizeof(db_handle_t));

   if (!t || !db)
      goto error;

   t->handler        = task_database_handler;
   t->state          = db;
   t->callback       = cb;

   if (directory)
      db->handle = database_info_dir_init(fullpath, DATABASE_TYPE_ITERATE);
   else
      db->handle = database_info_file_init(fullpath, DATABASE_TYPE_ITERATE);

   if (db->handle)
      db->handle->status = DATABASE_STATUS_ITERATE_BEGIN;

   task_queue_ctl(TASK_QUEUE_CTL_PUSH, t);

   return true;

error:
   if (t)
      free(t);
   if (db)
      free(db);
   return false;
}
Example #19
0
/*! \fn allocate memory for linear system solver UmfPack
 *
 */
int
allocateUmfPackData(int n_row, int n_col, int nz, void** voiddata)
{
    DATA_UMFPACK* data = (DATA_UMFPACK*) malloc(sizeof(DATA_UMFPACK));
    assertStreamPrint(NULL, 0 != data, "Could not allocate data for linear solver UmfPack.");

    data->symbolic = NULL;
    data->numeric = NULL;

    data->n_col = n_col;
    data->n_row = n_row;
    data->nnz = nz;


    data->Ap = (int*) calloc((n_row+1),sizeof(int));

    data->Ai = (int*) calloc(nz,sizeof(int));
    data->Ax = (double*) calloc(nz,sizeof(double));
    data->work = (double*) calloc(n_col,sizeof(double));

    data->numberSolving=0;
    umfpack_di_defaults(data->control);

    data->control[UMFPACK_PIVOT_TOLERANCE] = 0.1;
    data->control[UMFPACK_IRSTEP] = 2;
    data->control[UMFPACK_SCALE] = 1;
    data->control[UMFPACK_STRATEGY] = 5;



    *voiddata = (void*)data;

    return 0;
}
int sd_new(struct sd_display **display) {
  struct sd_display *new_display;
  new_display = calloc(1, sizeof(struct sd_display));
  if (!new_display) {
    return -1;
  }
  // init data fields
  new_display->refcount = 1;
  new_display->digit_count = -1;
  new_display->current_digit = 0;
  new_display->dot_position = -1;
  new_display->displayed_data = NULL;
  new_display->digit_pin_map = NULL;
  new_display->segment_pin_map = calloc(SD_SEGMENTS_PER_DIGIT,
                                        sizeof(struct sd_segment));
  if (!new_display->segment_pin_map) {
    sd_free(new_display);
    return -1;
  }
  // plug function pointers
  new_display->init_digit = sd_init_plug;
  new_display->turn_on_digit = sd_onoff_plug;
  new_display->turn_off_digit = sd_onoff_plug;
  new_display->init_segment = sd_init_plug;
  new_display->turn_on_segment = sd_onoff_plug;
  new_display->turn_off_segment = sd_onoff_plug;
  // object constructed
  *display = new_display;
  return 0;
}
Example #21
0
int s_keyvalue_buffer_append(s_keyvalue_buffer *kvb, const char *key, const char *value) {
	size_t i;
	if (kvb->size == 0) {
		kvb->size = 4;
		kvb->used = 0;

		kvb->kv = malloc(kvb->size * sizeof(*kvb->kv));

		for(i = 0; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	} else if (kvb->used == kvb->size) {
		kvb->size += 4;

		kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv));

		for(i = kvb->used; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	}

	kvb->kv[kvb->used]->key = key ? strdup(key) : NULL;
	kvb->kv[kvb->used]->value = strdup(value);

	kvb->used++;

	return 0;
}
Example #22
0
struct mTrieNode* mnewNode(mTrie *mtrie, char* mdata, int id1){
	
	
	
	if((mnewnode = (struct mTrieNode *)calloc(1,sizeof(struct mTrieNode))) == NULL)
			fprintf(stderr,"\nMemory cannot be allocated to mnewnode\n");
				
				if(mdata != NULL){ 
					if(id1 == 1){
						if((mnewnode->sdata = (char *)calloc(1,20*sizeof(char)))==NULL)
							fprintf(stderr,"\nMemory cannot be allocated to mnewnode->data\n");
						strcpy(mnewnode->sdata, (char *)mdata);
						mnewnode->pdata = NULL;
					}
					else{
						if((mnewnode->pdata = (char *)calloc(1,20*sizeof(char)))==NULL)
							fprintf(stderr,"\nMemory cannot be allocated to mnewnode->data\n");
						strcpy(mnewnode->pdata, (char *)mdata);
						mnewnode->sdata = NULL;
					}
				}
				else {
					mnewnode->pdata = (char *)mdata;
					mnewnode->sdata = (char *)mdata;
				}
				mnewnode->first = NULL;
				mnewnode->second = NULL;
				mnewnode->third = NULL;
				mnewnode->fourth = NULL;
				mtrie->size++;
				return mnewnode;


}
Example #23
0
File: hw1.c Project: kepler27/HW1
void changeTeamName(Node ** head, FILE * finTeams)
{
    char temp[MAX];
    char * longName;
    char * myStringCopy;
    Node * first = *head;

    for(; first != NULL; first = first->next)
    {
        fgets(temp, MAX, finTeams);
        while(fgets(temp, MAX, finTeams)!= NULL)
        {
            myStringCopy = (char *)calloc(strlen(temp)+1, sizeof(char));
            strcpy(myStringCopy,temp);
            char * toke = strtok(myStringCopy, ",");
            longName = (char*) calloc(strlen(toke)+1,sizeof(char));
            strcpy(longName, toke);
            toke = strtok(NULL, ",");
            stripRN(toke);
            if(strcasecmp(((Player*)(first->data))->teamName, toke) == 0)
            {
                free(myStringCopy);
                rewind(finTeams);
                free(((Player*)(first->data))->teamName);
                ((Player*)(first->data))->teamName = longName;
                break;
            }
            free(longName);
            free(myStringCopy);
        }
    }
}
Example #24
0
struct TrieNode* updatenewNode(BiTrie *trie, char* data){
	
	newnodes++;
	if((newnode1 = (struct TrieNode *)calloc(1,sizeof(struct TrieNode))) == NULL)
			fprintf(stderr,"\nMemory cannot be allocated to newnode1\n");
				
				if(data != NULL){ 
				
					printf("\n New node created through update");
					printf("\nThe previous value at this address was %s", newnode1->data);
				
					if((newnode1->data = (char *)calloc(1,20*sizeof(char)))==NULL)
						fprintf(stderr,"\nMemory cannot be allocated to newnode1->data\n");
					
					strcpy(newnode1->data, (char *)data);
					printf("\nThe new value at this address is %s", newnode1->data);
				}
				else 
					newnode1->data = (char *)data;
				
				newnode1->left = NULL;
				newnode1->right = NULL;
				trie->size++;
				return newnode1;


}
int main(void)
{
  MONO_PCM pcm0;
  int n, k, N;
  double *x_real, *x_imag;
  
  mono_wave_read(&pcm0, "ex2_1.wav"); /* WAVEファイルからモノラルの音データを入力する */
  
  N = 64;
  x_real = calloc(N, sizeof(double)); /* メモリの確保 */
  x_imag = calloc(N, sizeof(double)); /* メモリの確保 */
  
  for (n = 0; n < N; n++)
  {
    x_real[n] = pcm0.s[n]; /* x(n)の実数部 */
    x_imag[n] = 0.0; /* x(n)の虚数部 */
  }
  
  FFT(x_real, x_imag, N); /* FFTの計算結果はx_realとx_imagに上書きされる */
  
  /* 周波数特性 */
  for (k = 0; k < N; k++)
  {
    printf("%d %f+j%f\n", k, x_real[k], x_imag[k]);
  }
  
  free(pcm0.s); /* メモリの解放 */
  free(x_real); /* メモリの解放 */
  free(x_imag); /* メモリの解放 */
  
  return 0;
}
Example #26
0
void *pvwarpb_new(t_symbol *s, int argc, t_atom *argv)
{
	t_fftease *fft;
	t_pvwarpb *x = (t_pvwarpb *)pd_new(pvwarpb_class);
    int i;
    for(i=0;i<3;i++){
        inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("signal"), gensym("signal"));
    }
	outlet_new(&x->x_obj, gensym("signal"));
	x->fft = (t_fftease *) calloc(1,sizeof(t_fftease));
	fft = x->fft;
	fft->initialized = 0; // for FFTease package
	x->initialized = 0; // for object
	x->lofreq = 0.0;
	x->hifreq = 10000.0;
	fft->N = FFTEASE_DEFAULT_FFTSIZE;
	fft->overlap = FFTEASE_DEFAULT_OVERLAP;
	fft->winfac = FFTEASE_DEFAULT_WINFAC;
    x->warpfunc = (t_float *) calloc(8192, sizeof(t_float));
    if(argc > 0){ x->buffername = atom_getsymbolarg(0, argc, argv); }
    else { post("%s: Must specify array name", OBJECT_NAME); return NULL; }
    if(argc > 1){ fft->N = (int) atom_getfloatarg(1, argc, argv); }
    if(argc > 2){ fft->overlap = (int) atom_getfloatarg(2, argc, argv); }
	return x;
}
Example #27
0
static int poll_fd_resize(struct poll_fd_mgr *poll_mgr, int size)
{
	struct pollfd *new_poll_fds;
	struct poll_fd_info *new_poll_info;

	new_poll_fds = calloc(size, sizeof(*new_poll_fds));
	if (!new_poll_fds)
		return -FI_ENOMEM;

	new_poll_info = calloc(size, sizeof(*new_poll_info));
	if (!new_poll_info) {
		free(new_poll_fds);
		return -FI_ENOMEM;
	}

	if (poll_mgr->max_nfds) {
		memcpy(new_poll_fds, poll_mgr->poll_fds,
		       poll_mgr->max_nfds * sizeof(*new_poll_fds));
		free(poll_mgr->poll_fds);

		memcpy(new_poll_info, poll_mgr->poll_info,
		       poll_mgr->max_nfds * sizeof(*new_poll_info));
		free(poll_mgr->poll_info);
	}

	poll_mgr->poll_fds = new_poll_fds;
	poll_mgr->poll_info = new_poll_info;
	poll_mgr->max_nfds = size;

	return 0;
}
Example #28
0
int http_client_pool_init(struct http_client_pool *http_client_pool, size_t initial, size_t grow) {
    LOGGER_INFO("http client pool: initial=%zu, grow=%zu", initial, grow);
    if (0 > ctx_pool_init(&http_client_pool->ctx_pool, initial, grow, CLIENT_STACK_SIZE, sizeof(struct http_client_context)))
        return -1;

    /* Global to all clients */
    if (!client_chains) {
        struct rlimit rlim;
        if (0 > getrlimit(RLIMIT_NOFILE, &rlim))
            return LOGGER_PERROR("getrlimit(RLIMIT_NOFILE)"), -1;

        client_chains = calloc(rlim.rlim_cur, sizeof(struct list));
        if (!client_chains)
            return LOGGER_PERROR("calloc client_chains"), -1;

        /* storage for multiple client chains */
        client_heads = calloc(rlim.rlim_cur, sizeof(struct list));
        struct list *tmp = client_heads, *tmp_end = tmp + rlim.rlim_cur;
        if (!client_heads)
            return LOGGER_PERROR("calloc client_heads"), -1;
        for (; tmp != tmp_end; ++tmp)
            list_insert_tail(&free_list, tmp);

        idle_ctx = ribs_context_create(SMALL_STACK_SIZE, http_client_idle_handler);

        hashtable_init(&ht_persistent_clients, rlim.rlim_cur);
    }
    return timeout_handler_init(&http_client_pool->timeout_handler);
}
int main(int argc , char **argv)
{
	if(argc>1 && strcmp(argv[1],"DEBUG")==0) debug=1;
	int t,m,n,i,j,**floor,val;scanf("%d",&t);
	while(t--){
		scanf("%d %d",&m,&n);
		floor=(int**)calloc(m,sizeof(int*));
		for(i=0;i<m;++i){
			floor[i]=(int*)calloc(n,sizeof(int));
			for(j=0;j<n;++j){
				scanf("%d",&floor[i][j]);
			}
		}
		for(i=1;i<m;++i){
			for(j=0;j<n;++j){
				val = floor[i-1][j];
				if(j>0)val = val>floor[i-1][j-1] ? val : floor[i-1][j-1] ;
				if(j<n-1)val = val>floor[i-1][j+1] ? val : floor[i-1][j+1];
				
				floor[i][j]+=val;
			}
		}
		if(debug){
			printf("\n\n");
			for(i=0;i<m;++i){
				for(j=0;j<n;++j)printf("%d ",floor[i][j]);
				printf("\n");
			}
		}
		for(i=0;i<n;++i)val=val>floor[m-1][i]?val:floor[m-1][i];
		printf("%d\n",val);
	}
	return 0;
}
Example #30
0
ran_discrete_omp_t * ran_discrete_omp_preproc (size_t Kevents, const float *ProbArray) {
	ran_discrete_omp_t * g = calloc(1, sizeof(ran_discrete_omp_t));
	float * ptotal = NULL;

	#pragma omp parallel 
	{
		#pragma omp master
		{
			g->nthreads = omp_get_num_threads();
			g->rans = calloc(g->nthreads, sizeof(gsl_ran_discretef_t *));
			g->starts = calloc(g->nthreads, sizeof(size_t));
			ptotal = calloc(g->nthreads, sizeof(float));
		}
		#pragma omp barrier

		int tid = omp_get_thread_num();

		size_t start = Kevents * tid / g->nthreads;
		size_t end = Kevents * (tid + 1)/ g->nthreads;
		size_t len = end - start;
		g->starts[tid] = start;
		g->rans[tid] = gsl_ran_discretef_preproc0(len, &ProbArray[start], &ptotal[tid]);
		#pragma omp barrier
		#pragma omp master 
		{
			g->ranroot = gsl_ran_discretef_preproc(g->nthreads, ptotal);
			free(ptotal);
		}
	}
	return g;
}