Commit graph

54 commits

Author SHA1 Message Date
Jaroslav Kysela
b36687548d bat: fix the verbose compilation warnings for latest gcc
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-08-30 12:44:37 +02:00
Jaroslav Kysela
55bafb7938 alsabat: improve error handling in bat_init()
Fix 'LC_ALL=C.UTF-8 ./alsabat' command.

Fixes: https://github.com/alsa-project/alsa-utils/issues/192
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-02-27 13:23:28 +01:00
SASANO Takayoshi
613372dc7c Add OpenBSD support
- ERESTART not supported platform: use EINTR instead
- add include/os_compat.h, well-used OS specific definition
- copied include/bswap.h from alsa-lib

- EPIPE and ESTRPIPE are different usage, but currently
  EPIPE is used when ESTRPIPE is not defined.

  To fix this problem, assign ESPIPE instead.

Fixes: https://github.com/alsa-project/alsa-utils/pull/186
Signed-off-by: SASANO Takayoshi <uaa@uaa.org.uk>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-02-03 13:08:44 +01:00
Tim Bird
9e525074d2 bat: Add 'readcapture' option to support analyzing external audio
If audio data is captured on another device (ie we are NOT using
loopback mode), then allow alsabat to analyze that data, by passing
a filename reference on the command line.

Add the '--readcapture' option to the argument parser. When
this option is specified, avoid doing a local capture, and instead
just read the audio data from the indicated file, and analyze that.

Fixes: https://github.com/alsa-project/alsa-utils/pull/166
Signed-off-by: Tim Bird <tim.bird@sony.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-11-04 22:06:00 +01:00
Tobias Geerinckx-Rice
dea85a314b alsabat: fix typo
Halve the double negative ‘if no loopback mode is not available’.

Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 13:00:18 +02:00
Michael Forney
62a765087e Avoid pointer arithmetic on void *
The pointer operand to the binary `+` operator must be to a complete
object type.

Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-02-10 12:38:52 +01:00
Jonathan Liu
f6b59282f7 alsabat: Allow custom sample format for round trip latency test
Setting the format to BAT_PCM_FORMAT_S16_LE in the round trip latency
test initialization is redundant as it is already set by default to
BAT_PCM_FORMAT_S16_LE unless a sample format is specified on the command
line.

Signed-off-by: Jonathan Liu <net147@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-08-05 18:45:28 +02:00
Jaroslav Kysela
b9b40a2a9f bat: alsa.c - move the thread cleanup pop before goto exit3
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-04-03 10:54:38 +02:00
Zhang Keqiao
dbd4fc84f8 alsabat: fix one uninitialized warning issue
Fix a variable uninitialized issue, adding the initialized assignment to fix it.

Signed-off-by: Zhang Keqiao <keqiaox.k.zhang@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-08-30 10:19:08 +02:00
Keqiao, Zhang
7b122fb62a alsabat: add system power management S3 test
Support audio pause/resume for playback and capture. The user can
pause alsabat playback/capture threads by sending a signal. The patch
provides a method for QA to quick test audio during system s3.

Signed-off-by: Keqiao, Zhang <keqiao.zhang@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-08-30 07:49:46 +02:00
Keqiao, Zhang
cadd877da6 alsabat: fix alsabat -86 error
alsabat reports -86 error when system suspend and resume. Check the
return value of read_to_pcm() and write_to_pcm(), when -x8 err is
detected, do resume and wait for read/write to pcm to complete.

Write PCM device error: Streams pipe error(-86)
Read PCM device error: Streams pipe error(-86)
*** Error in alsabat: double free or corruption (out): 0x00007fb438001810 ***

Signed-off-by: Keqiao, Zhang <keqiao.zhang@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-08-30 07:49:37 +02:00
Focus Luo
18a1ed8f89 alsabat: add amixer config files
This patch includes the reference asound.state config files
on Intel Skylake, Broadwell and Hsawell platforms

