Commit graph

306 commits

Author SHA1 Message Date
Jaroslav Kysela
05ebe64b2d aplay: add avail > delay checks to --test-position
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-08 18:09:12 +01:00
Jaroslav Kysela
76bc37aeb7 aplay: add test code for snd_pcm_status() to --test-position
We need to test also snd_pcm_status() values.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-03 17:19:07 +01:00
Jaroslav Kysela
c1b92db5ef aplay: fix the CPU busy loop in the pause handler
Use the standard poll mechanism to ensure that there's
something in the input to avoid busy loop on the file
descriptor with the non-block mode set.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-11-08 19:11:22 +01:00
Jaroslav Kysela
986a1bd3d2 aplay: cosmetic code fix in xrun()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-23 12:05:59 +02:00
Hui Wang
0c5948e98a aplay: try to use 16-bit format to increase capture quality
Recently users reported a bug, I tested it and found it is a common
issue on Laptop or Desktop machines.

The issue is users plug a headset and use "arecord test.wav" to
record a sound with default input volume, the recorded sound has
poor quality and nearly can't distinguish it is the sound we want
to record.

This is because the input volume is low and the default format is U8.
The driver records sound with 16bit, because the input volume is low,
most of samples are within (-256,+256), when converting 16bit to U8,
those samples will be 0x7f. This is called quantization noise and we
could only workaround it by increase the input volume or adding -f to
arecord.

But users want to record a better quality sound with default input
volume (after installing a new OS, the volume is the default volume),
and they don't want to add parameters to the arecord because most of
new linux users just use "arecord test.wav".

So this patch tries to change the default format from U8 to S16_LE/BE.
If the machine doesn't support S16_LE/BE, it still uses U8 as default
format.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-23 11:39:52 +02:00
Jaroslav Kysela
246e132b80 aplay: fix the wrong count in compute_max_peak() for 16bit+ sample widths
The count argument was renamed to samples to correctly represent
the value meaning. Also, remove the wrong count recalculation lines
for 16-bit, 24-bit and 32-bit samples.

BugLink: https://github.com/alsa-project/alsa-utils/issues/57
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-15 13:14:39 +02:00
Olivier Humbert
789a307cf9 aplay: Fix typo in error message
BugLink: https://github.com/alsa-project/alsa-utils/pull/44
From: Olivier Humbert <trebmuh@users.noreply.github.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 13:10:54 +02:00
Marcin Rajwa
9b02b42db4 aplay: capture: write only the amount of read frames
This patch changes the way aborted stream is being saved. Currently when
abort signal happens the write back of read samples is skipped but there
is no reason to not save them. Also, we need to know how much frames have
been read and write only those.

Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 12:58:20 +02:00
Marcin Rajwa
5e87e2e021 aplay: pcm_read(): return read samples instead of requested upon abort
This patch changes the logic of pcm_read() when abort signal has been
detected. During such condition we should return the amount of frames
actually read instead of the size requested by caller.

Currently functions pcm_read() and pcm_readv() when aborted (in_aborting
flag set) return the amount of requested frames instead of those actually
read prior to interrupt. The consequence of this is repetition of recent X
frames where X stands for amount of frames in one period. This problem is
barely visible or rather audible when the period is small like few
milliseconds because repetition of 1 [ms] of data is not-noticeable
however if we use buffer and period sizes in seconds then the problem
becomes apparent.

Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 12:58:20 +02:00
Marcin Rajwa
bc7a944c50 aplay: pcm_readv(): return read samples instead of requested upon abort
This patch changes the logic of pcm_readv() when abort signal has been
detected. During such condition we should return the amount of frames
actually read instead of the size requested by caller.

Currently functions pcm_read() and pcm_readv() when aborted (in_aborting
flag set) return the amount of requested frames instead of those actually
read prior to interrupt. The consequence of this is repetition of recent X
frames where X stands for amount of frames in one period. This problem is
barely visible or rather audible when the period is small like few
milliseconds because repetition of 1 [ms] of data is not-noticeable
however if we use buffer and period sizes in seconds then the problem
becomes apparent.

