ALSA: emu10k1: multi-channel playback related improvements
cover ALSA: emu10k1: multi-channel playback related improvements
Oswald Buddenhagen (3):
ALSA: emu10k1: don't limit multi-channel playback to two periods
ALSA: emu10k1: add synchronized start of multi-channel playback
ALSA: emu10k1: make channel count of multi-channel playback flexible
include/sound/emu10k1.h | 10 +++- sound/pci/emu10k1/emupcm.c | 115 +++++++++++++++++++++++++++++-------- sound/pci/emu10k1/io.c | 82 ++++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 26 deletions(-)
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 1/3 ALSA: emu10k1: don't limit multi-channel playback to two periods
For unclear reasons, the extra voice was set up with half the buffer size instead of the period size. Commit 27ae958cf6 ("emu10k1 driver - add multichannel device hw:x,3 [2-8/8]") mentions half-loop interrupts, so maybe this was an artifact of an earlier iteration of the patch.
While at it, also fix periods_min of the regular playback - one period makes just no sense.
--- sound/pci/emu10k1/emupcm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
sound/pci/emu10k1/emupcm.c +5 -4
@@ -429,15 +429,16 @@ static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;struct snd_emu10k1_pcm *epcm = runtime->private_data;unsigned int start_addr; -unsigned int channel_size; +unsigned int extra_size, channel_size;int i; start_addr = epcm->start_addr >>1 ;// 16-bit voices + extra_size = runtime->period_size; channel_size = runtime->buffer_size;snd_emu10k1_pcm_init_extra_voice (emu, epcm->extra, true, - start_addr, start_addr + (channel_size /2 )); + start_addr, start_addr + extra_size); epcm->ccca_start_addr = start_addr;for (i =0 ; i <NUM_EFX_PLAYBACK ; i++) {
@@ -465,7 +466,7 @@ static const struct snd_pcm_hardware snd_emu10k1_efx_playback = .buffer_bytes_max = (128*1024), .period_bytes_max = (128*1024), .periods_min = 2, - .periods_max = 2, + .periods_max = 1024, .fifo_size = 0, };
@@ -925,7 +926,7 @@ static const struct snd_pcm_hardware snd_emu10k1_playback = .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_max = (128*1024), - .periods_min = 1, + .periods_min = 2, .periods_max = 1024, .fifo_size = 0, };
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 2/3 ALSA: emu10k1: add synchronized start of multi-channel playback
In reply to Oswald BuddenhagenWe use independent voices for the channels, so we need to make an effort to ensure that they are actually in sync.
The hardware doesn't provide atomicity, so we may need to retry a few times, due to NMIs, PCI contention, and the wrong phase of the moon.
Solution inspired by kX-project.
--- include/sound/emu10k1.h | 10 +++- sound/pci/emu10k1/emupcm.c | 100 ++++++++++++++++++++++++++++++------- sound/pci/emu10k1/io.c | 82 ++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 19 deletions(-)
include/sound/emu10k1.h +9 -1
@@ -422,7 +422,8 @@ SUB_REG(HCFG, LOCKTANKCACHE, 0x00000004) /* 1 = Cancel bustmaster accesses to ta#define CPF 0x00/* Current pitch and fraction register */ SUB_REG(CPF, CURRENTPITCH, 0xffff0000) /* Current pitch (linear, 0x4000 == unity pitch shift) */#define CPF_STEREO_MASK 0x00008000/* 1 = Even channel interleave, odd channel locked */ -#define CPF_STOP_MASK 0x00004000/* 1 = Current pitch forced to 0 */ +SUB_REG (CPF ,STOP ,0x00004000 )/* 1 = Current pitch forced to 0 */ + /* Can be set only while matching bit in SOLEx is 1 */#define CPF_FRACADDRESS_MASK 0x00003fff/* Linear fractional address of the current channel */ #define PTRX 0x01/* Pitch target and send A/B amounts register */
@@ -771,6 +772,9 @@ SUB_REG(PEFE, FILTERAMOUNT, 0x000000ff) /* Filter envlope amount */#define CLIPL 0x5a/* Channel loop interrupt pending low register */ #define CLIPH 0x5b/* Channel loop interrupt pending high register */ +// These cause CPF_STOP_MASK to be set shortly after CCCA_CURRADDR passes DSL_LOOPENDADDR. +// Subsequent changes to the address registers don't resume; clearing the bit here or in CPF does. +// The registers are NOT synchronized; the next serviced channel picks up immediately. #define SOLEL 0x5c/* Stop on loop enable low register */ #define SOLEH 0x5d/* Stop on loop enable high register */
@@ -1476,6 +1480,7 @@ struct snd_emu10k1_pcm {struct snd_emu10k1_voice *extra;unsigned short running;unsigned short first_ptr; +snd_pcm_uframes_t resume_pos;struct snd_util_memblk *memblk;unsigned int start_addr;unsigned int ccca_start_addr;
@@ -1820,6 +1825,9 @@ void snd_emu10k1_voice_half_loop_intr_ack(struct snd_emu10k1 *emu, unsigned intvoid snd_emu10k1_voice_set_loop_stop (struct snd_emu10k1 *emu,unsigned int voicenum);void snd_emu10k1_voice_clear_loop_stop (struct snd_emu10k1 *emu,unsigned int voicenum);#endif +void snd_emu10k1_voice_set_loop_stop_multiple (struct snd_emu10k1 *emu,u64 voices); +void snd_emu10k1_voice_clear_loop_stop_multiple (struct snd_emu10k1 *emu,u64 voices); +int snd_emu10k1_voice_clear_loop_stop_multiple_atomic (struct snd_emu10k1 *emu,u64 voices);void snd_emu10k1_wait (struct snd_emu10k1 *emu,unsigned int wait);static inline unsigned int snd_emu10k1_wc (struct snd_emu10k1 *emu) {return (inl (emu->port +WC ) >>6 ) &0xfffff ; }unsigned short snd_emu10k1_ac97_read (struct snd_ac97 *ac97,unsigned short reg);
sound/pci/emu10k1/emupcm.c +82 -18
144 lines not on this page · raw message
sound/pci/emu10k1/io.c +82 -0
88 lines not on this page · raw message
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 3/3 ALSA: emu10k1: make channel count of multi-channel playback flexible
In reply to Oswald BuddenhagenThere is no reason to nail it to 16 channels.
--- sound/pci/emu10k1/emupcm.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
sound/pci/emu10k1/emupcm.c +9 -9
@@ -430,18 +430,18 @@ static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)struct snd_emu10k1_pcm *epcm = runtime->private_data;unsigned int start_addr;unsigned int extra_size, channel_size; -int i; +unsigned int i; start_addr = epcm->start_addr >>1 ;// 16-bit voices extra_size = runtime->period_size; channel_size = runtime->buffer_size;snd_emu10k1_pcm_init_extra_voice (emu, epcm->extra, true, start_addr, start_addr + extra_size); epcm->ccca_start_addr = start_addr; -for (i =0 ; i <NUM_EFX_PLAYBACK ; i++) { +for (i =0 ; i < runtime->channels; i++) {snd_emu10k1_pcm_init_voices (emu, epcm->voices[i], true, false, start_addr, start_addr + channel_size, &emu->efx_pcm_mixer[i]);
@@ -461,7 +461,7 @@ static const struct snd_pcm_hardware snd_emu10k1_efx_playback = .rates = SNDRV_PCM_RATE_48000, .rate_min = 48000, .rate_max = 48000, - .channels_min = NUM_EFX_PLAYBACK, + .channels_min = 1, .channels_max = NUM_EFX_PLAYBACK, .buffer_bytes_max = (128*1024), .period_bytes_max = (128*1024),
@@ -903,32 +903,32 @@ static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream,case SNDRV_PCM_TRIGGER_PAUSE_RELEASE :case SNDRV_PCM_TRIGGER_RESUME : mask =snd_emu10k1_efx_playback_voice_mask ( - epcm,NUM_EFX_PLAYBACK ); + epcm, runtime->channels);for (int i =0 ; i <10 ; i++) {// Note that the freeze is not interruptible, so we make no // effort to reset the bits outside the error handling here. snd_emu10k1_voice_set_loop_stop_multiple (emu, mask);snd_emu10k1_efx_playback_freeze_voices ( - emu, epcm,NUM_EFX_PLAYBACK ); + emu, epcm, runtime->channels);snd_emu10k1_playback_prepare_voices ( - emu, epcm, true, false,NUM_EFX_PLAYBACK ); + emu, epcm, true, false, runtime->channels);// It might seem to make more sense to unmute the voices only after // they have been started, to potentially avoid torturing the speakers // if something goes wrong. However, we cannot unmute atomically, // which means that we'd get some mild artifacts in the regular case. -snd_emu10k1_efx_playback_unmute_voices (emu, epcm,NUM_EFX_PLAYBACK ); +snd_emu10k1_efx_playback_unmute_voices (emu, epcm, runtime->channels);snd_emu10k1_playback_set_running (emu, epcm); result =snd_emu10k1_voice_clear_loop_stop_multiple_atomic (emu, mask);if (result ==0 ) {// The extra voice is allowed to lag a bit snd_emu10k1_playback_trigger_voice (emu, epcm->extra); goto leave; }snd_emu10k1_efx_playback_stop_voices ( - emu, epcm,NUM_EFX_PLAYBACK ); + emu, epcm, runtime->channels);if (result != -EAGAIN )break ;
@@ -941,7 +941,7 @@ static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream,case SNDRV_PCM_TRIGGER_PAUSE_PUSH :snd_emu10k1_playback_stop_voice (emu, epcm->extra);snd_emu10k1_efx_playback_stop_voices ( - emu, epcm,NUM_EFX_PLAYBACK ); + emu, epcm, runtime->channels); epcm->resume_pos =snd_emu10k1_playback_pointer (substream);break ;
Signature · 1 line
2.40.0.152.g15d061e6df
Takashi Iwai
AppliedQuoted 6 lines · Oswald Buddenhagen
Oswald Buddenhagen (3):
ALSA: emu10k1: don't limit multi-channel playback to two periods
ALSA: emu10k1: add synchronized start of multi-channel playback
ALSA: emu10k1: make channel count of multi-channel playback flexible
Applied all three patches. Thanks.
Takashi