コード例 #1
0
ファイル: psycho_1.c プロジェクト: qyot27/twolame
/* mainly just changed the way range checking was done MFC Nov 1999 */
static void psycho_1_threshold(psycho_1_mem * mem, int *tone, int *noise, int bit_rate)
{
    int sub_size = mem->sub_size;
    mask *power = mem->power;
    g_thres *ltg = mem->ltg;
    int k, t;
    FLOAT dz, tmps, vf;

    for (k = 1; k < sub_size; k++) {
        ltg[k].x = DBMIN;
        t = *tone;              /* calculate individual masking threshold for */
        while ((t != LAST) && (t != STOP)) {    /* components in order to find the global */
            dz = ltg[k].bark - ltg[power[t].map].bark;  /* distance of bark value */
            if (dz >= -3.0 && dz < 8.0) {
                tmps = -1.525 - 0.275 * ltg[power[t].map].bark - 4.5 + power[t].x;
                /* masking function for lower & upper slopes */
                if (dz < -1)
                    vf = 17 * (dz + 1) - (0.4 * power[t].x + 6);
                else if (dz < 0)
                    vf = (0.4 * power[t].x + 6) * dz;
                else if (dz < 1)
                    vf = (-17 * dz);
                else
                    vf = -(dz - 1) * (17 - 0.15 * power[t].x) - 17;
                ltg[k].x = add_db(mem, ltg[k].x, tmps + vf);
            }
            t = power[t].next;
        }

        t = *noise;             /* calculate individual masking threshold */
        while ((t != LAST) && (t != STOP)) {    /* for non-tonal components to find LTG */
            dz = ltg[k].bark - ltg[power[t].map].bark;  /* distance of bark value */
            if (dz >= -3.0 && dz < 8.0) {
                tmps = -1.525 - 0.175 * ltg[power[t].map].bark - 0.5 + power[t].x;
                /* masking function for lower & upper slopes */
                if (dz < -1)
                    vf = 17 * (dz + 1) - (0.4 * power[t].x + 6);
                else if (dz < 0)
                    vf = (0.4 * power[t].x + 6) * dz;
                else if (dz < 1)
                    vf = (-17 * dz);
                else
                    vf = -(dz - 1) * (17 - 0.15 * power[t].x) - 17;
                ltg[k].x = add_db(mem, ltg[k].x, tmps + vf);
            }
            t = power[t].next;
        }
        if (bit_rate < 96)
            ltg[k].x = add_db(mem, ltg[k].hear, ltg[k].x);
        else
            ltg[k].x = add_db(mem, ltg[k].hear - 12.0, ltg[k].x);
    }

}
コード例 #2
0
ファイル: merchants.c プロジェクト: happyer/micposp2
int do_add_merchants(int param)
{
	int c;
	MERCHANTS merchants;
	char tmp[INFO_MAXINPUT + 1];

	LOG(LOG_DEBUG, "执行添加商户信息功能...");
	memset(&merchants, 0, sizeof(merchants));
INPUT_MID:
	printf("请输入[添加]商户编号:");
	scanf("%s", tmp);
	while((c = getchar()) != '\n' && c != EOF);//清空缓存
	if (strlen(tmp) != MID_SIZE || !isdigits(tmp, strlen(tmp))) {
		printf("输入数据必须是%d个数字!\n", MID_SIZE);
		goto INPUT_MID;
	}
	memcpy(merchants.mid, tmp, strlen(tmp));
INPUT_TID:
	printf("请输入终端编号:");
	scanf("%s", tmp);
	while((c = getchar()) != '\n' && c != EOF);//清空缓存
	if (strlen(tmp) != TID_SIZE || !isdigits(tmp, strlen(tmp))) {
		printf("输入数据必须是%d个数字!\n", TID_SIZE);
		goto INPUT_TID;
	}
	memcpy(merchants.tid, tmp, strlen(tmp));
INPUT_MNAME:
	printf("请输入商户名称:");
	scanf("%s", tmp);
	while((c = getchar()) != '\n' && c != EOF);//清空缓存
	if (strlen(tmp) > MNAME_MAXSIZE) {
		printf("输入数据不能超过%d个字节!\n", MNAME_MAXSIZE);
		goto INPUT_MNAME;
	}
	memcpy(merchants.mname, tmp, strlen(tmp));
INPUT_MMENU:
	printf("请输入商户菜单:");
	scanf("%s", tmp);
	while((c = getchar()) != '\n' && c != EOF);//清空缓存
	if (strlen(tmp) > MMENU_MAXSIZE) {
		printf("输入数据不能超过%d个字节!\n", MMENU_MAXSIZE);
		goto INPUT_MMENU;
	}
	memcpy(merchants.mmenu, tmp, strlen(tmp));
	if (sel_db(IT_MERCHANTS, merchants.mid, 0)) {
		printf("添加商户:%s失败,商户已经存在!\n", merchants.mid);
		return -1;
	}
	if (!add_db(IT_MERCHANTS, MEMBERS_COUNT, merchants.mid, merchants.tid, merchants.mname, merchants.mmenu)) {
		printf("添加商户:%s失败!\n", merchants.mid);
		return -1;
	} else {
		printf("添加商户:%s成功。\n", merchants.mid);
		return 0;
	}
}
コード例 #3
0
ファイル: psycho_1.c プロジェクト: qyot27/twolame
static void psycho_1_noise_label(psycho_1_mem * mem, int *noise, FLOAT energy[FFT_SIZE])
{
    int i, j, centre, last = LAST;
    FLOAT index, weight, sum;
    int crit_band = mem->crit_band;
    int *cbound = mem->cbound;
    mask *power = mem->power;
    /* calculate the remaining spectral */
    for (i = 0; i < crit_band - 1; i++) {   /* lines for non-tonal components */
        for (j = cbound[i], weight = 0.0, sum = DBMIN; j < cbound[i + 1]; j++) {
            if (power[j].type != TONE) {
                if (power[j].x != DBMIN) {
                    sum = add_db(mem, power[j].x, sum);
                    /* Weight is used in finding the geometric mean of the noise energy within a
                       subband */
                    weight += CF * energy[j] * (FLOAT) (j - cbound[i]) / (FLOAT) (cbound[i + 1] - cbound[i]);   /* correction
                                                                                                                 */
                    power[j].x = DBMIN;
                }
            }                   /* check to see if the spectral line is low dB, and if */
        }                       /* so replace the center of the critical band, which is */
        /* the center freq. of the noise component */

        if (sum <= DBMIN)
            centre = (cbound[i + 1] + cbound[i]) / 2;
        else {
            /* fprintf(stderr, "%i [%f %f] -", count++,weight/pow(10.0,0.1*sum),
               weight*pow(10.0,-0.1*sum)); */
            index = weight * pow(10.0, -0.1 * sum);
            centre = cbound[i] + (int) (index * (FLOAT) (cbound[i + 1] - cbound[i]));
        }


        /* locate next non-tonal component until finished; */
        /* add to list of non-tonal components */

        /* Masahiro Iwadare's fix for infinite looping problem? */
        if (power[centre].type == TONE) {
            if (power[centre + 1].type == TONE) {
                centre++;
            } else
                centre--;
        }

        if (last == LAST)
            *noise = centre;
        else {
            power[centre].next = LAST;
            power[last].next = centre;
        }
        power[centre].x = sum;
        power[centre].type = NOISE;
        last = centre;
    }
}
コード例 #4
0
ファイル: set_dbinfo.c プロジェクト: crherar/Admin
krb5_error_code
krb5_kdc_set_dbinfo(krb5_context context, struct krb5_kdc_configuration *c)
{
    struct hdb_dbinfo *info, *d;
    krb5_error_code ret;
    int i;

    /* fetch the databases */
    ret = hdb_get_dbinfo(context, &info);
    if (ret)
	return ret;

    d = NULL;
    while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
	
	ret = add_db(context, c,
		     hdb_dbinfo_get_dbname(context, d),
		     hdb_dbinfo_get_mkey_file(context, d));
	if (ret)
	    goto out;
	
	kdc_log(context, c, 0, "label: %s",
		hdb_dbinfo_get_label(context, d));
	kdc_log(context, c, 0, "\tdbname: %s",
		hdb_dbinfo_get_dbname(context, d));
	kdc_log(context, c, 0, "\tmkey_file: %s",
		hdb_dbinfo_get_mkey_file(context, d));
	kdc_log(context, c, 0, "\tacl_file: %s",
		hdb_dbinfo_get_acl_file(context, d));
    }
    hdb_free_dbinfo(context, &info);

    return 0;
