EvaluateRactangleCompact EvaluateRactangle::create_compact(double ratio)
{
	assert(ratio > 0);
	assert(_correction == 1);

	auto scaled = copy_scaled(ratio);
	return EvaluateRactangleCompact(scaled._x1, scaled._y1, scaled._x2, scaled._y2, scaled._corrected_weight);
}
Example #2
0
/* Renders count frames from shm into dst.  Updates count if anything is
 * written. If it's muted and the only stream zero memory. */
size_t cras_mix_add_stream(struct cras_audio_shm *shm,
			   size_t num_channels,
			   uint8_t *dst,
			   size_t *count,
			   size_t *index)
{
	int16_t *src;
	int16_t *target = (int16_t *)dst;
	size_t fr_written;
	int fr_in_buf;
	size_t num_samples;
	size_t frames = 0;
	float mix_vol;

	fr_in_buf = cras_shm_get_frames(shm);
	if (fr_in_buf <= 0)
		return 0;
	if (fr_in_buf < *count)
		*count = fr_in_buf;

	/* Stream volume scaler. */
	mix_vol = cras_shm_get_volume_scaler(shm);

	if (cras_shm_get_mute(shm) ||
	    mix_vol < MIN_VOLUME_TO_SCALE) {
		/* Muted, if first then zero fill, otherwise, nop. */
		if (*index == 0)
			memset(dst, 0, *count * num_channels * sizeof(*src));
	} else {
		fr_written = 0;
		while (fr_written < *count) {
			src = cras_shm_get_readable_frames(shm, fr_written,
					&frames);
			if (frames > *count - fr_written)
				frames = *count - fr_written;
			if (frames == 0)
				break;
			num_samples = frames * num_channels;
			if (*index == 0)
				copy_scaled(target, src, num_samples, mix_vol);
			else
				scale_add_clip(target, src,
					       num_samples,
					       mix_vol);
			fr_written += frames;
			target += num_samples;
		}
		*count = fr_written;
	}

	*index = *index + 1;
	return *count;
}