diff mbox series

[4/7] ALSA: emu10k1: make freeing untouched playback voices cheap

Message ID 20230518140947.3725394-5-oswald.buddenhagen@gmx.de
State New
Headers show
Series ALSA: emu10k1: refactoring of the playback voice management | expand

Commit Message

Oswald Buddenhagen May 18, 2023, 2:09 p.m. UTC
This allows us to drop the code that tries to preserve already allocated
voices upon repeated hw_param callback invocations. Getting it right for
multi-channel voices would otherwise get a bit hairy.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
---
 include/sound/emu10k1.h              |  1 +
 sound/pci/emu10k1/emu10k1_callback.c |  1 +
 sound/pci/emu10k1/emupcm.c           | 13 ++-----------
 sound/pci/emu10k1/emuproc.c          |  5 +++--
 sound/pci/emu10k1/voice.c            |  5 +++--
 5 files changed, 10 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h
index 2d247f8f635b..6ec2079534d4 100644
--- a/include/sound/emu10k1.h
+++ b/include/sound/emu10k1.h
@@ -1451,6 +1451,7 @@  struct snd_emu10k1;
 struct snd_emu10k1_voice {
 	unsigned char number;
 	unsigned char use;
+	unsigned char dirty;
 	void (*interrupt)(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *pvoice);
 
 	struct snd_emu10k1_pcm *epcm;
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index 4a8b2df06a28..d70ca1f50705 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -458,6 +458,7 @@  start_voice(struct snd_emux_voice *vp)
 	}
 #endif
 
+	hw->voices[ch].dirty = 1;
 	return 0;
 }
 
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index aa3d6d573f05..c4696c127028 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -80,17 +80,6 @@  static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voic
 {
 	int err, i;
 
-	if (epcm->voices[1] != NULL && voices < 2) {
-		snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
-		epcm->voices[1] = NULL;
-	}
-	for (i = 0; i < voices; i++) {
-		if (epcm->voices[i] == NULL)
-			break;
-	}
-	if (i == voices)
-		return 0; /* already allocated */
-
 	for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) {
 		if (epcm->voices[i]) {
 			snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
@@ -306,6 +295,8 @@  static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
 				      snd_emu10k1_compose_send_routing(send_routing));
 	}
 
+	emu->voices[voice].dirty = 1;
+
 	spin_unlock_irqrestore(&emu->reg_lock, flags);
 }
 
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index c423a56ebf9e..abcec8a01760 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -372,11 +372,12 @@  static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
 	};
 	static_assert(ARRAY_SIZE(types) == EMU10K1_NUM_TYPES);
 
-	snd_iprintf(buffer, "ch\tuse\n");
+	snd_iprintf(buffer, "ch\tdirty\tuse\n");
 	for (idx = 0; idx < NUM_G; idx++) {
 		voice = &emu->voices[idx];
-		snd_iprintf(buffer, "%i\t%s\n",
+		snd_iprintf(buffer, "%i\t%u\t%s\n",
 			idx,
+			voice->dirty,
 			types[voice->use]);
 	}
 }
diff --git a/sound/pci/emu10k1/voice.c b/sound/pci/emu10k1/voice.c
index ac89d09ed9bc..25e78fc188bf 100644
--- a/sound/pci/emu10k1/voice.c
+++ b/sound/pci/emu10k1/voice.c
@@ -87,9 +87,10 @@  static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
 static void voice_free(struct snd_emu10k1 *emu,
 		       struct snd_emu10k1_voice *pvoice)
 {
-	snd_emu10k1_voice_init(emu, pvoice->number);
+	if (pvoice->dirty)
+		snd_emu10k1_voice_init(emu, pvoice->number);
 	pvoice->interrupt = NULL;
-	pvoice->use = 0;
+	pvoice->use = pvoice->dirty = 0;
 	pvoice->epcm = NULL;
 }