Example issue -> thesofproject/sof#3189

Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 12:58:20 +02:00
Jaroslav Kysela
651ca88a99 aplay: fix possible string overflow (coverity)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-09 10:27:40 +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
Michael Forney
f80a290153 Use __func__ instead of __FUNCTION__
They are equivalent, but __func__ is in C99. __FUNCTION__ exists only
for backwards compatibility with old gcc versions.

Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewd-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-02-10 12:38:28 +01:00
Rosen Penev
c9dc401264 aplay: Limit VUMeter progress bar to 100 for negative as well
While the progress bar cannot be negative, GCC concludes that it can be
and assumes tmp can be written past the end. Fixes this GCC warning:

aplay.c:1747:18: warning: '%02d' directive writing between 2 and 11 bytes
 into a region of size 4 [-Wformat-overflow=]
 1747 |    sprintf(tmp, "%02d%%", maxperc[c]);

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-20 22:01:26 +01:00
Rosen Penev
ac82b65167 aplay: Adjust buffer sizes to fix snprintf warnings
It also reduces compiled size slightly.

aplay.c: In function 'capture':
aplay.c:3055:34: error: '-01' directive output may be truncated writing 3
bytes into a region of size between 1 and 4097 [-Werror=format-truncation=
]
 3055 |    snprintf(namebuf, namelen, "%s-01", buf);
      |                                  ^~~
aplay.c:3055:4: note: 'snprintf' output between 4 and 4100 bytes into a
destination of size 4097
 3055 |    snprintf(namebuf, namelen, "%s-01", buf);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aplay.c:3053:34: error: '-01.' directive output may be truncated writing 4
bytes into a region of size between 1 and 4097 [-Werror=format-truncation=
]
 3053 |    snprintf(namebuf, namelen, "%s-01.%s", buf, s);
      |                                  ^~~~
aplay.c:3053:4: note: 'snprintf' output 5 or more bytes (assuming 4101)
into a destination of size 4097
 3053 |    snprintf(namebuf, namelen, "%s-01.%s", buf, s);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aplay.c:3065:34: error: '%02i' directive output may be truncated writing
between 2 and 10 bytes into a region of size between 0 and 4096 [-Werror=
format-truncation=]
 3065 |   snprintf(namebuf, namelen, "%s-%02i", buf, filecount);
      |                                  ^~~~
aplay.c:3065:30: note: directive argument in the range [1, 2147483647]
 3065 |   snprintf(namebuf, namelen, "%s-%02i", buf, filecount);
      |                              ^~~~~~~~~
aplay.c:3065:3: note: 'snprintf' output between 4 and 4108 bytes into a
destination of size 4097
 3065 |   snprintf(namebuf, namelen, "%s-%02i", buf, filecount);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aplay.c:3063:34: error: '%02i' directive output may be truncated writing
between 2 and 10 bytes into a region of size between 0 and 4096 [-Werror=
format-truncation=]
 3063 |   snprintf(namebuf, namelen, "%s-%02i.%s", buf, filecount, s);
      |                                  ^~~~
aplay.c:3063:30: note: directive argument in the range [1, 2147483647]
 3063 |   snprintf(namebuf, namelen, "%s-%02i.%s", buf, filecount, s);
      |                              ^~~~~~~~~~~~
aplay.c:3063:3: note: 'snprintf' output 5 or more bytes (assuming 4109)
into a destination of size 4097
 3063 |   snprintf(namebuf, namelen, "%s-%02i.%s", buf, filecount, s);

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-20 19:46:55 +01:00
Rosen Penev
80fd81f4a8 treewide: Fix printf formats
Found with cppcheck

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-20 19:46:17 +01:00
Rosen Penev
5e6df5ae4b treewide: sys/poll to poll
Fixes warning on musl:

