From: Takashi Iwai Subject: Re: [PATCH] speaker-test: Fix dropped samples at the end of test Date: Mon, 15 Sep 2014 17:23:52 +0200 Message-ID: References: <1410524068-15982-1-git-send-email-jarkko.nikula@linux.intel.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 61157264FE3 for ; Mon, 15 Sep 2014 17:23:53 +0200 (CEST) In-Reply-To: <1410524068-15982-1-git-send-email-jarkko.nikula@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Jarkko Nikula Cc: alsa-devel@alsa-project.org, guillaume-florianx.vidal@intel.com List-Id: alsa-devel@alsa-project.org At Fri, 12 Sep 2014 15:14:28 +0300, Jarkko Nikula wrote: > > Commit 6d1673526b0f ("Avoid unnecessary drain/restart in speaker-test") > drains only when buffer is bigger than audio sample. This has a drawback > that up to buffer size amount of data may not be heard at the end of audio > sample. > > This was noted with "speaker-test -c 2 -t wav -s 2" test on a > hardware that has a buffer size of 24000 samples and 48 kHz sample rate. > Instead of playing "front right" it played something like "front ra". > > Reverse buffer size vs sample size test wouldn't work either since then > samples smaller than buffer are dropped. > > Fix this by removing buffer_size tests from write_loop() and do > drain/restart always when not aborting. > > Signed-off-by: Jarkko Nikula > Reported-by: Vidal, Guillaume-florianX > --- > This was originally noted on Baytrail ADSP hw (default buffer size 24000) > but can be heard also on Intel HDA (default buffer size 8192) when audio > sample is small enough but bigger than buffer. For instance 100 ms sample > finishes too shortly (buffer size 8192, sample size 9600) but 50 ms plays > ok (buffer size 8192, sample size 4800). > > I guess some optimization can be done for snd_pcm_prepare() when not looping > but that's not necessary for this fix. Won't it suffice by just putting snd_pcm_drain() at the end of the whole operation like below? Doing snd_pcm_drain() and snd_pcm_prepare() at each time causes often undesired pop noises or such. OTOH, doing drain there is good for showing the text at the right time. So, we'll likely want to have both options managed by a command line option. Takashi --- diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index 61396f296c65..362efa7ffc0d 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -1307,6 +1307,7 @@ int main(int argc, char *argv[]) { } } + snd_pcm_drain(handle); free(frames); #ifdef CONFIG_SUPPORT_CHMAP