void dsp_tone_copy()

in mISDN/dsp_tones.c [375:430]


void dsp_tone_copy(struct dsp *dsp, u8 *data, int len)
{
	int index, count, start, num;
	struct pattern *pat;
	struct dsp_tone *tone = &dsp->tone;

	/* if we have no tone, we copy silence */
	if (!tone->tone) {
		memset(data, dsp_silence, len);
		return;
	}

	/* process pattern */
	pat = (struct pattern *)tone->pattern;
	/* points to the current pattern */
	index = tone->index; /* gives current sequence index */
	count = tone->count; /* gives current sample */

	/* copy sample */
	while (len) {
		/* find sample to start with */
		while (42) {
			/* wrap around */
			if (!pat->seq[index]) {
				count = 0;
				index = 0;
			}
			/* check if we are currently playing this tone */
			if (count < pat->seq[index])
				break;
			if (dsp_debug & DEBUG_DSP_TONE)
				printk(KERN_DEBUG "%s: reaching next sequence "
				       "(index=%d)\n", __func__, index);
			count -= pat->seq[index];
			index++;
		}
		/* calculate start and number of samples */
		start = count % (*(pat->siz[index]));
		num = len;
		if (num + count > pat->seq[index])
			num = pat->seq[index] - count;
		if (num + start > (*(pat->siz[index])))
			num = (*(pat->siz[index])) - start;
		/* copy memory */
		memcpy(data, pat->data[index] + start, num);
		/* reduce length */
		data += num;
		count += num;
		len -= num;
	}
	tone->index = index;
	tone->count = count;

	/* return sk_buff */
	return;
}