Signed-off-by: Focus Luo <focus.luo@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-08-23 15:43:23 +02:00
Focus Luo
0882d92732 alsabat: automation test scripts
This patch includes automated test scripts for linux audio driver
based on alsa-lib interface by using alsabat as test tool.
It supports analog and display(HDMI/DP) audio test.
The package needs the alsa-utils, alsa-lib installed environment.

Signed-off-by: Focus Luo <focus.luo@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-08-23 15:40:03 +02:00
Vinod Koul
81eb216807 alsabat: make snr_is_valid static
The compilation fails due to multiple defination of snr_is_valid

common.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here

signal.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here

latencytest.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here

analyze.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here

alsa.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-07-20 07:23:06 +02:00
Lu, Han
9dee2da0af alsabat: fix a missing break in switch
Add the break line for OPT_ROUNDUPLATENCY case.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-12 08:41:07 +02:00
Lu, Han
0cfe406618 alsabat: add noise detection
Alsabat reports error when noise above threshold be detected.
Use either of the options below to designate the threshold. (e.g.
if the ratio of noise to signal is 5%, the snr is about 26dB.)
    --snr-db <value in dB>
    --snr-pc <value in %>

The noise detection is performed in time domain. On each period
of the sine wave being analyzed, alsabat substracts a clean sine
wave from the source, calculates the RMS value of the residual,
and compares the result with the threshold. At last, alsabat
returns the number of periods with noise above threshold. 0 is
returned when the source is clean.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-08 15:17:14 +02:00
Lu, Han
e1b7a5f376 alsabat: add a single channel sine wave generator
Add function generate_sine_wave_raw_mono(). It serves as a single
channel sine wave generator, to provide data for calculation (e.g.
for noise analysis).
The function is similar to generate_sine_wave(), but a lite revision.
It has no dependency on bat channels and target frequency, no malloc
inside, no data conversion from float to integer samples, and supports
one channel only.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-08 15:14:06 +02:00
Lu, Han
e0c1c86a90 alsabat: add channels parameter for adjust_waveform()
The function adjust_waveform() is a component of generate_sine_wave(),
and depended on bat->channels parameter. Add parameter "channels" to
remove the dependency, and then adjust_waveform() can be applied on
other use cases, e.g. a single channel sine wave generator.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-08 15:13:53 +02:00
Lu, Han
09cb66f40c alsabat: align the data type on float
Aligning the data type of fftw analyzer, sample converter and other
components on float, because:
  1. avoid unnecessary data type conversion;
  2. using float is more efficient than using double;
  3. the extra double accuracy is not required.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-08 15:12:27 +02:00
vivian,zhang
4157528808 alsabat: add round trip audio latency test
Audio latency is the time delay as an audio signal passes through
a system. There are many kinds of audio latency metrics. One useful
metric is the round trip latency, which is the sum of output latency
and input latency.

The measurement step works like below:
1. Listen and measure the average loudness of the environment for
one second;
2. Create a threshold value 16 decibels higher than the average
loudness;
3. Begin playing a ~1000 Hz sine wave and start counting the samples
elapsed;
4. Stop counting and playing if the input's loudness is higher than
the threshold, as the output wave is probably coming back;
5. Calculate the audio latency value in milliseconds.

Signed-off-by: Zhang Vivian <vivian.zhang@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-08 15:11:25 +02:00
Lu, Han
2b3adf8668 alsabat: fix a possible memory leak
Fix a possible memory leak in generate_sine_wave(). Memory free was
ignored when the function return an error.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-01 12:33:44 +02:00
vivian,zhang
9e196efda4 alsabat: add buffer size and period size settings
Add buffer size and period size settings in alsabat.
With -E and -B options, alsabat performs the test with
specified buffer size and period size

