From: Daniel Baluta Date: Thu, 7 Jan 2021 21:01:06 +0000 (+0200) Subject: cplay: Add suport for PCM audio codec X-Git-Tag: v1.2.5~3^2 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=cf3256ae1295020bcbe320d517610dfa7c5c71b4;p=tinycompress.git 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 --- diff --git a/configure.ac b/configure.ac index b6b44ed..346f63d 100644 --- a/configure.ac +++ b/configure.ac @@ -12,13 +12,21 @@ LT_INIT(disable-static) AC_ARG_ENABLE(fcplay, AS_HELP_STRING([--enable-fcplay], [enable the fcplay component]), [build_fcplay="$enableval"], [build_fcplay="no"]) +AC_ARG_ENABLE(pcm, + AS_HELP_STRING([--enable-pcm], [enable PCM compress playback support(used for debugging)]), + [enable_pcm="$enableval"], [enable_pcm="no"]) AM_CONDITIONAL([BUILD_FCPLAY], [test x$build_fcplay = xyes]) +AM_CONDITIONAL([ENABLE_PCM], [test x$enable_pcm = xyes]) #if test "$build_fcplay" = "yes"; then # AC_DEFINE([BUILD_FCPLAY], "1", [Build Fcplay component]) #fi +if test "$enable_pcm" = "yes"; then + AC_DEFINE([ENABLE_PCM], 1, [Enable PCM compress playback support (used for debugging)]) +fi + # Checks for programs. AC_PROG_CXX AC_PROG_CC diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index b8b6c11..379247f 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -1,6 +1,6 @@ bin_PROGRAMS = cplay crecord -cplay_SOURCES = cplay.c +cplay_SOURCES = cplay.c wave.c crecord_SOURCES = crecord.c wave.c cplay_CFLAGS = -I$(top_srcdir)/include diff --git a/src/utils/cplay.c b/src/utils/cplay.c index 3e9fcac..1a3bea7 100644 --- a/src/utils/cplay.c +++ b/src/utils/cplay.c @@ -66,12 +66,14 @@ #include #include #include +#include #define __force #define __bitwise #define __user #include "sound/compress_params.h" #include "tinycompress/tinycompress.h" #include "tinycompress/tinymp3.h" +#include "tinycompress/tinywave.h" static int verbose; static const unsigned int DEFAULT_CODEC_ID = SND_AUDIOCODEC_PCM; @@ -245,6 +247,44 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } +#if ENABLE_PCM +void get_codec_pcm(FILE *file, struct compr_config *config, + struct snd_codec *codec) +{ + size_t read; + struct wave_header header; + unsigned int channels, rate, format; + + read = fread(&header, 1, sizeof(header), file); + if (read != sizeof(header)) { + fprintf(stderr, "Unable to read header \n"); + fclose(file); + exit(EXIT_FAILURE); + } + + if (parse_wave_header(&header, &channels, &rate, &format) == -1) { + fclose(file); + exit(EXIT_FAILURE); + } + + codec->id = SND_AUDIOCODEC_PCM; + codec->ch_in = channels; + codec->ch_out = channels; + codec->sample_rate = rate; + if (!codec->sample_rate) { + fprintf(stderr, "invalid sample rate %d\n", rate); + fclose(file); + exit(EXIT_FAILURE); + } + codec->bit_rate = 0; + codec->rate_control = 0; + codec->profile = SND_AUDIOCODEC_PCM; + codec->level = 0; + codec->ch_mode = 0; + codec->format = format; +} +#endif + void get_codec_mp3(FILE *file, struct compr_config *config, struct snd_codec *codec) { @@ -317,6 +357,11 @@ void play_samples(char *name, unsigned int card, unsigned int device, } switch (codec_id) { +#if ENABLE_PCM + case SND_AUDIOCODEC_PCM: + get_codec_pcm(file, &config, &codec); + break; +#endif case SND_AUDIOCODEC_MP3: get_codec_mp3(file, &config, &codec); break;