warning redirecting incorrect #include <sys/poll.h> to <poll.h>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-20 19:44:02 +01:00
chunxu.li
d40e724905 aplay: fix memory leak when setup_chmap() fail
setup_chmap() will return with error number if hw_map calloc fail or
channels doesn't match with hw_params, but memory free was ignored when
error occurs.

Signed-off-by: chunxu.li <chunxuxiao@gmail.com>
Reviewed-by: Takashi Sakamoto o-takashi@sakamocchi.jp
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-09-25 09:57:19 +02:00
Jaroslav Kysela
9b6c5e2d5c aplay: check the return value for snd_pcm_sw_params_current() (coverity)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-03-13 14:46:33 +01:00
Jaroslav Kysela
bc42704c96 aplay: fix the multiple open file descriptors for the raw capture
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-03-12 17:36:11 +01:00
Jaroslav Kysela
fb97588025 aplay: add missing block brackets
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 17:00:26 +02:00
Takashi Iwai
da4d5bd53a aplay: Fix invalid file size check for non-regular files
aplay tries to check the file size via fstat() at parsing the format
headers and avoids parsing when the size is shorter than the given
size.  This works fine for regular files, but when a special file like
pipe is passed, it fails, eventually leading to the fallback mode
wrongly.

A proper fix is to do this sanity check only for a regular file.

Reported-by: Jay Foster <jay@systech.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-05-15 22:17:01 +02:00
erwin
588b3aa0ef aplay: Fix wav file not being split on 32 bit platforms
On my 32 bit armhf board arecord exits because of write() returning EFBIG
when the output file size reaches 2147483647 bytes.

To fix this, include generated header file before system header files
so that _FILE_OFFSET_BITS=64 is used properly, as required in documentation
"man feature_test_macros".

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-03-13 22:07:08 +01:00
Jussi Laako
d0802f32ca aplay: Adjust sample rate limits to support newer hardware
There are number of devices that support up to 384 kHz sampling rate and
some devices up to 768 kHz sampling rate. This patch increases sanity
check limit to 768k in order to support testing of such hardware.

Signed-off-by: Jussi Laako <jussi@sonarnerd.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-12-07 13:44:20 +01:00
Jaroslav Kysela
b1e3d945b7 Change FSF address (Franklin Street)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2017-11-14 14:28:53 +01:00
Daniel Baluta
1c9adf46b8 aplay: Fix playback for small raw files
This fixes a bug when trying to play files with size
smaller than maximum supported header size.

Lets have a look at the following example:

$ aplay -s 2 sample.raw

-> playback_go(fd = 10, loaded = 26, count = 2, name="sample.raw")
--> l = loaded = 26
--> c = count - written = 2
--> c -= l = 2 - 26 = -24
---> r = safe_read(fd, audiobuf + 26, -24)
---> r = -1, EXIT_FAILURE

In this case we have already 'loaded' from the input file more
bytes that we need to send to pcm device. So, we need to adjust
the number of bytes loaded and avoid reading a negative number
of bytes.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-08-09 10:39:36 +02:00
Daniel Baluta
dba6db9228 aplay: Refactor playback code
This introduces read_header function which tries
to read the header of an audio file in order to determine
its type.

This has the following effects:
	(1) makes code easier to read
	(2) don't abort if file size is less than expected header

(2), allows us to play small files with size smaller than any
supported audio file headers.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-08-09 10:38:41 +02:00
Ion-Horia Petrisor
3d44e2bc15 aplay: Add samples argument for playing/recording a given number of samples
-s --samples allows aplay to be used for playback/capture a given
number of samples per channel