Signed-off-by: Zhang Vivian <vivian.zhang@intel.com>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-05-31 16:05:07 +02:00
Lu, Han
569f2c116e alsabat: add terminate status check for capture thread
In loopback test, alsabat use pthread_join(pthread_t thread, **retval)
to wait for the capture thread to terminate. If the capture thread was
canceled, PTHREAD_CANCELED is placed in *retval, and the access to the
**retval will fail. Add status check to prevent illegal access to the
**retval.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-04-18 16:34:08 +02:00
Lu, Han
f51cb7212a alsabat: add tinyalsa support
Use "configure --enable-alsabat-backend-tiny" for alsabat to use
tinyalsa as backend lib. On a system that has both ALSA and tinyalsa
installed, alsabat will use ALSA library by default.
The intention is for alsabat to run on tinyalsa platforms such as
Android or some Internet of Things(IoT) devices.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-23 17:51:22 +01:00
Lu, Han
986db20331 alsabat: move alsa process to a single block
Move all alsa callings to a single block (alsa.c), so other blocks
such as the main structure, the signal process and the data analysis
modules will be independent to alsa, and new modules such as a
tinyalsa interface can be easily embedded into alsabat.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-23 17:51:22 +01:00
Lu, Han
c49a6180c8 alsabat: use general data generator function
Use general data generator to replace local function, so other
modules can reuse the data generator rather than re-implement it.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-23 17:51:21 +01:00
Lu, Han
eac9b149b4 alsabat: clean return value for playback and capture threads
Remove unnecessary prints in playback and capture threads, and replace
the return value "0" with error code for convenience of maintaining.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-23 17:51:21 +01:00
Lu, Han
2c37a6f9c4 alsabat: use general function for wav header update
In playback thread, use general function update_wav_header()
to replace a bunch of code, so the structure is cleaner and
no need to define variable "wav".

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-23 17:51:21 +01:00
Lu, Han
241d7fc1bb alsabat: refactoring alsa capture thread
Refactoring ALSA capture thread:
  1. Move file open/seek operations to sub function, so all file
  processes are now on a single function (read_from_pcm_loop()), so
  the structure is more reasonable, the function API is simplified
  and no need file cleanup in thread loop.
  2. Replace the wav header processing lines with a general function
  (update_wav_header()), which can be reused in other sections.
  3. Add pthread_exit() for thread to exit safely in single line mode,
  and correct comment.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-23 17:51:21 +01:00
