Esempio n. 1
0
void CSimulation::next_step()
{
	check_for_start();
	
	//std::cout << "RUNNING WITH BOOST SEED AND RAND SEED 1" << std::endl;
	
	//std::cout << "t: " << t << std::endl;
	
	if (is_paused()) return;
	
	calculateFinishTime();
	
	calculateForces();
		
	t++;
	check_for_end();

}
Esempio n. 2
0
int a2dp_write(a2dpData d, const void* buffer, int count)
{
	struct bluetooth_data* data = (struct bluetooth_data*)d;
	uint8_t* src = (uint8_t *)buffer;
	int codesize;
	int err, ret = 0;
	long frames_left = count;
	int encoded;
	unsigned int written;
	const char *buff;
	int did_configure = 0;
#ifdef ENABLE_TIMING
	uint64_t begin, end;
	DBG("********** a2dp_write **********");
	begin = get_microseconds();
#endif

	err = check_for_start(data);
	if (err < 0)
		return err;

	pthread_mutex_lock(&data->mutex);
	codesize = data->codesize;

	while (frames_left >= codesize) {
		/* Enough data to encode (sbc wants 512 byte blocks) */
		if (data->sbc.priv == NULL) {
			ERR("bad state");
			ret = -EINVAL;
			goto done;
		}
		encoded = sbc_encode(&(data->sbc), src, codesize,
					data->buffer + data->count,
					sizeof(data->buffer) - data->count,
					&written);
		if (encoded <= 0) {
			ERR("Encoding error %d", encoded);
			goto done;
		}
		VDBG("sbc_encode returned %d, codesize: %d, written: %d\n",
			encoded, codesize, written);

		src += encoded;
		data->count += written;
		data->frame_count++;
		data->samples += encoded;
		data->nsamples += encoded/4;

		/* No space left for another frame then send or frame count limit reached */
		if ((data->frame_count == 15) || (data->count + written >= data->link_mtu) ||
				(data->count + written >= BUFFER_SIZE)) {
			VDBG("sending packet %d, count %d, link_mtu %u",
					data->seq_num, data->count,
					data->link_mtu);
			err = avdtp_write(data);
			if (err < 0) {
				pthread_mutex_unlock(&data->mutex);
				return err;
			}
		}

		ret += encoded;
		frames_left -= encoded;
	}

	if (frames_left > 0)
		ERR("%ld bytes left at end of a2dp_write\n", frames_left);

done:
	pthread_mutex_unlock(&data->mutex);
#ifdef ENABLE_TIMING
	end = get_microseconds();
	print_time("a2dp_write total", begin, end);
#endif
	return ret;
}