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 <keqiaox.k.zhang@xxxxxxxxxxxxxxx> > --- > 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 _______________________________________________ Alsa-devel mailing list Alsa-devel@xxxxxxxxxxxxxxxx http://mailman.alsa-project.org/mailman/listinfo/alsa-devel