Lu, Han
98de9f7905 alsabat: use variable for thread return value
Use variable instead of 0/1 to indicate the return value of
playback and capture threads.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-21 18:04:36 +01:00
Lu, Han
f2f6583ee6 alsabat: fix fopen and messages
All files should be opened in either "rb" or "wb" in current
usage.
Remove incorrect and unneccesary prints.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-21 18:04:03 +01:00
Lu, Han
bd6c706606 alsabat: fix misusing of errno
Preserve errno value before use, since the value might be
changed by another library call.
Add "#include <errno.h>" and remove redundant include.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-21 18:03:12 +01:00
Lu, Han
f84c15ca1d alsabat: add bash test script
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-15 09:59:56 +01:00
Lu, Han
72800ad6bd alsabat: add standalone mode
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-15 09:59:26 +01:00
Lu, Han
333cd85d7d alsabat: add default device name for playback and capture
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-15 09:59:09 +01:00
Lu, Han
380c9fa444 alsabat: truncate sample frames for faster FFT analysis
Truncate the sample frames to powers of 2, since the FFTW algorithm
runs especially fast in this case, and other sizes may be computed
by means of a slow, general-purpose algorithm.
In my test environment applying the patch, a sound clip of 33072
frames is cut off to 32768 frames before analysis, and the time
cost is reduced from 6.128s to 0.224s.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-01 10:31:00 +01:00
Lu, Han
9fa7f6fd06 alsabat: rename to avoid naming conflict
alsa-utils as well as bareos-bat (as well a some Bacula packages)
all contain a program called /usr/bin/bat, which causes conflicts on
various distributions ("basic audio tester" vs "bareos administration
tool"("bacula administration tool")).
Rename to avoid conflict.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-03 08:49:53 +01:00
Takashi Iwai
ed0cce1b60 bat: Don't pass incompatible function pointers to pthread_cleanup_push()
pthread_cleanup_push() takes a function pointer for void (void *).
Although it may work in most cases, we shouldn't pass an incompatible
function pointer there, as some old gcc complains:
  alsa.c:560: warning: initialization from incompatible pointer type
  alsa.c:562: warning: initialization from incompatible pointer type

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-09 14:09:50 +01:00
Takashi Iwai
3bf8e79c3b bat: Avoid local signal.h file
The local header file named as "signal.h" causes mysterious compile
error when built with an old glibc.
 signal.h:27: error: conflicting types for 'sin_generator_init'
 ./signal.h:27: error: previous declaration of 'sin_generator_init' was here
 signal.h:28: error: conflicting types for 'sin_generator_next_sample'
 ./signal.h:28: error: previous declaration of 'sin_generator_next_sample' was here
 ....

This turned out to be the conflict of signal.h; namely, pthread.h that
is included before our local signal.h also includes "pthread.h".
Since our local "signal.h" has a higher priority, it gets loaded
instead of the expected pthread's one.  Then we load it again, and it
screws up.

Although it's basically a bug of pthread, it's anyway not good to have
a header file conflicting with the standard header file.  So, let's
name it more explicitly as specific to BAT, bat-signal.h, for avoiding
such a conflict.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-09 14:04:11 +01:00
Jaroslav Kysela
47e668f453 bat: add all headers to noinst_HEADERS
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2015-10-27 17:32:51 +01:00
Jaroslav Kysela
bc352dfba9 bat: don't link all binaries with fftw library, add missing header
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2015-10-27 17:15:58 +01:00
Caleb Crome
0960094905 BAT: Add missing locale.h header
Missing include became apparent when -O3 was not specified.
Added the header to remove error messages during debug compile.

Signed-off-by: Caleb Crome <caleb@crome.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-24 09:43:26 +02:00
Lu, Han
73f9dd149e BAT: Add man page
Add more information about BAT utility, including design intent,
principles, use mode, hardware connection, options, example and
return value.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-21 09:29:52 +02:00
Lu, Han
2abee9c5b4 BAT: Use dynamic temp file
Use dynamic temp file instead of fixed temp file to store recorded
wav data, for better security.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 11:06:24 +02:00
Lu, Han
5a48606d94 BAT: Change comments and interface of usage()
1. Change comment strings to make the descriptions more clear;
2. Add indent for option lines that have no indent;
3. Use a const string instead of argv[0] as program name.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 11:06:24 +02:00
Lu, Han
8c910830f0 BAT: Use colon instead of comma for separation
Use colon instead of comma to separate frequency parameters, for
in several locale comma may be handled as decimal point.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 11:06:24 +02:00
Lu, Han
2d0a124674 BAT: Remove redundant message strings
Cutting down 6 message strings to 2, as translators need to work
on each different variant.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 11:06:23 +02:00
Lu, Han
226ad884d2 BAT: Add Makefile and configures
Add Makefile and configures that enable BAT on alsa-utils

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@intel.com>
Signed-off-by: Bernard Gautier <bernard.gautier@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 12:42:03 +02:00
Lu, Han
d727c9d90e BAT: Add spectrum analysis functions
Add functions that detecting signal frequency through spectrum
analyzing.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@intel.com>
Signed-off-by: Bernard Gautier <bernard.gautier@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 12:42:03 +02:00
Lu, Han
6c4c5e51fa BAT: Add converting functions
Add functions that converting audio samples to double data for analysis,
and functions that converting float data to audio samples for playback.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@intel.com>
Signed-off-by: Bernard Gautier <bernard.gautier@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 12:42:02 +02:00