out:
    for (i = 0; i < c->num_db; i++)
	if (c->db[i] && c->db[i]->hdb_destroy)
	    (*c->db[i]->hdb_destroy)(context, c->db[i]);
    c->num_db = 0;
    free(c->db);
    c->db = NULL;

    hdb_free_dbinfo(context, &info);

    return ret;
}
コード例 #5
0
ファイル: init_utils.c プロジェクト: JoshCooley/irrd
/*
 * After we scan the IRRd file, the database are listed under the
 *  ci.srcs list.  Make a new list of rps_database_t type for use.
 * Make our own ACL list (read_conf only has host names, we want unsigned
 * long addresses for fast comparison)
 */
void parse_ci_srcs(){
  source_t * tmp;
  rps_database_t * ndbp;

  for(tmp = ci.srcs; tmp; tmp = tmp->next){
    if( !tmp->rpsdist_flag || !tmp->source )
      continue;
    
    ndbp = (rps_database_t *)malloc(sizeof(rps_database_t));
    if(!ndbp){
      trace(ERROR, default_trace, "parse_ci_srcs: Malloc error\n");
      fprintf(stderr, "parse_ci_srcs: Malloc error\n");
      exit(EXIT_ERROR);
    }
    bzero(ndbp, sizeof(rps_database_t));
    ndbp->name = tmp->source;
    ndbp->authoritative = tmp->authoritative;
    pthread_mutex_init(&ndbp->lock, NULL);
    ndbp->trusted = tmp->rpsdist_trusted;
    ndbp->pgppass = tmp->rpsdist_pgppass;
    if( tmp->rpsdist_host )
      ndbp->host = name_to_addr(tmp->rpsdist_host);
    if(tmp->rpsdist_port)
      ndbp->port = atoi(tmp->rpsdist_port);
    if( (ndbp->hexid = get_db_line_from_irrd_obj(ndbp->name, ndbp->name, ci.irrd_host, ci.irrd_port, "repository",
					    "repository-cert:[ \t]*PGPKEY-([a-f0-9]{8})[\n]?$")) == NULL){
      trace(ERROR, default_trace, "parce_ci_srcs: The database %s isn't in IRRD, Abort!\n", ndbp->name);
      fprintf(stderr, "parce_ci_srcs: The database %s isn't in IRRD, Abort!\n", ndbp->name);
      exit(EXIT_ERROR);
    }
    if(ndbp->authoritative)
      check_auth_db(ndbp);

    add_db(ndbp);
  }
}
コード例 #6
0
ファイル: psycho_1.c プロジェクト: qyot27/twolame
static void psycho_1_tonal_label(psycho_1_mem * mem, int *tone)
/* this function extracts (tonal)  sinusoidals from the spectrum  */
{
    int i, j, last = LAST, first, run, last_but_one = LAST; /* dpwe */
    FLOAT max;
    mask *power = mem->power;

    *tone = LAST;
    for (i = 2; i < HAN_SIZE - 12; i++) {
        if (power[i].x > power[i - 1].x && power[i].x >= power[i + 1].x) {
            power[i].type = TONE;
            power[i].next = LAST;
            if (last != LAST)
                power[last].next = i;
            else
                first = *tone = i;
            last = i;
        }
    }
    last = LAST;
    first = *tone;
    *tone = LAST;
    while ((first != LAST) && (first != STOP)) {    /* the conditions for the tonal */
        if (first < 3 || first > 500)
            run = 0;            /* otherwise k+/-j will be out of bounds */
        else if (first < 63)
            run = 2;            /* components in layer II, which */
        else if (first < 127)
            run = 3;            /* are the boundaries for calc.  */
        else if (first < 255)
            run = 6;            /* the tonal components */
        else
            run = 12;
        max = power[first].x - 7;   /* after calculation of tonal */
        for (j = 2; j <= run; j++)  /* components, set to local max */
            if (max < power[first - j].x || max < power[first + j].x) {
                power[first].type = FALSE;
                break;
            }
        if (power[first].type == TONE) {    /* extract tonal components */
            int help = first;
            if (*tone == LAST)
                *tone = first;
            while ((power[help].next != LAST) && (power[help].next - first) <= run)
                help = power[help].next;
            help = power[help].next;
            power[first].next = help;
            if ((first - last) <= run) {
                if (last_but_one != LAST)
                    power[last_but_one].next = first;
            }
            if (first > 1 && first < 500) { /* calculate the sum of the */
                FLOAT tmp;      /* powers of the components */
                tmp = add_db(mem, power[first - 1].x, power[first + 1].x);
                power[first].x = add_db(mem, power[first].x, tmp);
            }
            for (j = 1; j <= run; j++) {
                power[first - j].x = power[first + j].x = DBMIN;
                power[first - j].next = power[first + j].next = STOP;
                power[first - j].type = power[first + j].type = FALSE;
            }
            last_but_one = last;
            last = first;
            first = power[first].next;
        } else {
            int ll;
            if (last == LAST);  /* *tone = power[first].next; dpwe */
            else
                power[last].next = power[first].next;
            ll = first;
            first = power[first].next;
            power[ll].next = STOP;
        }
    }
}
コード例 #7
0
ファイル: sha2.C プロジェクト: Halfnhav4/okws
 oksrvc_sha_t (int argc, char *argv[]) : oksrvc_t (argc, argv) 
 {
   shadb = add_db ("-", SHAD_PORT, sha_prog_1);
 }
コード例 #8
0
ファイル: sha.C プロジェクト: Halfnhav4/okws
 oksrvc_sha_t (int argc, char *argv[]) : oksrvc_t (argc, argv) 
 {
   // Non-boiler-plate: connect to a particular db proxy
   shadb = add_db ("-", SHAD_PORT, sha_prog_1);
 }