]> git.alsa-project.org Git - tinycompress.git/commitdiff
cplay: Add suport for PCM audio codec
authorDaniel Baluta <daniel.baluta@nxp.com>
Thu, 7 Jan 2021 21:01:06 +0000 (23:01 +0200)
committerDaniel Baluta <daniel.baluta@nxp.com>
Tue, 2 Feb 2021 15:44:28 +0000 (17:44 +0200)
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>
configure.ac
src/utils/Makefile.am
src/utils/cplay.c

index b6b44ed77c8ca163d1fb6287132c4c5eac8ead44..346f63d7d16a864663504d258517762c81ff355d 100644 (file)
@@ -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
index b8b6c116ea5d0399f372f1c6686fb3ce2cd22a89..379247f838d405d4c20d0c3a16a8b908b6cd15df 100644 (file)
@@ -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
index 3e9fcac4d424a4d79fdc24cda17774465943cf31..1a3bea7dd1968369ee84ddbe4d86b6aac520f91b 100644 (file)
 #include <stdbool.h>
 #include <getopt.h>
 #include <sys/time.h>
+#include <config.h>
 #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;