Example #1
0
void
TimeNode::run(ProcessContext& context)
{
	BufferRef          buf = _notify_port->buffer(0);
	LV2_Atom_Sequence* seq = buf->get<LV2_Atom_Sequence>();

	// Initialise output to the empty sequence
	seq->atom.type = _notify_port->bufs().uris().atom_Sequence;
	seq->atom.size = sizeof(LV2_Atom_Sequence_Body);
	seq->body.unit = 0;
	seq->body.pad  = 0;

	// Ask the driver to append any time events for this cycle
	context.engine().driver()->append_time_events(
		context, *_notify_port->buffer(0));
}
Example #2
0
void
DelayNode::run(ProcessContext& context)
{
	Buffer* const delay_buf = _delay_port->buffer(0).get();
	Buffer* const in_buf    = _in_port->buffer(0).get();
	Buffer* const out_buf   = _out_port->buffer(0).get();

	DelayNode* plugin_data = this;

	const float* const in            = in_buf->samples();
	float* const       out           = out_buf->samples();
	const float        delay_time    = delay_buf->samples()[0];
	const uint32_t     buffer_mask   = plugin_data->_buffer_mask;
	const SampleRate   sample_rate   = context.engine().driver()->sample_rate();
	float              delay_samples = plugin_data->_delay_samples;
	int64_t            write_phase   = plugin_data->_write_phase;
	const uint32_t     sample_count  = context.nframes();

	if (write_phase == 0) {
		_last_delay_time = delay_time;
		_delay_samples   = delay_samples = CALC_DELAY(delay_time);
	}

	if (delay_time == _last_delay_time) {
		const int64_t idelay_samples = (int64_t)delay_samples;
		const float   frac           = delay_samples - idelay_samples;

		for (uint32_t i = 0; i < sample_count; i++) {
			int64_t read_phase = write_phase - (int64_t)delay_samples;
			const float read = cube_interp(frac,
			                               buffer_at(read_phase - 1),
			                               buffer_at(read_phase),
			                               buffer_at(read_phase + 1),
			                               buffer_at(read_phase + 2));
			buffer_at(write_phase++) = in[i];
			out[i] = read;
		}
	} else {
		const float next_delay_samples  = CALC_DELAY(delay_time);
		const float delay_samples_slope = (next_delay_samples - delay_samples) / sample_count;

		for (uint32_t i = 0; i < sample_count; i++) {
			delay_samples += delay_samples_slope;
			write_phase++;
			const int64_t read_phase     = write_phase - (int64_t)delay_samples;
			const int64_t idelay_samples = (int64_t)delay_samples;
			const float   frac           = delay_samples - idelay_samples;
			const float   read           = cube_interp(frac,
			                                           buffer_at(read_phase - 1),
			                                           buffer_at(read_phase),
			                                           buffer_at(read_phase + 1),
			                                           buffer_at(read_phase + 2));
			buffer_at(write_phase) = in[i];
			out[i] = read;
		}

		_last_delay_time = delay_time;
		_delay_samples   = delay_samples;
	}

	_write_phase = write_phase;
}