⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardwo.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (woinst->state & WAVE_STATE_STARTED)		return -1;	query_format(wave_dev, format);	if (woinst->format.samplingrate != format->samplingrate ||	    woinst->format.channels != format->channels ||	    woinst->format.bitsperchannel != format->bitsperchannel) {		woinst->format = *format;		if (woinst->state == WAVE_STATE_CLOSED)			return 0;		emu10k1_timer_uninstall(card, &woinst->timer);		for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {			emu10k1_voice_free(&woinst->voice[voicenum]);			if (get_voice(card, woinst, voicenum) < 0) {				ERROR();				emu10k1_waveout_close(wave_dev);				return -1;			}		}		delay = (48000 * woinst->buffer.fragment_size) /			 (woinst->format.samplingrate * woinst->format.bytespervoicesample);		emu10k1_timer_install(card, &woinst->timer, delay);	}	return 0;}void emu10k1_waveout_stop(struct emu10k1_wavedevice *wave_dev){	struct emu10k1_card *card = wave_dev->card;	struct woinst *woinst = wave_dev->woinst;	DPF(2, "emu10k1_waveout_stop()\n");	if (!(woinst->state & WAVE_STATE_STARTED))		return;	emu10k1_timer_disable(card, &woinst->timer);	/* Stop actual voices */	emu10k1_voices_stop(woinst->voice, woinst->num_voices);	emu10k1_waveout_update(woinst);	woinst->state &= ~WAVE_STATE_STARTED;}/** * emu10k1_waveout_getxfersize - * * gives the total free bytes on the voice buffer, including silence bytes * (basically: total_free_bytes = free_bytes + silence_bytes). * */void emu10k1_waveout_getxfersize(struct woinst *woinst, u32 *total_free_bytes){	struct waveout_buffer *buffer = &woinst->buffer;	int pending_bytes;	if (woinst->mmapped) {		*total_free_bytes = buffer->free_bytes;		return;	}	pending_bytes = buffer->size - buffer->free_bytes;	buffer->fill_silence = (pending_bytes < (signed) buffer->fragment_size * 2) ? 1 : 0;	if (pending_bytes > (signed) buffer->silence_bytes) {		*total_free_bytes = (buffer->free_bytes + buffer->silence_bytes);	} else {		*total_free_bytes = buffer->size;		buffer->silence_bytes = pending_bytes;		if (pending_bytes < 0) {			buffer->silence_pos = buffer->hw_pos;			buffer->silence_bytes = 0;			buffer->free_bytes = buffer->size;			DPF(1, "buffer underrun\n");		}	}}/** * copy_block - * * copies a block of pcm data to a voice buffer. * Notice that the voice buffer is actually a set of disjointed memory pages. * */static void copy_block(void **dst, u32 str, u8 __user *src, u32 len){	unsigned int pg;	unsigned int pgoff;	unsigned int k;	pg = str / PAGE_SIZE;	pgoff = str % PAGE_SIZE;	if (len > PAGE_SIZE - pgoff) {		k = PAGE_SIZE - pgoff;		if (__copy_from_user((u8 *)dst[pg] + pgoff, src, k))			return;		len -= k;		while (len > PAGE_SIZE) {			if (__copy_from_user(dst[++pg], src + k, PAGE_SIZE))				return;			k += PAGE_SIZE;			len -= PAGE_SIZE;		}		if (__copy_from_user(dst[++pg], src + k, len))			return;	} else		__copy_from_user((u8 *)dst[pg] + pgoff, src, len);}/** * copy_ilv_block - * * copies a block of pcm data containing n interleaved channels to n mono voice buffers. * Notice that the voice buffer is actually a set of disjointed memory pages. * */static void copy_ilv_block(struct woinst *woinst, u32 str, u8 __user *src, u32 len) {        unsigned int pg;	unsigned int pgoff;	unsigned int voice_num;	struct emu_voice *voice = woinst->voice;	pg = str / PAGE_SIZE;	pgoff = str % PAGE_SIZE;	while (len) { 		for (voice_num = 0; voice_num < woinst->num_voices; voice_num++) {			if (__copy_from_user((u8 *)(voice[voice_num].mem.addr[pg]) + pgoff, src, woinst->format.bytespervoicesample))				return;			src += woinst->format.bytespervoicesample;		}		len -= woinst->format.bytespervoicesample;		pgoff += woinst->format.bytespervoicesample;		if (pgoff >= PAGE_SIZE) {			pgoff = 0;			pg++;		}	}}/** * fill_block - * * fills a set voice buffers with a block of a given sample. * */static void fill_block(struct woinst *woinst, u32 str, u8 data, u32 len){	unsigned int pg;	unsigned int pgoff;	unsigned int voice_num;        struct emu_voice *voice = woinst->voice;	unsigned int  k;	pg = str / PAGE_SIZE;	pgoff = str % PAGE_SIZE;	if (len > PAGE_SIZE - pgoff) {		k = PAGE_SIZE - pgoff;		for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)			memset((u8 *)voice[voice_num].mem.addr[pg] + pgoff, data, k);		len -= k;		while (len > PAGE_SIZE) {			pg++;			for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)				memset(voice[voice_num].mem.addr[pg], data, PAGE_SIZE);			len -= PAGE_SIZE;		}		pg++;		for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)			memset(voice[voice_num].mem.addr[pg], data, len);	} else {		for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)			memset((u8 *)voice[voice_num].mem.addr[pg] + pgoff, data, len);	}}/** * emu10k1_waveout_xferdata - * * copies pcm data to the voice buffer. Silence samples * previously added to the buffer are overwritten. * */void emu10k1_waveout_xferdata(struct woinst *woinst, u8 __user *data, u32 *size){	struct waveout_buffer *buffer = &woinst->buffer;	struct voice_mem *mem = &woinst->voice[0].mem;	u32 sizetocopy, sizetocopy_now, start;	unsigned long flags;	sizetocopy = min_t(u32, buffer->size, *size);	*size = sizetocopy;	if (!sizetocopy)		return;		spin_lock_irqsave(&woinst->lock, flags);	start = (buffer->size + buffer->silence_pos - buffer->silence_bytes) % buffer->size;	if (sizetocopy > buffer->silence_bytes) {		buffer->silence_pos += sizetocopy - buffer->silence_bytes;		buffer->free_bytes -= sizetocopy - buffer->silence_bytes;		buffer->silence_bytes = 0;	} else		buffer->silence_bytes -= sizetocopy;	spin_unlock_irqrestore(&woinst->lock, flags);	sizetocopy_now = buffer->size - start;	if (sizetocopy > sizetocopy_now) {		sizetocopy -= sizetocopy_now;		if (woinst->num_voices > 1) {			copy_ilv_block(woinst, start, data, sizetocopy_now);			copy_ilv_block(woinst, 0, data + sizetocopy_now * woinst->num_voices, sizetocopy);		} else {			copy_block(mem->addr, start, data, sizetocopy_now);			copy_block(mem->addr, 0, data + sizetocopy_now, sizetocopy);		}	} else {		if (woinst->num_voices > 1)			copy_ilv_block(woinst, start, data, sizetocopy);		else			copy_block(mem->addr, start, data, sizetocopy);	}}/** * emu10k1_waveout_fillsilence - * * adds samples of silence to the voice buffer so that we * don't loop over stale pcm data. * */void emu10k1_waveout_fillsilence(struct woinst *woinst){	struct waveout_buffer *buffer = &woinst->buffer;	u32 sizetocopy, sizetocopy_now, start;	u8 filldata;	unsigned long flags;	sizetocopy = buffer->fragment_size;	if (woinst->format.bitsperchannel == 16)		filldata = 0x00;	else		filldata = 0x80;	spin_lock_irqsave(&woinst->lock, flags);	buffer->silence_bytes += sizetocopy;	buffer->free_bytes -= sizetocopy;	buffer->silence_pos %= buffer->size;	start = buffer->silence_pos;	buffer->silence_pos += sizetocopy;	spin_unlock_irqrestore(&woinst->lock, flags);	sizetocopy_now = buffer->size - start;	if (sizetocopy > sizetocopy_now) {		sizetocopy -= sizetocopy_now;		fill_block(woinst, start, filldata, sizetocopy_now);		fill_block(woinst, 0, filldata, sizetocopy);	} else {		fill_block(woinst, start, filldata, sizetocopy);	}}/** * emu10k1_waveout_update - * * updates the position of the voice buffer hardware pointer (hw_pos) * and the number of free bytes on the buffer (free_bytes). * The free bytes _don't_ include silence bytes that may have been * added to the buffer. * */void emu10k1_waveout_update(struct woinst *woinst){	u32 hw_pos;	u32 diff;	/* There is no actual start yet */	if (!(woinst->state & WAVE_STATE_STARTED)) {		hw_pos = woinst->buffer.hw_pos;	} else {		/* hw_pos in sample units */		hw_pos = sblive_readptr(woinst->voice[0].card, CCCA_CURRADDR, woinst->voice[0].num);		if(hw_pos < woinst->voice[0].start)			hw_pos += woinst->buffer.size / woinst->format.bytespervoicesample - woinst->voice[0].start;		else			hw_pos -= woinst->voice[0].start;		hw_pos *= woinst->format.bytespervoicesample;	}	diff = (woinst->buffer.size + hw_pos - woinst->buffer.hw_pos) % woinst->buffer.size;	woinst->total_played += diff;	woinst->buffer.free_bytes += diff;	woinst->buffer.hw_pos = hw_pos;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -