From: Takashi Iwai Subject: emu10k1 pitch control patch Date: Thu, 08 Aug 2002 12:31:51 +0200 Sender: alsa-devel-admin@lists.sourceforge.net Message-ID: Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: multipart/mixed; boundary="Multipart_Thu_Aug__8_12:31:51_2002-1" Return-path: Errors-To: alsa-devel-admin@lists.sourceforge.net List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: To: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Thu_Aug__8_12:31:51_2002-1 Content-Type: text/plain; charset=US-ASCII Hi, the attached is a patch to add a pitch control for each pcm playback stream. when you play a pcm, a control "Emu10k1 PCM Pitch" on mixer. this allows to change the current pitch (sample rate) on the fly. the value is in Hz from 4000 to 96000. (i'm not sure whether sb live accepts the rate higher than 48000, but on audigy it works.) unfortuantely alsamixer can adjust the values only roughly in 10%, but theoretically you can adjust the pitch in 1 Hz resolution. anyway, this is somewhat "just for fun". if you feel it's useful, let me know. i'll consider to put it to cvs. i think, however, that a generic api which bound to pcm such like in ASIO or EASI would be more useful. yep, time to discuss about it again... btw, a similar thing can be implemented for other cards, such like trident. ciao, Takashi --Multipart_Thu_Aug__8_12:31:51_2002-1 Content-Type: application/octet-stream Content-Disposition: attachment; filename="emu10k1-pitch.dif" Content-Transfer-Encoding: 7bit Index: alsa-kernel/include/emu10k1.h =================================================================== RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/include/emu10k1.h,v retrieving revision 1.15 diff -u -r1.15 emu10k1.h --- alsa-kernel/include/emu10k1.h 19 Jul 2002 17:02:37 -0000 1.15 +++ alsa-kernel/include/emu10k1.h 8 Aug 2002 09:44:40 -0000 @@ -814,9 +814,11 @@ unsigned char send_routing[3][8]; unsigned char send_volume[3][8]; unsigned short attn[3]; + int rate; snd_kcontrol_t *ctl_send_routing; snd_kcontrol_t *ctl_send_volume; snd_kcontrol_t *ctl_attn; + snd_kcontrol_t *ctl_pitch; emu10k1_pcm_t *epcm; } emu10k1_pcm_mixer_t; Index: alsa-kernel/pci/emu10k1/emumixer.c =================================================================== RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/pci/emu10k1/emumixer.c,v retrieving revision 1.10 diff -u -r1.10 emumixer.c --- alsa-kernel/pci/emu10k1/emumixer.c 18 Jun 2002 15:28:38 -0000 1.10 +++ alsa-kernel/pci/emu10k1/emumixer.c 8 Aug 2002 10:05:25 -0000 @@ -340,6 +340,78 @@ put: snd_emu10k1_attn_put }; +static int snd_emu10k1_pitch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = 4000; + uinfo->value.integer.max = 96000; + return 0; +} + +static int snd_emu10k1_pitch_get(snd_kcontrol_t * kcontrol, + snd_ctl_elem_value_t * ucontrol) +{ + emu10k1_pcm_mixer_t *mix = (emu10k1_pcm_mixer_t *)kcontrol->private_value; + emu10k1_t *emu = snd_kcontrol_chip(kcontrol); + unsigned long flags; + + spin_lock_irqsave(&emu->reg_lock, flags); + ucontrol->value.integer.value[0] = mix->rate; + spin_unlock_irqrestore(&emu->reg_lock, flags); + return 0; +} + +static unsigned int emu10k1_calc_pitch_target(unsigned int rate) +{ + unsigned int pitch_target; + + pitch_target = (rate << 8) / 375; + pitch_target = (pitch_target >> 1) + (pitch_target & 1); + return pitch_target; +} + +static int snd_emu10k1_pitch_put(snd_kcontrol_t * kcontrol, + snd_ctl_elem_value_t * ucontrol) +{ + unsigned long flags; + emu10k1_pcm_mixer_t *mix = (emu10k1_pcm_mixer_t *)kcontrol->private_value; + emu10k1_t *emu = snd_kcontrol_chip(kcontrol); + int change = 0, val; + unsigned int pitch_target; + + val = ucontrol->value.integer.value[0]; + if (val < 4000 || val > 96000) + return -EINVAL; + spin_lock_irqsave(&emu->reg_lock, flags); + if (mix->rate != val) { + mix->rate = val; + change = 1; + } + if (change && mix->epcm) { + mix->epcm->substream->runtime->rate = mix->rate; + pitch_target = emu10k1_calc_pitch_target(val); + if (mix->epcm->voices[0]) + snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, mix->epcm->voices[0]->number, pitch_target); + if (mix->epcm->voices[1]) + snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, mix->epcm->voices[1]->number, pitch_target); + if (mix->epcm->extra) + snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, mix->epcm->extra->number, pitch_target); + } + spin_unlock_irqrestore(&emu->reg_lock, flags); + return change; +} + +static snd_kcontrol_new_t snd_emu10k1_pitch_control = +{ + access: SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, + iface: SNDRV_CTL_ELEM_IFACE_MIXER, + name: "EMU10K1 PCM Pitch", + info: snd_emu10k1_pitch_info, + get: snd_emu10k1_pitch_get, + put: snd_emu10k1_pitch_put +}; + static int snd_emu10k1_shared_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; @@ -472,6 +544,14 @@ if ((err = snd_ctl_add(card, kctl))) return err; mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff; + + if ((kctl = mix->ctl_pitch = snd_ctl_new1(&snd_emu10k1_pitch_control, emu)) == NULL) + return -ENOMEM; + kctl->private_value = (long)mix; + kctl->id.index = pcm; + if ((err = snd_ctl_add(card, kctl))) + return err; + mix->rate = 44100; } for (idx = 0; idx < 3; idx++) { Index: alsa-kernel/pci/emu10k1/emupcm.c =================================================================== RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/pci/emu10k1/emupcm.c,v retrieving revision 1.11 diff -u -r1.11 emupcm.c --- alsa-kernel/pci/emu10k1/emupcm.c 30 Jul 2002 13:06:27 -0000 1.11 +++ alsa-kernel/pci/emu10k1/emupcm.c 8 Aug 2002 10:04:25 -0000 @@ -411,6 +411,7 @@ snd_pcm_runtime_t *runtime = substream->runtime; emu10k1_pcm_t *epcm = snd_magic_cast(emu10k1_pcm_t, runtime->private_data, return -ENXIO); unsigned int start_addr, end_addr; + emu10k1_pcm_mixer_t *mix; start_addr = epcm->start_addr; end_addr = snd_pcm_lib_period_bytes(substream); @@ -425,6 +426,8 @@ if (epcm->voices[1]) snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1], start_addr, end_addr); + mix = &emu->pcm_mixer[substream->number]; + mix->rate = runtime->rate; return 0; } @@ -752,6 +755,7 @@ snd_emu10k1_pcm_mixer_notify1(card, mix->ctl_send_routing, activate); snd_emu10k1_pcm_mixer_notify1(card, mix->ctl_send_volume, activate); snd_emu10k1_pcm_mixer_notify1(card, mix->ctl_attn, activate); + snd_emu10k1_pcm_mixer_notify1(card, mix->ctl_pitch, activate); } static void snd_emu10k1_pcm_free_substream(snd_pcm_runtime_t *runtime) --Multipart_Thu_Aug__8_12:31:51_2002-1-- ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf