Пример #1
0
/** Empty (ie zero) the buffer.
 */
void
AudioBuffer::clear()
{
	assert(nframes() != 0);
	set_block(0, 0, nframes() - 1);
	_state = OK;
}
Пример #2
0
/** Copy a block of @a src into buffer.
 *
 * @a start_sample and @a end_sample define the inclusive range to be set.
 * This function only copies the same range in one buffer to another.
 */
void
AudioBuffer::copy(const Sample* src, size_t start_sample, size_t end_sample)
{
	assert(end_sample >= start_sample);
	assert(nframes() != 0);

	Sample* const buf = data();
	assert(buf);

	const size_t copy_end = std::min(end_sample, (size_t)nframes() - 1);
	for (size_t i = start_sample; i <= copy_end; ++i)
		buf[i] = src[i];
}
Пример #3
0
void
AudioBuffer::copy(Context& context, const Buffer* src)
{
	const AudioBuffer* src_abuf = dynamic_cast<const AudioBuffer*>(src);
	if (!src_abuf) {
		clear();
		return;
	}

	// Control => Control
	if (src_abuf->is_control() == is_control()) {
		ObjectBuffer::copy(context, src);

	// Audio => Audio
	} else if (!src_abuf->is_control() && !is_control()) {
		copy(src_abuf->data(),
				context.offset(), context.offset() + context.nframes() - 1);

	// Audio => Control
	} else if (!src_abuf->is_control() && is_control()) {
		data()[0] = src_abuf->data()[context.offset()];

	// Control => Audio
	} else if (src_abuf->is_control() && !is_control()) {
		data()[context.offset()] = src_abuf->data()[0];

	// Control => Audio or Audio => Control
	} else {
		set_block(src_abuf->data()[0], 0, nframes());
	}
}
Пример #4
0
 void MultiTrajectory::initWithList(const std::vector<std::string>& filenames, const AtomicGroup& model) {
   for (uint i=0; i<filenames.size(); ++i) {
     pTraj traj = createTrajectory(filenames[i], model);
     _trajectories.push_back(traj);
     _nframes += nframes(i);
   }
 }
Пример #5
0
void
AudioBuffer::prepare_read(Context& context)
{
	assert(nframes() != 0);
	switch (_state) {
	case HALF_SET_CYCLE_1:
		if (context.start() > _set_time)
			_state = HALF_SET_CYCLE_2;
		break;
	case HALF_SET_CYCLE_2:
		set_block(_set_value, 0, nframes() - 1);
		_state = OK;
		break;
	default:
		break;
	}
}
Пример #6
0
 MultiTrajectory::Location MultiTrajectory::frameIndexToLocation(const uint i) {
   uint k, j;
   for (j=k=0; k<_trajectories.size(); ++k) {
     uint n = nframes(k);
     if (j + n > i)
       break;
     j += n;
   }
   Location loc(k, (_skip + (i-j)*_stride));
   return loc;
 }
Пример #7
0
/** Set a block of buffer to @a val.
 *
 * @a start_sample and @a end_sample define the inclusive range to be set.
 */
void
AudioBuffer::set_block(Sample val, size_t start_offset, size_t end_offset)
{
	assert(end_offset >= start_offset);
	assert(end_offset < nframes());

	Sample* const buf = data();
	assert(buf);

	for (size_t i = start_offset; i <= end_offset; ++i)
		buf[i] = val;
}
Пример #8
0
/** Set value of buffer to @a val after @a start_sample.
 *
 * The Buffer will handle setting the intial portion of the buffer to the
 * value on the next cycle automatically (if @a start_sample is > 0), as
 * long as pre_process() is called every cycle.
 */
void
AudioBuffer::set_value(Sample val, FrameTime cycle_start, FrameTime time)
{
	if (is_control())
		time = cycle_start;

	const FrameTime offset = time - cycle_start;
	assert(nframes() != 0);
	assert(offset <= nframes());

	if (offset < nframes()) {
		set_block(val, offset, nframes() - 1);

		if (offset == 0)
			_state = OK;
		else
			_state = HALF_SET_CYCLE_1;
	} // else trigger at very end of block

	_set_time = time;
	_set_value = val;
}