Example #1
0
static void find_peaks(DCAContext *c)
{
    int band, ch;

    for (band = 0; band < 32; band++)
        for (ch = 0; ch < c->fullband_channels; ch++) {
            int sample;
            int32_t m = 0;

            for (sample = 0; sample < SUBBAND_SAMPLES; sample++) {
                int32_t s = abs(c->subband[sample][band][ch]);
                if (m < s)
                    m = s;
            }
            c->peak_cb[band][ch] = get_cb(m);
        }

    if (c->lfe_channel) {
        int sample;
        int32_t m = 0;

        for (sample = 0; sample < DCA_LFE_SAMPLES; sample++)
            if (m < abs(c->downsampled_lfe[sample]))
                m = abs(c->downsampled_lfe[sample]);
        c->lfe_peak_cb = get_cb(m);
    }
}
Example #2
0
static void adjust_jnd(int samplerate_index,
                       const int32_t in[512], int32_t out_cb[256])
{
    int32_t power[256];
    cplx32 out[256];
    int32_t out_cb_unnorm[256];
    int32_t denom;
    const int32_t ca_cb = -1114;
    const int32_t cs_cb = 928;
    int i, j;

    fft(in, out);

    for (j = 0; j < 256; j++) {
        power[j] = add_cb(get_cb(out[j].re), get_cb(out[j].im));
        out_cb_unnorm[j] = -2047; /* and can only grow */
    }

    for (i = 0; i < AUBANDS; i++) {
        denom = ca_cb; /* and can only grow */
        for (j = 0; j < 256; j++)
            denom = add_cb(denom, power[j] + auf[samplerate_index][i][j]);
        for (j = 0; j < 256; j++)
            out_cb_unnorm[j] = add_cb(out_cb_unnorm[j],
                    -denom + auf[samplerate_index][i][j]);
    }

    for (j = 0; j < 256; j++)
        out_cb[j] = add_cb(out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb);
}
Example #3
0
w_rc_t bf_tree_m::_grab_free_block(bf_idx& ret, bool evict)
{
    ret = 0;
    while (true) {
        // once the bufferpool becomes full, getting _freelist_lock everytime will be
        // too costly. so, we check _freelist_len without lock first.
        //   false positive : fine. we do real check with locks in it
        //   false negative : fine. we will eventually get some free block anyways.
        if (_freelist_len > 0) {
            CRITICAL_SECTION(cs, &_freelist_lock);
            if (_freelist_len > 0) { // here, we do the real check
                bf_idx idx = FREELIST_HEAD;
                DBG5(<< "Grabbing idx " << idx);
                w_assert1(_is_valid_idx(idx));
                w_assert1 (!get_cb(idx)._used);
                ret = idx;

                --_freelist_len;
                if (_freelist_len == 0) {
                    FREELIST_HEAD = 0;
                } else {
                    FREELIST_HEAD = _freelist[idx];
                    w_assert1 (FREELIST_HEAD > 0 && FREELIST_HEAD < _block_cnt);
                }
                DBG5(<< "New head " << FREELIST_HEAD);
                w_assert1(ret != FREELIST_HEAD);
                return RCOK;
            }
        } // exit the scope to do the following out of the critical section
Example #4
0
void f_async_db_exec(){
    array_t *info;
    db_t *db;
    info = allocate_empty_array(1);
    info->item[0].type = T_STRING;
    info->item[0].subtype = STRING_MALLOC;
    info->item[0].u.string = string_copy((sp-1)->u.string, "f_db_exec");
    valid_database("exec", info);

    db = find_db_conn((sp-1)->u.number);
    if (!db) {
        error("Attempt to exec on an invalid database handle\n");
    }

    if (db->type->cleanup) {
        db->type->cleanup(&(db->c));
    }

    function_to_call_t *cb = get_cb();
    process_efun_callback(2, cb, F_ASYNC_READ);
    cb->f.fp->hdr.ref++;

    add_db_exec(db, (sp-1)->u.string, cb);
    pop_2_elems();
}
Example #5
0
void f_async_write(){
    function_to_call_t *cb = get_cb();
    process_efun_callback(3, cb, F_ASYNC_WRITE);
    cb->f.fp->hdr.ref++;
    add_write(check_valid_path((sp-3)->u.string, current_object, "write_file", 1), (sp-2)->u.string, strlen((sp-2)->u.string), (sp-1)->u.number, cb);
    pop_n_elems(4);
}
Example #6
0
void f_async_getdir(){
    function_to_call_t *cb = get_cb();
    process_efun_callback(1, cb, F_ASYNC_READ);
    cb->f.fp->hdr.ref++;
    add_getdir(check_valid_path((sp-1)->u.string, current_object, "get_dir", 0), cb);
    pop_2_elems();
}
Example #7
0
File: async.c Project: Elohim/FGmud
void f_async_db_exec(){
	array_t *info;
	db_t *db;
	info = allocate_empty_array(1);
	info->item[0].type = T_STRING;
	info->item[0].subtype = STRING_MALLOC;
	info->item[0].u.string = string_copy((sp-1)->u.string, "f_db_exec");
	int num_arg = st_num_arg;
	valid_database("exec", info);

	db = find_db_conn((sp-2)->u.number);
	if (!db) {
		error("Attempt to exec on an invalid database handle\n");
	}
	if(!db_mut){
		db_mut = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(db_mut, NULL);
	}
	st_num_arg = num_arg;
	function_to_call_t *cb = get_cb();
	process_efun_callback(2, cb, F_ASYNC_DB_EXEC);
	cb->f.fp->hdr.ref++;

	add_db_exec((sp-2)->u.number, cb);
	pop_3_elems();
}
Example #8
0
static void
dump_cb(afs_uint32 idx)
{
    if (get_cb(idx)) {
	fprintf(stderr, "error getting cb %d\n", idx);
	return;
    }

    DPFOFF(cb_cursor.cursor);
    dump_cb_entry();
}
static void parse_button(xmlNodePtr node, button * btn) {
    xmlAttrPtr attr;
    rect_t rect;

    attr = node->properties;
    while(attr != NULL) {
        char *value = (char *) xmlGetProp(node, (const xmlChar *) attr->name);

        if(value != NULL) {
            if(!xmlStrcmp(attr->name, (const xmlChar *) "name")) {
                btn->set_name(value);
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "text"))
                btn->set_text(get_string(value));
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "image")) {
                btn->set_image(value);
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "onclick")) {
                btn->set_cb(get_cb(value));
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "color"))
                btn->set_color(strtol(value, NULL, 0));
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "x_abs"))
                rect.x = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "y_abs"))
                rect.y = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "w_abs"))
                rect.w = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "h_abs"))
                rect.h = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "x_rel")) {
                rect.x = atoi(value) * gr_fb_width() / 100;
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "y_rel")) {
                rect.y = atoi(value) * gr_fb_height() / 100;
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "w_rel")) {
                rect.w = atoi(value) * gr_fb_width() / 100;
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "h_rel")) {
                rect.h = atoi(value) * gr_fb_height() / 100;
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "visibility")) {
                if(!strcmp("invisible", value))
                    btn->set_visibility(false);
                else
                    btn->set_visibility(true);
            }

            xmlFree(value);
        }

        attr = attr->next;
    }
    btn->set_rect(&rect);
}
Example #10
0
VALUE ruby_libvirt_get_parameters(VALUE d, unsigned int flags, void *opaque,
                                  unsigned int typesize,
                                  const char *(*nparams_cb)(VALUE d,
                                                            unsigned int flags,
                                                            void *opaque,
                                                            int *nparams),
                                  const char *(*get_cb)(VALUE d,
                                                        unsigned int flags,
                                                        void *voidparams,
                                                        int *nparams,
                                                        void *opaque),
                                  void (*hash_set)(void *voidparams, int i,
                                                   VALUE result))
{
    int nparams = 0;
    void *params;
    VALUE result;
    const char *errname;
    int i;

    errname = nparams_cb(d, flags, opaque, &nparams);
    ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname,
                                ruby_libvirt_connect_get(d));

    result = rb_hash_new();

    if (nparams == 0) {
        return result;
    }

    params = alloca(typesize * nparams);

    errname = get_cb(d, flags, params, &nparams, opaque);
    ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname,
                                ruby_libvirt_connect_get(d));

    for (i = 0; i < nparams; i++) {
        hash_set(params, i, result);
    }

    return result;
}
Example #11
0
static void shell(int arg1, int arg2)
{
	char *argv[ARGC_MAX + 1];
	size_t argc;

	while (1) {
		struct uart_console_input *cmd;
		shell_cmd_function_t cb;

		printk("%s", get_prompt());

		cmd = nano_fiber_fifo_get(&cmds_queue, TICKS_UNLIMITED);

		argc = line2argv(cmd->line, argv, ARRAY_SIZE(argv));
		if (!argc) {
			nano_fiber_fifo_put(&avail_queue, cmd);
			continue;
		}

		cb = get_cb(argv[0]);
		if (!cb) {
			if (app_cmd_handler != NULL) {
				cb = app_cmd_handler;
			} else {
				printk("Unrecognized command: %s\n", argv[0]);
				printk("Type 'help' for list of available commands\n");
				nano_fiber_fifo_put(&avail_queue, cmd);
				continue;
			}
		}

		/* Execute callback with arguments */
		if (cb(argc, argv) < 0) {
			show_cmd_help(argc, argv);
		}

		nano_fiber_fifo_put(&avail_queue, cmd);
	}
}
Example #12
0
int shell_exec(char *line)
{
	char *argv[ARGC_MAX + 1];
	int argc;
	int module = default_module;
	int err;
	shell_cmd_function_t cb;

	argc = line2argv(line, argv, ARRAY_SIZE(argv));
	if (!argc) {
		return -EINVAL;
	}

	err = argc;

	cb = get_cb(&argc, argv, &module);
	if (!cb) {
		if (app_cmd_handler != NULL) {
			cb = app_cmd_handler;
		} else {
			print_cmd_unknown(argv[0]);
			return -EINVAL;
		}
	}

	/* Execute callback with arguments */
	if (module != -1 && module != default_module) {
		/* Ajust parameters to point to the actual command */
		err = cb(argc - 1, &argv[1]);
	} else {
		err = cb(argc, argv);
	}

	if (err < 0) {
		show_cmd_help(argv);
	}

	return err;
}
Example #13
0
static int
find_cb_by_index(afs_uint32 idx)
{
    int i;

    if (get_fe_hdr()) {
	return 1;
    }

    for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
	if (get_cb(i)) {
	    fprintf(stderr, "error getting cb %d\n", i);
	    return 1;
	}
	if (cb_cursor.cb.index == idx)
	    break;
    }

    if (i < fe_cursor.hdr.nCBs) {
	dump_this_cb();
	return 0;
    }
    return 1;
}
static void parse_listview(xmlNodePtr node, listview * view) {
    xmlAttrPtr attr;
    rect_t rect;

    attr = node->properties;
    while(attr != NULL) {
        char *value = (char *) xmlGetProp(node, (const xmlChar *) attr->name);

        if(value != NULL) {
            if(!xmlStrcmp(attr->name, (const xmlChar *) "name"))
                view->set_name(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "onclick"))
                view->set_cb(get_cb(value));
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "x_abs"))
                rect.x = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "y_abs"))
                rect.y = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "w_abs"))
                rect.w = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "h_abs"))
                rect.h = atoi(value);
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "x_rel")) {
                rect.x = atoi(value) * gr_fb_width() / 100;
            } else if(!xmlStrcmp(attr->name, (const xmlChar *) "y_rel"))
                rect.y = atoi(value) * gr_fb_height() / 100;
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "w_rel"))
                rect.w = atoi(value) * gr_fb_width() / 100;
            else if(!xmlStrcmp(attr->name, (const xmlChar *) "h_rel"))
                rect.h = atoi(value) * gr_fb_height() / 100;

            xmlFree(value);
        }
        attr = attr->next;
    }
    view->set_rect(&rect);
}