Commit 9581128a authored by Oswald Buddenhagen's avatar Oswald Buddenhagen Committed by Takashi Iwai

ALSA: emu10k1: refactor PCM playback cache filling

Rename snd_emu10k1_playback_invalidate_cache() to the more apt
snd_emu10k1_playback_fill_cache(), and factor out
snd_emu10k1_playback_prepare_voices(), which calls the former for all
channels.
Signed-off-by: default avatarOswald Buddenhagen <oswald.buddenhagen@gmx.de>
Link: https://lore.kernel.org/r/20230517174256.3657060-8-oswald.buddenhagen@gmx.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 9e72666b
...@@ -511,16 +511,12 @@ static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream) ...@@ -511,16 +511,12 @@ static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream)
return 0; return 0;
} }
static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu, static void snd_emu10k1_playback_fill_cache(struct snd_emu10k1 *emu,
struct snd_emu10k1_voice *evoice, unsigned voice,
bool w_16, bool stereo) u32 sample, bool stereo)
{ {
unsigned voice, sample;
u32 ccr; u32 ccr;
voice = evoice->number;
sample = w_16 ? 0 : 0x80808080;
// We assume that the cache is resting at this point (i.e., // We assume that the cache is resting at this point (i.e.,
// CCR_CACHEINVALIDSIZE is very small). // CCR_CACHEINVALIDSIZE is very small).
...@@ -539,6 +535,22 @@ static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu, ...@@ -539,6 +535,22 @@ static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu,
snd_emu10k1_ptr_write(emu, CCR, voice, ccr); snd_emu10k1_ptr_write(emu, CCR, voice, ccr);
} }
static void snd_emu10k1_playback_prepare_voices(struct snd_emu10k1 *emu,
struct snd_emu10k1_pcm *epcm,
bool w_16, bool stereo,
int channels)
{
u32 sample = w_16 ? 0 : 0x80808080;
for (int i = 0; i < channels; i++) {
unsigned voice = epcm->voices[i]->number;
snd_emu10k1_playback_fill_cache(emu, voice, sample, stereo);
}
// It takes a moment until the cache fills complete,
// but the unmuting takes long enough for that.
}
static void snd_emu10k1_playback_commit_volume(struct snd_emu10k1 *emu, static void snd_emu10k1_playback_commit_volume(struct snd_emu10k1 *emu,
struct snd_emu10k1_voice *evoice, struct snd_emu10k1_voice *evoice,
unsigned int vattn) unsigned int vattn)
...@@ -632,7 +644,7 @@ static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream, ...@@ -632,7 +644,7 @@ static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
spin_lock(&emu->reg_lock); spin_lock(&emu->reg_lock);
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
snd_emu10k1_playback_invalidate_cache(emu, epcm->voices[0], w_16, stereo); snd_emu10k1_playback_prepare_voices(emu, epcm, w_16, stereo, 1);
fallthrough; fallthrough;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_RESUME:
...@@ -774,10 +786,7 @@ static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream, ...@@ -774,10 +786,7 @@ static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream,
spin_lock(&emu->reg_lock); spin_lock(&emu->reg_lock);
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
/* prepare voices */ snd_emu10k1_playback_prepare_voices(emu, epcm, true, false, NUM_EFX_PLAYBACK);
for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
snd_emu10k1_playback_invalidate_cache(emu, epcm->voices[i], true, false);
}
fallthrough; fallthrough;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_RESUME:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment