[alsa-devel] [PATCH 0/3] *** new features for alsabat ***
From: "Lu, Han" han.lu@intel.com
Add 3 features for alsabat: 1. add default device name for playback and capture 2. add standalone mode, to bypass data analysis 3. add bash test script to cover basic alsabat features
Lu, Han (3): alsabat: add default device name for playback and capture alsabat: add standalone mode alsabat: add bash test script
bat/Makefile.am | 13 +++--- bat/alsa.c | 12 ------ bat/alsabat-test.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bat/alsabat.1 | 9 +++++ bat/bat.c | 18 ++++++++- bat/common.h | 3 ++ configure.ac | 5 ++- 7 files changed, 153 insertions(+), 19 deletions(-) create mode 100755 bat/alsabat-test.sh
From: "Lu, Han" han.lu@intel.com
Add default name for the playback and capture devices, in case they were not set by user through '-D', '-P' or '-C' options. Previously, if no device be specified, the alsabat will start a playback thread and a capture thread, and then exit the threads with error log. If only one of playback and capture is specified, the alsabat will work on single line mode as before, where only one thread (playback or capture) will be started. The patch was tested on Ubuntu and Chrome OS.
Signed-off-by: Lu, Han han.lu@intel.com
diff --git a/bat/alsa.c b/bat/alsa.c index 5eaa25b..5775748 100644 --- a/bat/alsa.c +++ b/bat/alsa.c @@ -377,12 +377,6 @@ void *playback_alsa(struct bat *bat) retval_play = 0; memset(&sndpcm, 0, sizeof(sndpcm));
- if (bat->playback.device == NULL) { - fprintf(bat->err, _("No PCM device for playback: exit\n")); - retval_play = 1; - goto exit1; - } - err = snd_pcm_open(&sndpcm.handle, bat->playback.device, SND_PCM_STREAM_PLAYBACK, 0); if (err != 0) { @@ -533,12 +527,6 @@ void *record_alsa(struct bat *bat) retval_record = 0; memset(&sndpcm, 0, sizeof(sndpcm));
- if (bat->capture.device == NULL) { - fprintf(bat->err, _("No PCM device for capture: exit\n")); - retval_record = 1; - goto exit1; - } - err = snd_pcm_open(&sndpcm.handle, bat->capture.device, SND_PCM_STREAM_CAPTURE, 0); if (err != 0) { diff --git a/bat/bat.c b/bat/bat.c index ddb60b7..9c637f2 100644 --- a/bat/bat.c +++ b/bat/bat.c @@ -473,6 +473,10 @@ static int bat_init(struct bat *bat) return err; }
+ /* Set default playback and capture devices */ + if (bat->playback.device == NULL && bat->capture.device == NULL) + bat->playback.device = bat->capture.device = DEFAULT_DEV_NAME; + /* Determine capture file */ if (bat->local) { bat->capture.file = bat->playback.file; diff --git a/bat/common.h b/bat/common.h index 7346d9f..5417c0e 100644 --- a/bat/common.h +++ b/bat/common.h @@ -16,6 +16,7 @@ #include <alsa/asoundlib.h>
#define TEMP_RECORD_FILE_NAME "/tmp/bat.wav.XXXXXX" +#define DEFAULT_DEV_NAME "default"
#define OPT_BASE 300 #define OPT_LOG (OPT_BASE + 1)
From: "Lu, Han" han.lu@intel.com
Add support for standalone mode where alsabat will run on a different machine to the one being tested. In standalone mode, the alsabat just generates, playback and capture sound data like in normal mode, but does not analyze. The alsabat being built without libfftw3 support is always work in standalone mode. The alsabat in normal mode can also bypass data analysis using option "--standalone".
Signed-off-by: Lu, Han han.lu@intel.com
diff --git a/bat/Makefile.am b/bat/Makefile.am index 8dfafa9..5646e9a 100644 --- a/bat/Makefile.am +++ b/bat/Makefile.am @@ -6,7 +6,6 @@ EXTRA_DIST = alsabat.1 alsabat_SOURCES = \ bat.c \ common.c \ - analyze.c \ signal.c \ convert.c \ alsa.c @@ -15,8 +14,12 @@ noinst_HEADERS = \ common.h \ bat-signal.h \ alsa.h \ - convert.h \ - analyze.h + convert.h + +if HAVE_LIBFFTW3 +alsabat_SOURCES += analyze.c +noinst_HEADERS += analyze.h +endif
AM_CPPFLAGS = \ -Wall -I$(top_srcdir)/include diff --git a/bat/alsabat.1 b/bat/alsabat.1 index 8d0b9c0..5f41669 100644 --- a/bat/alsabat.1 +++ b/bat/alsabat.1 @@ -120,6 +120,15 @@ Internal loopback mode. Playback, capture and analysis internal to ALSABAT only. This is intended for developers to test new ALSABAT features as no audio is routed outside of ALSABAT. +.TP +\fI--standalone\fP +Add support for standalone mode where ALSABAT will run on a different machine +to the one being tested. +In standalone mode, the sound data can be generated, playback and captured +just like in normal mode, but will not be analyzed. +The ALSABAT being built without libfftw3 support is always in standalone mode. +The ALSABAT in normal mode can also bypass data analysis using option +"--standalone".
.SH EXAMPLES
diff --git a/bat/bat.c b/bat/bat.c index 9c637f2..85ec5aa 100644 --- a/bat/bat.c +++ b/bat/bat.c @@ -33,7 +33,9 @@
#include "alsa.h" #include "convert.h" +#ifdef HAVE_LIBFFTW3 #include "analyze.h" +#endif
static int get_duration(struct bat *bat) { @@ -289,6 +291,7 @@ _("Usage: alsabat [-options]...\n" " --file=# file for playback\n" " --saveplay=# file that storing playback content, for debug\n" " --local internal loop, set to bypass pcm hardware devices\n" +" --standalone standalone mode, to bypass analysis\n" )); fprintf(bat->log, _("Recognized sample formats are: %s %s %s %s\n"), snd_pcm_format_name(SND_PCM_FORMAT_U8), @@ -339,6 +342,7 @@ static void parse_arguments(struct bat *bat, int argc, char *argv[]) {"file", 1, 0, OPT_READFILE}, {"saveplay", 1, 0, OPT_SAVEPLAY}, {"local", 0, 0, OPT_LOCAL}, + {"standalone", 0, 0, OPT_STANDALONE}, {0, 0, 0, 0} };
@@ -357,6 +361,9 @@ static void parse_arguments(struct bat *bat, int argc, char *argv[]) case OPT_LOCAL: bat->local = true; break; + case OPT_STANDALONE: + bat->standalone = true; + break; case 'D': if (bat->playback.device == NULL) bat->playback.device = optarg; @@ -601,7 +608,12 @@ int main(int argc, char *argv[]) test_loopback(&bat);
analyze: - err = analyze_capture(&bat); +#ifdef HAVE_LIBFFTW3 + if (!bat.standalone) + err = analyze_capture(&bat); +#else + fprintf(bat.log, _("No libfftw3 library. Exit without analysis.\n")); +#endif out: fprintf(bat.log, _("\nReturn value is %d\n"), err);
diff --git a/bat/common.h b/bat/common.h index 5417c0e..30e39fc 100644 --- a/bat/common.h +++ b/bat/common.h @@ -23,6 +23,7 @@ #define OPT_READFILE (OPT_BASE + 2) #define OPT_SAVEPLAY (OPT_BASE + 3) #define OPT_LOCAL (OPT_BASE + 4) +#define OPT_STANDALONE (OPT_BASE + 5)
#define COMPOSE(a, b, c, d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24)) #define WAV_RIFF COMPOSE('R', 'I', 'F', 'F') @@ -150,6 +151,7 @@ struct bat { char *narg; /* argument string of duration */ char *logarg; /* path name of log file */ char *debugplay; /* path name to store playback signal */ + bool standalone; /* enable to bypass analysis */
struct pcm playback; struct pcm capture; diff --git a/configure.ac b/configure.ac index bdb133c..f6f8103 100644 --- a/configure.ac +++ b/configure.ac @@ -70,7 +70,9 @@ if test x$bat = xtrue; then FFTW_INC="" FFTW_LIB="" FFTW_CFLAGS="" - AC_CHECK_LIB([fftw3], [fftw_malloc], , [AC_MSG_ERROR([Error: need FFTW3 library])]) + dnl Check for libfftw3 + have_libfftw3="yes" + AC_CHECK_LIB([fftw3], [fftw_malloc], , [have_libfftw3="no"]) AC_CHECK_LIB([m], [sqrtf], , [AC_MSG_ERROR([Error: Need sqrtf])]) AC_CHECK_LIB([pthread], [pthread_create], , [AC_MSG_ERROR([Error: need PTHREAD library])]) FFTW_CFLAGS="$CFLAGS" @@ -83,6 +85,7 @@ if test x$bat = xtrue; then AC_SUBST(FFTW_CFLAGS)
fi +AM_CONDITIONAL(HAVE_LIBFFTW3, test "$have_libfftw3" = "yes")
dnl Check for librt LIBRT=""
From: "Lu, Han" han.lu@intel.com
Add bash script for alsabat feature test. It covers basic alsabat features, including waveform and wav file generate, playback, capture and analysis with configurable parameters under different work modes. (loopback, single line, standalone and local mode) Usage examples: alsabat-test.sh alsabat-test.sh plughw:1,0 alsabat-test.sh plughw:1,0 plughw:1,0
Signed-off-by: Lu, Han han.lu@intel.com
diff --git a/bat/Makefile.am b/bat/Makefile.am index 5646e9a..712f5bf 100644 --- a/bat/Makefile.am +++ b/bat/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = alsabat man_MANS = alsabat.1 - -EXTRA_DIST = alsabat.1 +EXTRA_DIST = alsabat.1 alsabat-test.sh +sbin_SCRIPTS = alsabat-test.sh
alsabat_SOURCES = \ bat.c \ diff --git a/bat/alsabat-test.sh b/bat/alsabat-test.sh new file mode 100755 index 0000000..2d31a77 --- /dev/null +++ b/bat/alsabat-test.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# default devices +dev_playback="default" +dev_capture="default" + +bin="alsabat" +commands="$bin -P $dev_playback -C $dev_capture" + +file_sin_mono="default_mono.wav" +file_sin_dual="default_dual.wav" +logdir="tmp" + +# frequency range of signal +maxfreq=16547 +minfreq=17 + +# features passes vs. features all +feature_pass=0 +feature_cnt=0 + +init_counter () { + feature_pass=0 + feature_all=0 +} + +evaluate_result () { + feature_cnt=$((feature_cnt+1)) + if [ $1 -eq 0 ]; then + feature_pass=$((feature_pass+1)) + echo "pass" + else + echo "fail" + fi +} + +print_result () { + echo "[$feature_pass/$feature_cnt] features passes." +} + +feature_test () { + echo "============================================" + echo "$feature_cnt: ALSA $2" + echo "-------------------------------------------" + echo "$commands $1 --log=$logdir/$feature_cnt.log" + $commands $1 --log=$logdir/$feature_cnt.log + evaluate_result $? + echo "$commands $1" >> $logdir/$((feature_cnt-1)).log +} + +# test items +feature_list_test () { + init_counter + + commands="$bin" + feature_test "-c1 --saveplay $file_sin_mono" \ + "generate mono wav file with default params" + feature_test "-c2 --saveplay $file_sin_dual" \ + "generate dual wav file with default params" + sleep 5 + feature_test "-P $dev_playback" "single line mode, playback" + feature_test "-C $dev_capture --standalone" "single line mode, capture" + + commands="$bin -P $dev_playback -C $dev_capture" + feature_test "--file $file_sin_mono" "play mono wav file and detect" + feature_test "--file $file_sin_dual" "play dual wav file and detect" + feature_test "-c1" "configurable channel number: 1" + feature_test "-c2 -F $minfreq:$maxfreq" "configurable channel number: 2" + feature_test "-r44100" "configurable sample rate: 44100" + feature_test "-r48000" "configurable sample rate: 48000" + feature_test "-n10000" "configurable duration: in samples" + feature_test "-n2.5s" "configurable duration: in seconds" + feature_test "-f U8" "configurable data format: U8" + feature_test "-f S16_LE" "configurable data format: S16_LE" + feature_test "-f S24_3LE" "configurable data format: S24_3LE" + feature_test "-f S32_LE" "configurable data format: S32_LE" + feature_test "-f cd" "configurable data format: cd" + feature_test "-f dat" "configurable data format: dat" + feature_test "-F $maxfreq --standalone" \ + "standalone mode: play and capture" + latestfile=`ls -t1 /tmp/bat.wav.* | head -n 1` + feature_test "--local -F $maxfreq --file $latestfile" \ + "local mode: analyze local file" + + print_result +} + +echo "*******************************************" +echo " BAT Test " +echo "-------------------------------------------" + +# get device +echo "usage:" +echo " $0 <sound card>" +echo " $0 <device-playback> <device-capture>" + +if [ $# -eq 2 ]; then + dev_playback=$1 + dev_capture=$2 +elif [ $# -eq 1 ]; then + dev_playback=$1 + dev_capture=$1 +fi + +echo "current setting:" +echo " $0 $dev_playback $dev_capture" + +# run +mkdir -p $logdir +feature_list_test + +echo "*******************************************"
On Tue, 15 Mar 2016 04:18:51 +0100, han.lu@intel.com wrote:
From: "Lu, Han" han.lu@intel.com
Add 3 features for alsabat: 1. add default device name for playback and capture 2. add standalone mode, to bypass data analysis 3. add bash test script to cover basic alsabat features
Lu, Han (3): alsabat: add default device name for playback and capture alsabat: add standalone mode alsabat: add bash test script
Applied all three patches now. Thanks.
Takashi
participants (2)
-
han.lu@intel.com
-
Takashi Iwai