Signed-off-by: Ion-Horia Petrisor <ion-horia.petrisor@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-08-09 10:38:19 +02:00
Srikanth Krishnakar
16557c2c7f aplay: interrupt streaming via signal in voc_pcm_write
aplay/arecord (alsa-utils v1.1.2) cannot interrupt streaming
via CTRL-C. Fixed the issue by properly handling 'in_aborting'
flag in appropriate functions.

Signed-off-by: Anant Agrawal <Anant_Agrawal@mentor.com>
Signed-off-by: Mikhail Durnev <mikhail_durnev@mentor.com>
Signed-off-by: Srikanth Krishnakar <Srikanth_Krishnakar@mentor.com>
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-07-10 15:27:22 +02:00
Scott Gilliland
a28ff22df8 aplay: Fix --max-file-time option 32 bits overflow
Fix bug in arecord --max-file-time where the file size could overflow
32 bits.

Signed-off-by: Scott Gilliland <scott.gilliland@gatech.edu>
Acked-by: John Sauter <John_Sauter@systemeyescomputerstore.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-06-26 17:05:38 +02:00
Daniel Baluta
1d34e6addc aplay: Introduce and use xwrite helper
Write can return less then requested bytes, but we treat this as
an error thus ending up with confusing error messages.

Fix this by introducing xwrite helper, which makes sure all bytes
are written or an error is returned.

With this patch an usecase where disk is filled by recording will
print:
$ /mnt/msc/audio.wav: No space left on device

instead of random messages like:

$/mnt/msc/audio.wav: No such file or directory

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-04-10 09:11:28 +02:00
Jeeja KP
d24a60b781 aplay: Fix to handle pause when system is suspended/Resumed
If PCM is paused and then we do system supend-resume, the stream throws
error(EBADF) when stream is paused released.

Check the pcm state before pause/release and if stream is suspended,
call snd_pcm_resume to resume the stream.

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Jeeja KP <jeeja.kp@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-11-28 20:19:21 +01:00
David Fries
85827fbb64 aplay: fix lurking capture file overwrite bug
If -d was given to arecord while commit
8aa13eec80 (now reverted) was in effect,
the last read would be shorter than the chunk size, but pcm_read would
read and return the chunk size, the samples were discarded, and
capture() continued in a loop because count never reached 0.  arecord
opens a new file each loop iteration, if arecord is dynamically naming
files, --use-strftime option or beyond the wave 2GB limit, this will
generate a series of header only wave files.  If the file is unique
the originally recorded data is lost and it will continue overwriting
the same file with a header only wave file.

While the current pcm_read can't fail (it can exit), it is better to
just fix this lurking bug in case it is "fixed" again.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-04-14 14:35:42 +02:00
erwin
b5c0660230 aplay/arecord: handle parsing errors of parameter values
when a user enters a command, he expects his command to be executed
as specified or aborted if it is impossible to fulfill his request

right now a command like "arecord -d hw:1,0 --max-file-time 1h recording.wav"
will happily record something and exit without error status while the resulting
recording contains definitely not what the user requested

to fix this, the patch handles the number parsing function's error channel
and checks whether the parsed number has any trailing characters

Signed-off-by: erwin <nebelbank@posteo.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-11 16:47:17 +01:00
Ricard Wanderlof
cd1bb5f4a7 aplay: fix VU meter for S24_LE etc formats
When recording or playing back audio in a format where the number of
significant bits is less than the physical width (e.g. S24_LE), the VU
meter code needs to consider the number of significant bits in the samples
rather than the physical sample width (e.g. 24 vs 32 bits). Otherwise the
resulting VU meter display will be far too low and it will just indicate
0% all the time.

Tested with a device supporting the S24_LE format.

Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-23 16:28:33 +02:00
Alexander Volkov
5f0fc49a3a arecord: Remove only regular files
arecord removes a file before writing into it. It's not
appropriate in some cases. For example, if you a pass
a symlink to a file, then the symlink will be removed
while the user expects to record into the symlink's target.
Another case is recording into the device file. Some
modems provide a tty device file as a voice device.
And it's not possible to write into it under root with
arecord, because it removes the device file.

