📄 korg1212.c
字号:
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", stateName[korg1212->cardState]); 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(struct snd_pcm_substream *substream){ unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", stateName[korg1212->cardState]); 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(struct snd_pcm_substream *substream, unsigned int cmd, void *arg){ K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd); if (cmd == SNDRV_PCM_IOCTL1_CHANNEL_INFO ) { struct snd_pcm_channel_info *info = arg; info->offset = 0; info->first = info->channel * 16; info->step = 256; K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info->channel, info->offset, info->first, info->step); return 0; } return snd_pcm_lib_ioctl(substream, cmd, arg);}static int snd_korg1212_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params){ unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int err; pid_t this_pid; pid_t other_pid; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n", stateName[korg1212->cardState]); 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(struct snd_pcm_substream *substream){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", stateName[korg1212->cardState]); spin_lock_irq(&korg1212->lock); /* FIXME: we should wait for ack! */ if (korg1212->stop_pending_cnt > 0) { K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]); spin_unlock_irq(&korg1212->lock); return -EAGAIN; /* korg1212->sharedBufferPtr->cardCommand = 0; 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(struct snd_pcm_substream *substream, int cmd){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n", stateName[korg1212->cardState], cmd); spin_lock(&korg1212->lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START:/* if (korg1212->running) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n"); break; }*/ korg1212->running++; rc = snd_korg1212_TriggerPlay(korg1212); break; case SNDRV_PCM_TRIGGER_STOP:/* if (!korg1212->running) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n"); 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(struct snd_pcm_substream *substream){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; pos = korg1212->currentBuffer * kPlayBufferFrames; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n", stateName[korg1212->cardState], pos); return pos;}static snd_pcm_uframes_t snd_korg1212_capture_pointer(struct snd_pcm_substream *substream){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; pos = korg1212->currentBuffer * kPlayBufferFrames; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n", stateName[korg1212->cardState], pos); return pos;}static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count); return snd_korg1212_copy_from(korg1212, src, pos, count, 0, korg1212->channels * 2);}static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ snd_pcm_uframes_t pos, snd_pcm_uframes_t count){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", stateName[korg1212->cardState]); return snd_korg1212_silence(korg1212, pos, count, 0, korg1212->channels * 2);}static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count){ struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count); return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2);}static struct snd_pcm_ops snd_korg1212_playback_ops = { .open = snd_korg1212_playback_open, .close = snd_korg1212_playback_close, .ioctl = snd_korg1212_ioctl, .hw_params = snd_korg1212_hw_params, .prepare = snd_korg1212_prepare, .trigger = snd_korg1212_trigger, .pointer = snd_korg1212_playback_pointer, .copy = snd_korg1212_playback_copy, .silence = snd_korg1212_playback_silence,};static struct snd_pcm_ops snd_korg1212_capture_ops = { .open = snd_korg1212_capture_open, .close = snd_korg1212_capture_close, .ioctl = snd_korg1212_ioctl, .hw_params = snd_korg1212_hw_params, .prepare = snd_korg1212_prepare, .trigger = snd_korg1212_trigger, .pointer = snd_korg1212_capture_pointer, .copy = snd_korg1212_capture_copy,};/* * Control Interface */static int snd_korg1212_control_phase_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; return 0;}static int snd_korg1212_control_phase_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u){ struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i = kcontrol->private_value; spin_lock_irq(&korg1212->lock); u->value.integer.value[0] = korg1212->volumePhase[i]; if (i >= 8) u->value.integer.value[1] = korg1212->volumePhase[i+1]; spin_unlock_irq(&korg1212->lock); return 0;}static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u){ struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; int i, val; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; korg1212->volumePhase[i] = u->value.integer.value[0]; val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value]; if ((u->value.integer.value[0] > 0) != (val < 0)) { val = abs(val) * (korg1212->volumePhase[i] > 0 ? -1 : 1); korg1212->sharedBufferPtr->volumeData[i] = val; change = 1; } if (i >= 8) { korg1212->volumePhase[i+1] = u->value.integer.value[1]; val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value+1]; if ((u->value.integer.value[1] > 0) != (val < 0)) { val = abs(val) * (korg1212->volumePhase[i+1] > 0 ? -1 : 1); korg1212->sharedBufferPtr->volumeData[i+1] = val; change = 1; } } spin_unlock_irq(&korg1212->lock); return change;}static int snd_korg1212_control_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; uinfo->value.integer.min = k1212MinVolume; uinfo->value.integer.max = k1212MaxVolume; return 0;}static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u){ struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; u->value.integer.value[0] = abs(korg1212->sharedBufferPtr->volumeData[i]); if (i >= 8) u->value.integer.value[1] = abs(korg1212->sharedBuffe
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -