static void runDivider(LADSPA_Handle instance, unsigned long sample_count) {
	Divider *plugin_data = (Divider *)instance;

	/* Denominator (float value) */
	const LADSPA_Data denominator = *(plugin_data->denominator);

	/* Input (array of floats of length sample_count) */
	const LADSPA_Data * const input = plugin_data->input;

	/* Output (array of floats of length sample_count) */
	LADSPA_Data * const output = plugin_data->output;
	LADSPA_Data amp = plugin_data->amp;
	float count = plugin_data->count;
	LADSPA_Data lamp = plugin_data->lamp;
	LADSPA_Data last = plugin_data->last;
	LADSPA_Data out = plugin_data->out;
	int zeroxs = plugin_data->zeroxs;

#line 25 "divider_1186.xml"
	/* Integer version of denominator */
	int den = (int)denominator;
	
	unsigned long pos;
	
	for (pos = 0; pos < sample_count; pos++) {
	        count += 1.0f;
	        if ((input[pos] > 0.0f && last <= 0.0f) ||
	         (input[pos] < 0.0f && last >= 0.0)) {
	                zeroxs++;
	                if (den == 1) {
	                        out = out > 0.0f ? -1.0f : 1.0f;
	                        lamp = amp / count;
	                        zeroxs = 0;
	                        count = 0;
	                        amp = 0;
	                }
	        }
	        amp += fabs(input[pos]);
	        if (den > 1 && (zeroxs % den) == den-1) {
	                out = out > 0.0f ? -1.0f : 1.0f;
	                lamp = amp / count;
	                zeroxs = 0;
	                count = 0;
	                amp = 0;
	        }
	        last = input[pos];
	        buffer_write(output[pos], out * lamp);
	}
	
	plugin_data->last = last;
	plugin_data->amp = amp;
	plugin_data->lamp = lamp;
	plugin_data->zeroxs = zeroxs;
	plugin_data->count = count;
	plugin_data->out = out;
}
Esempio n. 2
0
Datum
query_buffer_flush(PG_FUNCTION_ARGS)
{
    
    LWLockAcquire(log_file->lock, LW_EXCLUSIVE);
    buffer_write();
    LWLockRelease(log_file->lock);
    
    PG_RETURN_VOID();
}
Esempio n. 3
0
static void runAddingXfade4(LADSPA_Handle instance, unsigned long sample_count) {
	Xfade4 *plugin_data = (Xfade4 *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Crossfade (float value) */
	const LADSPA_Data xfade = *(plugin_data->xfade);

	/* Input A left (array of floats of length sample_count) */
	const LADSPA_Data * const inputLA = plugin_data->inputLA;

	/* Input A right (array of floats of length sample_count) */
	const LADSPA_Data * const inputRA = plugin_data->inputRA;

	/* Input B left (array of floats of length sample_count) */
	const LADSPA_Data * const inputLB = plugin_data->inputLB;

	/* Input B right (array of floats of length sample_count) */
	const LADSPA_Data * const inputRB = plugin_data->inputRB;

	/* Output A left (array of floats of length sample_count) */
	LADSPA_Data * const outputLA = plugin_data->outputLA;

	/* Output A right (array of floats of length sample_count) */
	LADSPA_Data * const outputRA = plugin_data->outputRA;

	/* Output B left (array of floats of length sample_count) */
	LADSPA_Data * const outputLB = plugin_data->outputLB;

	/* Output B right (array of floats of length sample_count) */
	LADSPA_Data * const outputRB = plugin_data->outputRB;

#line 19 "xfade_1915.xml"
	unsigned long pos;
	const float coefB = (xfade + 1.0f) * 0.5f;
	const float coefA = 1.0f - coefB;

	for (pos = 0; pos < sample_count; pos++) {
	  buffer_write(outputLA[pos], inputLA[pos] * coefA);
	  buffer_write(outputRA[pos], inputRA[pos] * coefA);
	  buffer_write(outputLB[pos], inputLB[pos] * coefB);
	  buffer_write(outputRB[pos], inputRB[pos] * coefB);
	}
}
Esempio n. 4
0
//Pessoa termina - Morre
void person_end(ElevatorMonitor* monitor, int thread, buffer *buff){
    pthread_mutex_lock(&monitor->monitorGlobalLock);
    

    monitor->number_of_clients--;
    buffer_write(buff, thread, monitor->start_time, 'M', 0);
    
    
    pthread_mutex_unlock(&monitor->monitorGlobalLock);
}
Esempio n. 5
0
void
tty_puts(struct tty *tty, const char *s)
{
	if (*s == '\0')
		return;
	buffer_write(tty->out, s, strlen(s));

	if (tty->log_fd != -1)
		write(tty->log_fd, s, strlen(s));
}
Esempio n. 6
0
/* Translate mouse and output. */
void
input_mouse(struct window_pane *wp, struct mouse_event *m)
{
	if (wp->screen->mode & MODE_MOUSE) {
		buffer_write(wp->out, "\033[M", 3);
		buffer_write8(wp->out, m->b + 32);
		buffer_write8(wp->out, m->x + 33);
		buffer_write8(wp->out, m->y + 33);
	}
}
Esempio n. 7
0
void
cmd_new_window_send(struct cmd *self, struct buffer *b)
{
	struct cmd_new_window_data	*data = self->data;

	buffer_write(b, data, sizeof *data);
	cmd_send_string(b, data->target);
	cmd_send_string(b, data->name);
	cmd_send_string(b, data->cmd);
}
Esempio n. 8
0
File: buffer.c Progetto: kaye64/gem
/**
 * Writes the entire contents (and only the entire contents)
 * of a codec to a buffer_t
 * returns: Whether the operation was a success
 */
bool codec_buffer_write(codec_t* codec, buffer_t* buffer)
{
	buffer_pushp(buffer);
	if (buffer_write(buffer, codec->data, codec_len(codec)) < codec_len(codec)) {
		buffer_popp(buffer);
		return false;
	}
	buffer_dropp(buffer);
	return true;
}
Esempio n. 9
0
static void test_buffer_write(void)
{
	buffer_t *buf;

	test_begin("buffer_write");
	buf = t_buffer_create(8);
	buffer_write(buf, 5, buf, 0);
	test_assert(buf->used == 5);
	test_end();
}
Esempio n. 10
0
ssize_t
argos_net_send_errmsg(struct argos_net_conn *conn, uint16_t errnum,
    const char *errmsg)
{
    if (conn->state == ARGOS_NET_CONN_DEAD) {
        orion_log_err("unable to send on DEAD network handle");
        errno = EBADF;
        return -1;
    }

    if (conn->shutdown) {
        /* illegal to try to send after argos_net_shutdown() is called */
        errno = EPIPE;
        return -1;
    }

    int slen = strlen(errmsg);
    if (slen > (1 << 16)) {
        errno = EMSGSIZE;
        return -1;
    }

    struct argos_net_error_msg msg;
    msg.msgtype = htons(ARGOS_NET_ERROR_MSGTYPE);
    msg.msglen = htonl(sizeof(struct argos_net_error_msg) + slen);
    msg.errnum = htons(errnum);

    /* error messages enqueue directly into the outbuf */
    size_t reqlen = sizeof(msg) + slen;
    if (buffer_remaining(conn->outbuf) < reqlen) {
        errno = ENOBUFS;
        return -1;
    }

    int rv = buffer_write(conn->outbuf, &msg, sizeof(msg));
    assert(rv >= 0);

    rv = buffer_write(conn->outbuf, errmsg, slen);
    assert(rv >= 0);

    return reqlen;
}
Esempio n. 11
0
void rpk_dropback(rpacket_t r,uint32_t dropsize)
{
    if(!r || PACKET_RAW(r) || r->len < dropsize)
        return;
    r->len -= dropsize;
    if(r->data_remain > dropsize)
        r->data_remain -= dropsize;
    else
        r->data_remain = 0;
    buffer_write(PACKET_BUF(r),PACKET_BEGINPOS(r),(int8_t*)&r->len,sizeof(r->len));
}
Esempio n. 12
0
void CPeerBase::EncodeBYTE(BYTE b)
{
	if (!m_outBuffer)
	{
		sys_err("Not ready to write");
		return;
	}

	buffer_write(m_outBuffer, &b, 1);
	fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true);
}
Esempio n. 13
0
void channel_handle_client_read(connector_t pconn, int event)
{
    //由于和客户端只有一次交互,不用一直读取
    if (connector_read(pconn, event) > 0)
    {
        char *val = buffer_get_read(pconn->preadbuf);
        message_t pmsg = (message_t)malloc(sizeof(message));
        memset(pmsg, 0, sizeof(pmsg));
        size_t len1 = get_client_msg(val, pmsg);

        if (len1 == 0)
        {
            print_log(LOG_TYPE_ERROR, "Read Client Msg Error %s", val);
            free(pmsg);
            return;
        }

        char data[20] = {0};
        memcpy(data, pmsg->uid, pmsg->len);
        buffer_read(pconn->preadbuf, len1, TRUE);

        memcpy(pconn->uid, data, pmsg->len);

        int len2 = sizeof(connector_t);
        ht_insert(pconn->pworker->pht, data, (pmsg->len)+1, pconn, len2+1);

        context_t pcontext = (context_t)malloc(sizeof(context));
        memset(pcontext, 0, sizeof(context));
        memcpy(pcontext->data, data, pmsg->len);
        list_push_tail(pconn->pworker->plist, pcontext);

        //print_log(LOG_TYPE_DEBUG, "Hash key %s, Len %d", pcontext->data, pmsg->len);

        char cmd[REDIS_CMD_LEN] = {'\0'};
        get_request_str(data, cmd);

        int len = strlen(cmd);

        if (pconn->pworker->redis->state == CONN_STATE_RUN)
        {
            buffer_write(pconn->pworker->redis->pwritebuf, cmd, len);
            connector_write(pconn->pworker->redis);
        }
        else
        {
            print_log(LOG_TYPE_ERROR, "Redis not run");
            list_pop_head(pconn->pworker->plist);
            ht_remove(pconn->pworker->pht, data, (pmsg->len)+1);
            pconn->pworker->neterr_count++;
        }

        free(pmsg);
    }
}
Esempio n. 14
0
void CPeerBase::EncodeDWORD(DWORD dw)
{
	if (!m_outBuffer)
	{
		sys_err("Not ready to write");
		return;
	}

	buffer_write(m_outBuffer, &dw, 4);
	fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true);
}
Esempio n. 15
0
void array_idx_set_i(struct array *array, unsigned int idx, const void *data)
{
	size_t pos;

	pos = idx * array->element_size;
	if (pos > array->buffer->used) {
		/* index doesn't exist yet, initialize with zero */
		buffer_append_zero(array->buffer, pos - array->buffer->used);
	}
	buffer_write(array->buffer, pos, data, array->element_size);
}
Esempio n. 16
0
/*UART's routine*/
static void duart_handler(void)
{
  Int8U byte;
	while ( !( HW_UARTDBG_FR & DUART_RECEIVE_FIFO_EMPTY ) ) {

   byte = HW_UARTDBG_DR;

   buffer_write( pointer_duart_buffer, byte);

	}
}
Esempio n. 17
0
void CPeerBase::Encode(const void* data, DWORD size)
{
	if (!m_outBuffer)
	{
		sys_err("Not ready to write");
		return;
	}

	buffer_write(m_outBuffer, data, size);
	fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true);
}
Esempio n. 18
0
static void
marshal_str(struct buffer* b, const char* s)
{
	if(!s) marshal_u8(b, 0);
	else {
		size_t len = strlen(s);
		marshal_u8(b, 1);
		buffer_reserve(b, len+1);
		buffer_write(b, s, len+1);
	}
}
Esempio n. 19
0
static uint8_t adios_transform_serialize_transform(enum ADIOS_TRANSFORM_TYPE transform_type,
                                                   enum ADIOS_DATATYPES pre_transform_type,
                                                   const struct adios_index_characteristic_dims_struct_v1 *pre_transform_dimensions,
                                                   uint16_t transform_metadata_len,
                                                   void *transform_metadata,
                                                   uint64_t *write_length, char **buffer, uint64_t *buffer_size, uint64_t *buffer_offset) {

    // Either there is no metadata, or the metadata buffer is non-null
    assert(!transform_metadata_len || transform_metadata);

    *write_length = 0;

    // No transform case
    if (transform_type == adios_transform_none)
        return 0;

    // From this point on, this is an actual transform type

    // Write characteristic flag
    uint8_t flag = (uint8_t)adios_characteristic_transform_type;
    buffer_write(buffer, buffer_size, buffer_offset, &flag, 1);
    *write_length += 1;

    // Write transform type
    //buffer_write(buffer, buffer_size, buffer_offset, &transform_type, 1);
    //*write_length += 1;
    serialize_transform_type(transform_type, write_length, buffer, buffer_size, buffer_offset);

    // Write the pre-transform datatype
    flag = (uint8_t) pre_transform_type; // convert down to a single byte
    buffer_write(buffer, buffer_size, buffer_offset, &flag, 1);
    *write_length += 1;

    // Write the number of pre-transform dimensions
    buffer_write (buffer, buffer_size, buffer_offset, &pre_transform_dimensions->count, 1);
    *write_length += 1;

    // Write the length of pre-transform dimension data about to be written
    uint16_t len = 3 * 8 * pre_transform_dimensions->count;
    buffer_write (buffer, buffer_size, buffer_offset, &len, 2);
    *write_length += 2;

    // Write the pre-transform dimensions
    buffer_write (buffer, buffer_size, buffer_offset, pre_transform_dimensions->dims, len);
    *write_length += len;

    buffer_write (buffer, buffer_size, buffer_offset, &transform_metadata_len, 2);
    *write_length += 2;

    if (transform_metadata_len) {
        buffer_write (buffer, buffer_size, buffer_offset, transform_metadata, transform_metadata_len);
        *write_length += transform_metadata_len;
    }

    return 1; // Return that we wrote 1 characteristic flag
}
Esempio n. 20
0
void buffer_insert(buffer_t *_buf, size_t pos,
		   const void *data, size_t data_size)
{
	struct real_buffer *buf = (struct real_buffer *)_buf;

	if (pos >= buf->used)
		buffer_write(_buf, pos, data, data_size);
	else {
		buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
		memcpy(buf->w_buffer + pos, data, data_size);
	}
}
Esempio n. 21
0
static void str_add_nul(string_t *str)
{
	const unsigned char *data = str_data(str);
	size_t len = str_len(str);
	size_t alloc = buffer_get_size(str);

	if (len == alloc || data[len] != '\0') {
		buffer_write(str, len, "", 1);
		/* remove the \0 - we don't want to keep it */
		buffer_set_used_size(str, len);
	}
}
Esempio n. 22
0
static void runFadDelay(LV2_Handle instance, uint32_t sample_count)
{
  FadDelay *plugin_data = (FadDelay *)instance;

  const float delay = *(plugin_data->delay);
  const float fb_db = *(plugin_data->fb_db);
  const float * const input = plugin_data->input;
  float * const output = plugin_data->output;
  float * buffer = plugin_data->buffer;
  float phase = plugin_data->phase;
  int last_phase = plugin_data->last_phase;
  float last_in = plugin_data->last_in;
  unsigned long buffer_size = plugin_data->buffer_size;
  unsigned long buffer_mask = plugin_data->buffer_mask;
  long sample_rate = plugin_data->sample_rate;
  
long int pos;
float increment = (float)buffer_size / ((float)sample_rate *
					f_max(fabs(delay), 0.01));
float lin_int, lin_inc;
int track;
int fph;
float out;
const float fb = DB_CO(fb_db);

for (pos = 0; pos < sample_count; pos++) {
	fph = f_round(floor(phase));
	last_phase = fph;
	lin_int = phase - (float)fph;
	out = LIN_INTERP(lin_int, buffer[(fph+1) & buffer_mask],
	 buffer[(fph+2) & buffer_mask]);
	phase += increment;
	lin_inc = 1.0f / (floor(phase) - last_phase + 1);
	lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc;
	lin_int = 0.0f;
	for (track = last_phase; track < phase; track++) {
		lin_int += lin_inc;
		buffer[track % buffer_size] = out * fb +
		 LIN_INTERP(lin_int, last_in, input[pos]);
	}
	last_in = input[pos];
	buffer_write(output[pos], out);
	if (phase >= buffer_size) {
		phase -= buffer_size;
	}
}

// Store current phase in instance
plugin_data->phase = phase;
plugin_data->last_phase = last_phase;
plugin_data->last_in = last_in;
		
}
Esempio n. 23
0
static int write_plateaus(struct nl_buffer *buffer, cJSON *root)
{
	struct global_value *chunk;
	size_t size;
	cJSON *json;
	__u16 *plateaus;
	__u16 i;
	/* TODO (later) I found a bug in gcc; remove "= -EINVAL." */
	int error = -EINVAL;

	i = 0;
	for (json = root->child; json; json = json->next) {
		if (i > PLATEAUS_MAX) {
			log_err("Too many plateaus. (max is %u)", PLATEAUS_MAX);
			return -EINVAL;
		}
		i++;
	}

	size = sizeof(struct global_value) + i * sizeof(__u16);
	chunk = malloc(size);
	if (!chunk) {
		log_err("Out of memory.");
		return -ENOMEM;
	}

	chunk->type = MTU_PLATEAUS;
	chunk->len = size;
	plateaus = (__u16 *)(chunk + 1);

	i = 0;
	for (json = root->child; json; json = json->next) {
		if (json->type != cJSON_Number) {
			log_err("'%s' is not a number.", json->valuestring);
			log_err("(Quotation marks might also be the problem.)");
			goto end;
		}
		if (json->valueint < 0 || 0xFFFF < json->valueint) {
			log_err("'%d' is out of range (0-65535).",
					json->valueint);
			goto end;
		}
		plateaus[i] = json->valueint;
		i++;
	}

	error = buffer_write(buffer, chunk, size, SEC_GLOBAL);
	/* Fall through. */

end:
	free(chunk);
	return error;
}
Esempio n. 24
0
static int handle_eamt(cJSON *json)
{
	struct nl_buffer *buffer;
	cJSON *prefix_json;
	struct eamt_entry eam;
	unsigned int i = 1;
	int error;

	if (!json)
		return 0;

	buffer = buffer_create(SEC_EAMT);
	if (!buffer)
		return -ENOMEM;

	for (json = json->child; json; json = json->next, i++) {
		prefix_json = cJSON_GetObjectItem(json, "ipv6 Prefix");
		if (!prefix_json) {
			log_err("EAM entry #%u lacks an 'ipv6 prefix' field.", i);
			error = -EINVAL;
			goto end;
		}
		error = str_to_prefix6(prefix_json->valuestring, &eam.prefix6);
		if (error) {
			log_err("Error found on EAM entry #%u.", i);
			goto end;
		}

		prefix_json = cJSON_GetObjectItem(json, "ipv4 Prefix");
		if (!prefix_json) {
			log_err("EAM entry #%u lacks an 'ipv4 prefix' field.", i);
			error = -EINVAL;
			goto end;
		}
		error = str_to_prefix4(prefix_json->valuestring, &eam.prefix4);
		if (error) {
			log_err("Error found on EAM entry #%u.", i);
			goto end;
		}

		error = buffer_write(buffer, &eam, sizeof(eam), SEC_EAMT);
		if (error)
			goto end;
	}

	error = nlbuffer_flush(buffer);
	/* Fall through. */

end:
	nlbuffer_destroy(buffer);
	return error;
}
Esempio n. 25
0
static void runSplit(LADSPA_Handle instance, unsigned long sample_count) {
	Split *plugin_data = (Split *)instance;

	/* Input (array of floats of length sample_count) */
	const LADSPA_Data * const input = plugin_data->input;

	/* Output 1 (array of floats of length sample_count) */
	LADSPA_Data * const out2 = plugin_data->out2;

	/* Output 2 (array of floats of length sample_count) */
	LADSPA_Data * const out1 = plugin_data->out1;

#line 16 "split_1406.xml"
	unsigned long pos;

	for (pos = 0; pos < sample_count; pos++) {
	        const LADSPA_Data in = input[pos];

	        buffer_write(out1[pos], in);
	        buffer_write(out2[pos], in);
	}
}
Esempio n. 26
0
/** Interrupt handler routine.
 *
 * Write new data to the corresponding buffer.
 *
 * @param dev  Device that caued the interrupt.
 * @param iid  Call id.
 * @param call pointerr to call data.
 *
 */
