From: Takashi Iwai Subject: Re: [PATCH] alsabat: fix the buffer size dependency issue Date: Wed, 16 Aug 2017 18:07:20 +0200 Message-ID: References: <20170808143138.18439-1-keqiaox.k.zhang@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 mx1.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id B92D4266B1C for ; Wed, 16 Aug 2017 18:07:20 +0200 (CEST) In-Reply-To: <20170808143138.18439-1-keqiaox.k.zhang@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: Zhang Keqiao Cc: keqiao.zhang@intel.com, alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Tue, 08 Aug 2017 16:31:38 +0200, Zhang Keqiao wrote: > > In round trip latency test, the latency time is depends on the buffer > size, before the test, it will playing one second 0 data to synchronize > the playback thread and the recording thread, then begin playing a ~1000 > HZ sine wave and record it. Stop counting and playing if the input's > loudness is higher than the threshold. The issue here is before catching > the sine wave, the buffer is full with 0 data need to deal with, so this > latency is also counted. > > This patch is intends to use flag to do the thread synchronization instead > of playing 0 data, once recording thread is ready, playing the ~1000 HZ > sine wave and start over this process until the final test is over. > > Signed-off-by: Zhang Keqiao > --- > bat/alsa.c | 26 +++++++++++++++++++++++--- > bat/common.h | 4 +++- > bat/latencytest.c | 47 +++++++++++++++++++++++++---------------------- > 3 files changed, 51 insertions(+), 26 deletions(-) > > diff --git a/bat/alsa.c b/bat/alsa.c > index 7613f44..5af7766 100644 > --- a/bat/alsa.c > +++ b/bat/alsa.c > @@ -351,6 +351,14 @@ static int latencytest_process_output(struct pcm_container *sndpcm, > > bat->latency.is_playing = true; > > + /* set playback ready */ > + bat->latency.state = LATENCY_STATE_PLAY_READY; > + > + /* wait for capture ready */ > + while (bat->latency.state != LATENCY_STATE_RECORD_AND_LISTEN) { > + usleep(10); > + } The code doesn't look good from the multi-thread synchronization POV... thanks, Takashi