diff mbox series

[1/2] ALSA: emu10k1: introduce higher-level voice manipulation functions

Message ID 20230523104612.198884-1-oswald.buddenhagen@gmx.de (mailing list archive)
State New, archived
Headers show
Series [1/2] ALSA: emu10k1: introduce higher-level voice manipulation functions | expand

Commit Message

Oswald Buddenhagen May 23, 2023, 10:46 a.m. UTC
This adds snd_emu10k1_pcm_init_{voices,extra_voice}() and
snd_emu10k1_playback_{un,}mute_voices() to slightly abstract by voice
function and potential stereo property.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
---
 sound/pci/emu10k1/emupcm.c | 70 +++++++++++++++++++++++++++++---------
 1 file changed, 53 insertions(+), 17 deletions(-)

Comments

Takashi Iwai May 23, 2023, 12:14 p.m. UTC | #1
On Tue, 23 May 2023 12:46:11 +0200,
Oswald Buddenhagen wrote:
> 
> This adds snd_emu10k1_pcm_init_{voices,extra_voice}() and
> snd_emu10k1_playback_{un,}mute_voices() to slightly abstract by voice
> function and potential stereo property.
> 
> Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>

Applied both patches now.  Thanks.


Takashi
diff mbox series

Patch

diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index 0036593cca7c..65af94d08b47 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -312,6 +312,30 @@  static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
 	spin_unlock_irqrestore(&emu->reg_lock, flags);
 }
 
+static void snd_emu10k1_pcm_init_voices(struct snd_emu10k1 *emu,
+					struct snd_emu10k1_voice *evoice,
+					bool w_16, bool stereo,
+					unsigned int start_addr,
+					unsigned int end_addr,
+					struct snd_emu10k1_pcm_mixer *mix)
+{
+	snd_emu10k1_pcm_init_voice(emu, 1, 0, evoice, w_16, stereo,
+				   start_addr, end_addr, mix);
+	if (stereo)
+		snd_emu10k1_pcm_init_voice(emu, 0, 0, evoice + 1, w_16, true,
+					   start_addr, end_addr, mix);
+}
+
+static void snd_emu10k1_pcm_init_extra_voice(struct snd_emu10k1 *emu,
+					     struct snd_emu10k1_voice *evoice,
+					     bool w_16,
+					     unsigned int start_addr,
+					     unsigned int end_addr)
+{
+	snd_emu10k1_pcm_init_voice(emu, 1, 1, evoice, w_16, false,
+				   start_addr, end_addr, NULL);
+}
+
 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream *substream,
 					  struct snd_pcm_hw_params *hw_params)
 {
@@ -393,18 +417,15 @@  static int snd_emu10k1_playback_prepare(struct snd_pcm_substream *substream)
 
 	start_addr = epcm->start_addr >> w_16;
 	end_addr = start_addr + runtime->period_size;
-	snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra, w_16, false,
-				   start_addr, end_addr, NULL);
+	snd_emu10k1_pcm_init_extra_voice(emu, epcm->extra, w_16,
+					 start_addr, end_addr);
 	start_addr >>= stereo;
 	epcm->ccca_start_addr = start_addr;
 	end_addr = start_addr + runtime->buffer_size;
-	snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0], w_16, stereo,
-				   start_addr, end_addr,
-				   &emu->pcm_mixer[substream->number]);
-	if (stereo)
-		snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[0] + 1, w_16, true,
-					   start_addr, end_addr,
-					   &emu->pcm_mixer[substream->number]);
+	snd_emu10k1_pcm_init_voices(emu, epcm->voices[0], w_16, stereo,
+				    start_addr, end_addr,
+				    &emu->pcm_mixer[substream->number]);
+
 	return 0;
 }
 
@@ -421,8 +442,8 @@  static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)
 
 	channel_size = runtime->buffer_size;
 
-	snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra, true, false,
-				   start_addr, start_addr + (channel_size / 2), NULL);
+	snd_emu10k1_pcm_init_extra_voice(emu, epcm->extra, true,
+					 start_addr, start_addr + (channel_size / 2));
 
 	epcm->ccca_start_addr = start_addr;
 	for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
@@ -598,12 +619,31 @@  static void snd_emu10k1_playback_unmute_voice(struct snd_emu10k1 *emu,
 	snd_emu10k1_playback_commit_volume(emu, evoice, vattn);
 }	
 
+static void snd_emu10k1_playback_unmute_voices(struct snd_emu10k1 *emu,
+					       struct snd_emu10k1_voice *evoice,
+					       bool stereo,
+					       struct snd_emu10k1_pcm_mixer *mix)
+{
+	snd_emu10k1_playback_unmute_voice(emu, evoice, stereo, true, mix);
+	if (stereo)
+		snd_emu10k1_playback_unmute_voice(emu, evoice + 1, true, false, mix);
+}
+
 static void snd_emu10k1_playback_mute_voice(struct snd_emu10k1 *emu,
 					    struct snd_emu10k1_voice *evoice)
 {
 	snd_emu10k1_playback_commit_volume(emu, evoice, 0);
 }
 
+static void snd_emu10k1_playback_mute_voices(struct snd_emu10k1 *emu,
+					     struct snd_emu10k1_voice *evoice,
+					     bool stereo)
+{
+	snd_emu10k1_playback_mute_voice(emu, evoice);
+	if (stereo)
+		snd_emu10k1_playback_mute_voice(emu, evoice + 1);
+}
+
 static void snd_emu10k1_playback_commit_pitch(struct snd_emu10k1 *emu,
 					      u32 voice, u32 pitch_target)
 {
@@ -680,22 +720,18 @@  static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
 	case SNDRV_PCM_TRIGGER_RESUME:
 		mix = &emu->pcm_mixer[substream->number];
-		snd_emu10k1_playback_unmute_voice(emu, epcm->voices[0], stereo, true, mix);
-		if (stereo)
-			snd_emu10k1_playback_unmute_voice(emu, epcm->voices[0] + 1, true, false, mix);
+		snd_emu10k1_playback_unmute_voices(emu, epcm->voices[0], stereo, mix);
 		snd_emu10k1_playback_set_running(emu, epcm);
 		snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0]);
 		snd_emu10k1_playback_trigger_voice(emu, epcm->extra);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 		snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]);
 		snd_emu10k1_playback_stop_voice(emu, epcm->extra);
 		snd_emu10k1_playback_set_stopped(emu, epcm);
-		snd_emu10k1_playback_mute_voice(emu, epcm->voices[0]);
-		if (stereo)
-			snd_emu10k1_playback_mute_voice(emu, epcm->voices[0] + 1);
+		snd_emu10k1_playback_mute_voices(emu, epcm->voices[0], stereo);
 		break;
 	default:
 		result = -EINVAL;