ALSA: emu10k1: make snd_emu10k1_voice_alloc() assign voices' epcm
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>
Thu, 18 May 2023 14:09:46 +0000 (16:09 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sat, 20 May 2023 08:16:03 +0000 (10:16 +0200)
The voice allocator clearly knows about the field (it resets it), so
it's more consistent (and leads to less duplicated code) to have the
constructor take it as a parameter.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Link: https://lore.kernel.org/r/20230518140947.3725394-7-oswald.buddenhagen@gmx.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/emu10k1.h
sound/pci/emu10k1/emu10k1_callback.c
sound/pci/emu10k1/emupcm.c
sound/pci/emu10k1/voice.c

index 0ce84be..3cd1b77 100644 (file)
@@ -1850,7 +1850,8 @@ int snd_emu10k1_synth_copy_from_user(struct snd_emu10k1 *emu, struct snd_util_me
 int snd_emu10k1_memblk_map(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk);
 
 /* voice allocation */
-int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int pair, struct snd_emu10k1_voice **rvoice);
+int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int pair,
+                           struct snd_emu10k1_pcm *epcm, struct snd_emu10k1_voice **rvoice);
 int snd_emu10k1_voice_free(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *pvoice);
 
 /* MIDI uart */
index 6d483bd..2fdfed7 100644 (file)
@@ -287,7 +287,7 @@ get_voice(struct snd_emux *emu, struct snd_emux_port *port)
                        if (vp->ch < 0) {
                                /* allocate a voice */
                                struct snd_emu10k1_voice *hwvoice;
-                               if (snd_emu10k1_voice_alloc(hw, EMU10K1_SYNTH, 1, &hwvoice) < 0 || hwvoice == NULL)
+                               if (snd_emu10k1_voice_alloc(hw, EMU10K1_SYNTH, 1, NULL, &hwvoice) < 0 || hwvoice == NULL)
                                        continue;
                                vp->ch = hwvoice->number;
                                emu->num_voices++;
index 9d6eb58..0651e77 100644 (file)
@@ -95,15 +95,13 @@ static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voic
        err = snd_emu10k1_voice_alloc(epcm->emu,
                                      epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
                                      voices,
-                                     &epcm->voices[0]);
+                                     epcm, &epcm->voices[0]);
        
        if (err < 0)
                return err;
-       epcm->voices[0]->epcm = epcm;
        if (voices > 1) {
                for (i = 1; i < voices; i++) {
                        epcm->voices[i] = &epcm->emu->voices[(epcm->voices[0]->number + i) % NUM_G];
-                       epcm->voices[i]->epcm = epcm;
                }
        }
        if (epcm->extra == NULL) {
@@ -114,7 +112,7 @@ static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voic
                err = snd_emu10k1_voice_alloc(epcm->emu,
                                              epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM_IRQ : EMU10K1_EFX_IRQ,
                                              1,
-                                             &epcm->extra);
+                                             epcm, &epcm->extra);
                if (err < 0) {
                        /*
                        dev_dbg(emu->card->dev, "pcm_channel_alloc: "
@@ -124,7 +122,6 @@ static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voic
                        snd_emu10k1_pcm_free_voices(epcm);
                        return err;
                }
-               epcm->extra->epcm = epcm;
                epcm->extra->interrupt = snd_emu10k1_pcm_interrupt;
        }
 
index 25e78fc..6c58e3b 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
-                      struct snd_emu10k1_voice **rvoice)
+                      struct snd_emu10k1_pcm *epcm, struct snd_emu10k1_voice **rvoice)
 {
        struct snd_emu10k1_voice *voice;
        int i, j, k, first_voice, last_voice, skip;
@@ -79,6 +79,7 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
                       voice->number, idx-first_voice+1, number);
                */
                voice->use = type;
+               voice->epcm = epcm;
        }
        *rvoice = &emu->voices[first_voice];
        return 0;
@@ -95,7 +96,7 @@ static void voice_free(struct snd_emu10k1 *emu,
 }
 
 int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number,
-                           struct snd_emu10k1_voice **rvoice)
+                           struct snd_emu10k1_pcm *epcm, struct snd_emu10k1_voice **rvoice)
 {
        unsigned long flags;
        int result;
@@ -107,7 +108,7 @@ int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number,
 
        spin_lock_irqsave(&emu->voice_lock, flags);
        for (;;) {
-               result = voice_alloc(emu, type, number, rvoice);
+               result = voice_alloc(emu, type, number, epcm, rvoice);
                if (result == 0 || type == EMU10K1_SYNTH)
                        break;