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

📄 korg1212.c

📁 h内核
💻 C
📖 第 1 页 / 共 5 页
字号:
{        korg1212_t *korg1212 = (korg1212_t *) pcm->private_data;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n", stateName[korg1212->cardState]);#endif        korg1212->pcm = NULL;}static int snd_korg1212_playback_open(snd_pcm_substream_t *substream){        unsigned long flags;        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);        snd_pcm_runtime_t *runtime = substream->runtime;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n", stateName[korg1212->cardState]);#endif        snd_pcm_set_sync(substream);    // ???	snd_korg1212_OpenCard(korg1212);        runtime->hw = snd_korg1212_playback_info;	snd_pcm_set_runtime_buffer(substream, &korg1212->dma_play);        spin_lock_irqsave(&korg1212->lock, flags);        korg1212->playback_substream = substream;	korg1212->playback_pid = current->pid;        korg1212->periodsize = K1212_PERIODS;	korg1212->channels = K1212_CHANNELS;        spin_unlock_irqrestore(&korg1212->lock, flags);        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames, kPlayBufferFrames);        return 0;}static int snd_korg1212_capture_open(snd_pcm_substream_t *substream){        unsigned long flags;        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);        snd_pcm_runtime_t *runtime = substream->runtime;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n", stateName[korg1212->cardState]);#endif        snd_pcm_set_sync(substream);    // ???	snd_korg1212_OpenCard(korg1212);        runtime->hw = snd_korg1212_capture_info;	snd_pcm_set_runtime_buffer(substream, &korg1212->dma_rec);        spin_lock_irqsave(&korg1212->lock, flags);        korg1212->capture_substream = substream;	korg1212->capture_pid = current->pid;        korg1212->periodsize = K1212_PERIODS;	korg1212->channels = K1212_CHANNELS;        spin_unlock_irqrestore(&korg1212->lock, flags);        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames, kPlayBufferFrames);        return 0;}static int snd_korg1212_playback_close(snd_pcm_substream_t *substream){        unsigned long flags;        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", stateName[korg1212->cardState]);#endif	snd_korg1212_silence(korg1212, 0, K1212_MAX_SAMPLES, 0, korg1212->channels * 2);        spin_lock_irqsave(&korg1212->lock, flags);	korg1212->playback_pid = -1;        korg1212->playback_substream = NULL;        korg1212->periodsize = 0;        spin_unlock_irqrestore(&korg1212->lock, flags);	snd_korg1212_CloseCard(korg1212);        return 0;}static int snd_korg1212_capture_close(snd_pcm_substream_t *substream){        unsigned long flags;        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", stateName[korg1212->cardState]);#endif        spin_lock_irqsave(&korg1212->lock, flags);	korg1212->capture_pid = -1;        korg1212->capture_substream = NULL;        korg1212->periodsize = 0;        spin_unlock_irqrestore(&korg1212->lock, flags);	snd_korg1212_CloseCard(korg1212);        return 0;}static int snd_korg1212_ioctl(snd_pcm_substream_t *substream,			     unsigned int cmd, void *arg){#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd);#endif	if (cmd == SNDRV_PCM_IOCTL1_CHANNEL_INFO ) {		snd_pcm_channel_info_t *info = arg;        	info->offset = 0;        	info->first = info->channel * 16;        	info->step = 256;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info->channel, info->offset, info->first, info->step);#endif		return 0;	}        return snd_pcm_lib_ioctl(substream, cmd, arg);}static int snd_korg1212_hw_params(snd_pcm_substream_t *substream,                             snd_pcm_hw_params_t *params){        unsigned long flags;        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);        int err;	pid_t this_pid;	pid_t other_pid;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n", stateName[korg1212->cardState]);#endif        spin_lock_irqsave(&korg1212->lock, flags);	if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {		this_pid = korg1212->playback_pid;		other_pid = korg1212->capture_pid;	} else {		this_pid = korg1212->capture_pid;		other_pid = korg1212->playback_pid;	}	if ((other_pid > 0) && (this_pid != other_pid)) {		/* The other stream is open, and not by the same		   task as this one. Make sure that the parameters		   that matter are the same.		 */		if ((int)params_rate(params) != korg1212->clkRate) {			spin_unlock_irqrestore(&korg1212->lock, flags);			_snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);			return -EBUSY;		}        	spin_unlock_irqrestore(&korg1212->lock, flags);	        return 0;	}        if ((err = snd_korg1212_SetRate(korg1212, params_rate(params))) < 0) {                spin_unlock_irqrestore(&korg1212->lock, flags);                return err;        }	korg1212->channels = params_channels(params);        korg1212->periodsize = K1212_PERIOD_BYTES;        spin_unlock_irqrestore(&korg1212->lock, flags);        return 0;}static int snd_korg1212_prepare(snd_pcm_substream_t *substream){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);	int rc;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", stateName[korg1212->cardState]);#endif	spin_lock_irq(&korg1212->lock);	/* FIXME: we should wait for ack! */	if (korg1212->stop_pending_cnt > 0) {#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]);#endif        	spin_unlock_irq(&korg1212->lock);		return -EAGAIN;		/*		writel(0, &korg1212->sharedBufferPtr->cardCommand);		del_timer(&korg1212->timer);		korg1212->stop_pending_cnt = 0;		*/	}        rc = snd_korg1212_SetupForPlay(korg1212);        korg1212->currentBuffer = 0;        spin_unlock_irq(&korg1212->lock);	return rc ? -EINVAL : 0;}static int snd_korg1212_trigger(snd_pcm_substream_t *substream,                           int cmd){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);	int rc;#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n", stateName[korg1212->cardState], cmd);#endif	spin_lock(&korg1212->lock);        switch (cmd) {                case SNDRV_PCM_TRIGGER_START:/*			if (korg1212->running) {#if K1212_DEBUG_LEVEL > 1				K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger: Already running?\n");#endif				break;			}*/                        korg1212->running++;                        rc = snd_korg1212_TriggerPlay(korg1212);                        break;                case SNDRV_PCM_TRIGGER_STOP:/*			if (!korg1212->running) {#if K1212_DEBUG_LEVEL > 1				K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n");#endif				break;			}*/                        korg1212->running--;                        rc = snd_korg1212_StopPlay(korg1212);                        break;                default:			rc = 1;			break;        }	spin_unlock(&korg1212->lock);        return rc ? -EINVAL : 0;}static snd_pcm_uframes_t snd_korg1212_playback_pointer(snd_pcm_substream_t *substream){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);        snd_pcm_uframes_t pos;	pos = korg1212->currentBuffer * kPlayBufferFrames;#if K1212_DEBUG_LEVEL > 2	K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n", 			stateName[korg1212->cardState], pos);#endif        return pos;}static snd_pcm_uframes_t snd_korg1212_capture_pointer(snd_pcm_substream_t *substream){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);        snd_pcm_uframes_t pos;	pos = korg1212->currentBuffer * kPlayBufferFrames;#if K1212_DEBUG_LEVEL > 2	K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n",			stateName[korg1212->cardState], pos);#endif        return pos;}static int snd_korg1212_playback_copy(snd_pcm_substream_t *substream,                        int channel, /* not used (interleaved data) */                        snd_pcm_uframes_t pos,                        void __user *src,                        snd_pcm_uframes_t count){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);#if K1212_DEBUG_LEVEL > 2		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count);#endif 	return snd_korg1212_copy_from(korg1212, src, pos, count, 0, korg1212->channels * 2);}static int snd_korg1212_playback_silence(snd_pcm_substream_t *substream,                           int channel, /* not used (interleaved data) */                           snd_pcm_uframes_t pos,                           snd_pcm_uframes_t count){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);#if K1212_DEBUG_LEVEL > 0		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", stateName[korg1212->cardState]);#endif	return snd_korg1212_silence(korg1212, pos, count, 0, korg1212->channels * 2);}static int snd_korg1212_capture_copy(snd_pcm_substream_t *substream,                        int channel, /* not used (interleaved data) */                        snd_pcm_uframes_t pos,                        void __user *dst,                        snd_pcm_uframes_t count){        korg1212_t *korg1212 = snd_pcm_substream_chip(substream);#if K1212_DEBUG_LEVEL > 2		K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count);#endif	return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2);}static snd_pcm_ops_t snd_korg1212_playback_ops = {        .open =		snd_korg1212_playback_open,        .close =	snd_korg1212_playback_close,        .ioctl =	sn

⌨️ 快捷键说明

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