static void i8042_irq_handler(ddf_dev_t *dev, ipc_callid_t iid,
                              ipc_call_t *call)
{
    i8042_t *controller = dev_i8042(dev);

    const uint8_t status = IPC_GET_ARG1(*call);
    const uint8_t data = IPC_GET_ARG2(*call);

    buffer_t *buffer = (status & i8042_AUX_DATA) ?
                       &controller->aux_buffer : &controller->kbd_buffer;

    buffer_write(buffer, data);
}
Esempio n. 27
0
void CLIENT_DESC::DBPacket(BYTE bHeader, DWORD dwHandle, const void * c_pvData, DWORD dwSize)
{
    if (m_sock == INVALID_SOCKET) {
        sys_log(0, "CLIENT_DESC [%s] trying DBPacket() while not connected",
                GetKnownClientDescName(this));
        return;
    }
    sys_log(1, "DB_PACKET: header %d handle %d size %d buffer_size %d", bHeader, dwHandle, dwSize, buffer_size(m_lpOutputBuffer));
    DBPacketHeader(bHeader, dwHandle, dwSize);

    if (c_pvData)
        buffer_write(m_lpOutputBuffer, c_pvData, dwSize);
}
Esempio n. 28
0
static int luastream_clone (lua_State *L)
{
	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LUA_STREAM);
	lua_Stream *other = (lua_Stream *)lua_newuserdata(L, sizeof(lua_Stream));
	luaL_check(self->buf, "%s (released) #1", LUA_STREAM);
	other->buf = buffer_new(buffer_tell(&self->buf));
	other->pos = self->pos;
	other->ref = LUA_REFNIL;
	buffer_write(&other->buf, buffer_ptr(&self->buf), buffer_tell(&self->buf));
	luaL_getmetatable(L, LUA_STREAM);
	lua_setmetatable(L, -2);
	return 1;
}
Esempio n. 29
0
static ssize_t data_buffer_t_write (data_t *data, fastcall_write *fargs){ // {{{
	ssize_t                ret;
	
	if(fargs->buffer == NULL)
		return -EINVAL;
	
	if( (ret = buffer_write( (buffer_t *)data->ptr, fargs->offset, fargs->buffer, fargs->buffer_size)) == -1){
		fargs->buffer_size = 0;
		return -1; // EOF
	}
	fargs->buffer_size = ret;
	return 0;
} // }}}
Esempio n. 30
0
static void runMatrixStMS(LADSPA_Handle instance, unsigned long sample_count) {
	MatrixStMS *plugin_data = (MatrixStMS *)instance;

	/* Left (array of floats of length sample_count) */
	const LADSPA_Data * const left = plugin_data->left;

	/* Right (array of floats of length sample_count) */
	const LADSPA_Data * const right = plugin_data->right;

	/* Mid (array of floats of length sample_count) */
	LADSPA_Data * const mid = plugin_data->mid;

	/* Side (array of floats of length sample_count) */
	LADSPA_Data * const side = plugin_data->side;

	unsigned long pos;

	for (pos = 0; pos < sample_count; pos++) {
	  buffer_write(mid[pos], (left[pos] + right[pos]) * 0.5);
	  buffer_write(side[pos], (left[pos] - right[pos]) * 0.5);
	}
}