Vinod Koul [Thu, 13 Oct 2022 12:45:54 +0000 (18:15 +0530)]
cplay: add parentheses around comparison in operand of ‘&’
We get a warning:
cplay.c: In function ‘find_adts_header’:
cplay.c:259:41: warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]
259 | if ((buf[0] != 0xff) || (buf[1] & 0xf0 != 0xf0))
Vinod Koul [Thu, 13 Oct 2022 12:19:57 +0000 (17:49 +0530)]
cplay: remove set but not used warnings
cplay.c: In function ‘find_adif_header’:
cplay.c:367:13: warning: variable ‘object_type’ set but not used [-Wunused-but-set-variable]
367 | int object_type;
| ^~~~~~~~~~~
cplay.c:366:13: warning: variable ‘bitrate’ set but not used [-Wunused-but-set-variable]
366 | int bitrate;
| ^~~~~~~
cplay.c:91:27: warning: ‘DEFAULT_CODEC_ID’ defined but not used [-Wunused-const-variable=]
91 | static const unsigned int DEFAULT_CODEC_ID = SND_AUDIOCODEC_PCM;
| ^~~~~~~~~~~~~~~~
While at it, cleanup the code a bit as well removing now redundant
braces around if-else
This patch will allow playing MP3 files containing ID3v2
tag at the beginning of the file.
This is done simply by parsing the ID3v2 header, extracting
the header size and seeking to that position (+10 bytes
from the header size which is not included in the 'header
size' field of the ID3v2 header)
We want to be able to pause and resume the stream
just like the ALSA utilitary aplay does.
In order to do so, we first need to mark the read operations
on stdin as nonblocking and then enable the noncanonical mode
for the terminal. What this does is it makes the read operations
nonblocking and it makes the input available immediately.
After doing so, we can check if we receive a SPACE or ENTER
character from user and do pause/resume depending on current
stream state (and by this I mean if the stream is currently
paused and we receive a SPACE or ENTER then we resume it
and vice-versa)
utils: cplay: Reset file cursor after MP3 header parse
We need to reset the file cursor to the beginning of the file.
Initially, the program would simply get stuck polling the
compress fd. This was probably because of the fact that the
codec would hang because of the fact that it was expecting
to receive the MP3 data along with its associated MP3 header.
This was not the case for the first (header, data) pair because,
after parsing the first header, the file cursor would point
at the beginning of the data region.
By resetting the file cursor to the beginning of the file,
the codec will receive all the (header, data) pairs it
actually expects.
Suggested-by: Shengjiu Wang <shengjiu.wang@nxp.com> Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
Daniel Baluta [Thu, 7 Jan 2021 21:01:06 +0000 (23:01 +0200)]
cplay: Add suport for PCM audio codec
Make use of newly added parse_wave_header function in order
to discover PCM codec properties.
PCM with tinycompress interface is very useful for testing
new compress API implementations and can be enabled using
--enable-pcm option at configuration time.
e.g:
- ./gitcompile --enable-pcm
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Daniel Baluta [Thu, 7 Jan 2021 20:57:14 +0000 (22:57 +0200)]
wave: Introduce parse_wave header
This parses a canonical WAVE header and fills in
informationlike channels, rate and format.
In tinycompress, we use canonical WAVE format described here:
http://soundfile.sapp.org/doc/WaveFormat/
A WAVE file is often just a RIFF file with a single "WAVE" chunk which
consists of two sub-chunks -- a "fmt " chunk specifying the data format
and a "data" chunk containing the actual sample data.
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Add compress_open_by_name() and is_codec_supported_by_name()
to support plugins. Format of name is 'hw:<card>,<device>'
for hw compress nodes and '<plugin_name>:<custom_data>'
for virtual compress nodes. It dynamically loads the plugin
library whose name is libtinycompress_module_<plugin_name>.so.
Plugin library needs to expose compress_plugin_ops.
Default path of plugin lib is /usr/lib/tinycompress-lib/ and it
can be updated by defining TINYCOMPRESS_PLUGIN_DIR in makefile.
Vinod Koul [Thu, 5 Dec 2019 07:57:28 +0000 (13:27 +0530)]
fcplay: initial addition
This tool was forked from tinycompress cplay. The fork was required due
to this linking against libavcodec which is GPL. This uses libav APIs to
parse the compressed files and send the audio stream to compressed
device using tinycompress APIs
Right now it supports only playback on MP3 (no problems now not finding
sync word) and flac files.
Charles Keepax [Thu, 8 Nov 2018 17:12:32 +0000 (17:12 +0000)]
tinycompress: Update headers to include AUDIOCODEC_BESPOKE
commit dbb6b94339e8 ("ALSA: compress: Add SND_AUDIOCODEC_BESPOKE") added
an additional CODEC type for bespoke CODECs. Update the local headers to
include this.
Reported-by: Andrew Ford <andrew.ford@cirrus.com> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
We get a warning in crecord for incorrect print specifier, fix it by using
right one %u for unsigned int
crecord.c:380:17: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Wformat=]
fprintf(finfo, "Recording file %s On Card %u device %u, with buffer of %lu bytes\n",
We get a warning in cplay for incorrect print specifier, fix it by using
right one %ld for long unsigned int.
cplay.c:327:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
fprintf(stderr, "codec ID %d is not supported\n", codec_id);
Charles Keepax [Fri, 13 Apr 2018 11:58:59 +0000 (12:58 +0100)]
crecord: Use whole buffer requested by user
Currently, crecord will only actually use 1 fragment worth of its
internal buffer no matter what the user requests. Correct this so that
the whole buffer requested by the user is used for copying data.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Katsuhiro Suzuki [Tue, 23 Jan 2018 02:33:11 +0000 (11:33 +0900)]
cplay: fix size and nmemb of mp3 header of fread
This patch swaps 'size' and 'nmemb' arguments of fread.
The fread returns always 1 (because 'nmemb' is 1) so checking
the return value is always failure.
This patch adds a -I command line option to set the codec ID,
either from a defined set of string values or as a number.
After discussion with Vinod it was agreed that we should only
allow writing to a file if we support creating the correct container
file format for that data. As we currently only have support for
creating WAV files only PCM data can be written to a file. Other
formats can be sent raw to stdout.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
- Incorrect indenting of arguments to capture_samples()
- Wrap long line in capture_samples()
- Added a blank line in main() for readability
- Deleted extra trailing blank line at end of file
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Sat, 9 Jan 2016 08:12:46 +0000 (13:42 +0530)]
tinycompress: crec: make functions static
Sparse rightly complains some functions should be static so make them static
crec.c:113:26: warning: symbol 'blank_wave_header' was not declared. Should it be static?
crec.c:239:6: warning: symbol 'capture_samples' was not declared. Should it be static?
Vinod Koul [Sat, 9 Jan 2016 08:12:46 +0000 (13:42 +0530)]
tinycompress: cplay: make functions static
Sparse rightly complains some functions should be static so make them static
cplay.c:100:5: warning: symbol 'parse_mp3_header' was not declared. Should it be static?
cplay.c:129:5: warning: symbol 'check_codec_format_supported' was not declared. Should it be static?
../../include/tinycompress/tinymp3.h:66:11: warning: symbol 'mp3_sample_rates' was not declared. Should it be static?
../../include/tinycompress/tinymp3.h:72:11: warning: symbol 'mp3_bit_rates' was not declared. Should it be static?
crec: Always read whole number of fragments when length limit specified
This patch removes the lines that adjusted the read size to exactly
read to the end of the calculated length in bytes. Doing this could
lead to invalid fragment sizes being requested which may then cause
a read error on some codecs.
Instead we keep reading whole fragments until we have >= length bytes
of data captured.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Fri, 8 May 2015 10:30:02 +0000 (16:00 +0530)]
cplay: check the values of fread
This fixes the following warning:
cplay.c: In function ‘play_samples’:
cplay.c:219:7: warning: ignoring return value of ‘fread’, declared with
attribute warn_unused_result [-Wunused-result]
fread(&header, sizeof(header), 1, file);
Qais Yousef [Tue, 5 May 2015 10:21:11 +0000 (11:21 +0100)]
tinycompress.h: explicitly include required headers
tinycompress.h was relying on other files to include linux/types.h and stdbool.h
which are required by it. Explicitly include it to fix compile errors when external
program tries to include this header.
The code was not compiling when mode was not passed to open()
while using O_CREAT offset. Passed mode to the open() alongwith
O_CREAT to specify the attributes of file and fix compile issue.
Signed-off-by: Ammar Zahid Ali Syed <ammar.zhd@googlemail.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Thu, 19 Jun 2014 09:33:17 +0000 (15:03 +0530)]
tinycompress: update headers for packed, aligned
commit "6b24a8dd: ALSA: compress: fix the struct alignment to 4 bytes" updated
compress struct to force packed and aligned to 4 bytes. Update here a s well
Vinod Koul [Thu, 19 Jun 2014 09:27:59 +0000 (14:57 +0530)]
tinycompress: update compress headers for sample rate field
commit "929559b: ALSA: compress: add num_sample_rates in snd_codec_desc" adds
array for passing sample rate instead of bit map. Update the local header as
well
compress: compress_wait() must return error if timed out
The caller must be certain that a return of 0 really means
that compress is ready for more data, so when poll() returns
0 for a timeout we must report that as an error.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress: Must check for POLLERR before POLLOUT/POLLIN
In the case of error the ALSA compressed driver sets revents as
(POLLOUT | POLLWRNORM | POLLERR) or (POLLIN | POLLWRNORM | POLLERR).
So we can't assume that POLLOUT or POLLIN indicate success, we must
check for POLLERR first.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Support for non-blocking I/O, based on API of main alsalib.
In non-blocking mode a compress_write() will return without
blocking after it has written all bytes that will fit in the
buffer and compress_read() will return after it has read all
bytes available from the buffer. Use compress_wait() to wait
for free write space or available read bytes.
Non-blocking mode is enabled and disabled using compress_nonblock().
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>