So check the type of a file before writing into it and
remove only regular files.

Signed-off-by: Alexander Volkov <a.volkov@rusbitech.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-23 15:27:40 +02:00
Takashi Iwai
46b6082756 aplay: Fix uninterruptible aplay
When aplay is invoked to play from stdin, it can't be terminated by
normal signals like SIGTERM or SIGINT.  It's because our signal
handler tries to trap as much as possible while the stalling point is
not in the PCM loop but rather the file I/O.

For fixing this, leave our signal handler once when a signal is
received and snd_pcm_abort() is called.  At the next hit, it shall be
handled normally.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-29 18:01:58 +02:00
Takashi Iwai
9aa5c271f4 aplay: Fix type for signal flag
A flag used in signal handlers has to be a special atomic type,
volatile sig_atomic_t.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-29 18:01:07 +02:00
Jaroslav Kysela
8f361d83cf Revert "aplay: fix pcm_read() return value"
This reverts commit 8aa13eec80.

The semantics for pcm_read() and pcm_readv() was changed, but the
callers expect the exact frame count as requested. It's possible
to fix callers, but the fix is more complicated than to revert the
change. Note that '-d' processing was broken in some cases.

Note: The reverted commit allows that the return value might be
greater than requested (see the first condition in read routines).
2014-10-01 15:43:57 +02:00
Sergey
a9705ca48f aplay: Fix VU-meter stdout/stderr mess
Commit 6bbeb78d forgot to change some of VU-meter output to stderr.
This patch makes the output of `aplay -vvv` consistent again.

Signed-off-by: Sergey <sergemp@mail.ru>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2014-06-13 18:39:11 +02:00
Jaroslav Kysela
c06dbf0774 aplay/arecord: Add more in_aborting checks to read/write loops
Reported-by: Sergey <sergemp@mail.ru>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2014-06-13 10:52:26 +02:00
Olivier Langlois
360878f9c3 aplay: fix timespec to msec conversion
There is 1M nsec in a msec.

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-01-22 08:05:17 +01:00
Olivier Langlois
8aa13eec80 aplay: fix pcm_read() return value
Because of the way the pcm_read() functions are currently used, returning
rcount or result is equivalent but I feel it is more accurate to
return 'result'.

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-01-08 11:56:52 +01:00
Jurgen Kramer
719faff809 aplay: fix two off by one errors
Attached patch for aplay fixes two off-by-one errors preventing usage
of the last available sample format.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-09-09 12:02:29 +02:00
Elimar Riesebieter
48554fc28b Fix several typos in manpage and help strings.
Signed-off-by: Jordi Mallach <jordi@debian.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-05-16 10:38:02 +02:00
Jaroslav Kysela
b4f34ac260 arecord: add a missing break to the capture loop
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2013-04-17 08:34:34 +02:00
Jaroslav Kysela
1d0042d7e9 aplay/arecord: change the interrupt handling using snd_pcm_abort()
It is required (exclude the fatal SIGABRT) to call snd_pcm_close() and
the end of work (outside of the interrupt handler). Use new snd_pcm_abort()
function to inform alsa-lib to not ignore EINTR and move the in_aborting
variable to the global scope to be checked in the i/o loops.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2013-04-08 13:30:54 +02:00
Jaroslav Kysela
6de3c709b3 aplay/arecord: added isatty() check (interactive mode)
Turn off the interactive mode when stdin is not a tty.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2013-03-22 14:00:44 +01:00
Takashi Iwai
de61ec66fe aplay: Add the support for big-endian WAV format (RIFX)
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-12-13 10:53:19 +01:00
Fabio Estevam
c6614dbdab aplay: Show usage if no parameter is passed
When aplay/arecord are called without any argument the application hangs forever.

Instead of hanging, print the usage and exit.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-13 14:33:40 +01:00