]> git.alsa-project.org Git - tinycompress.git/commitdiff
wave: Separate wave functions to wave file
authorDaniel Baluta <daniel.baluta@nxp.com>
Thu, 7 Jan 2021 18:36:22 +0000 (20:36 +0200)
committerDaniel Baluta <daniel.baluta@nxp.com>
Thu, 21 Jan 2021 15:42:30 +0000 (17:42 +0200)
Move all related wave functions from crecord to their own wave.c
file.

This helps organizing the code so that both cplay/crecord can
use wave functions.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
include/tinycompress/tinywave.h
src/utils/Makefile.am
src/utils/crecord.c
src/utils/wave.c [new file with mode: 0644]

index c7e98aab5cde90b90806ec61a286b784e6e9aebd..ac128e598dc80b30b6b1c96314dec68b7a83390c 100644 (file)
@@ -34,4 +34,8 @@ struct wave_header {
        } __attribute__((__packed__)) data;
 } __attribute__((__packed__));
 
+void init_wave_header(struct wave_header *header, uint16_t channels,
+                     uint32_t rate, uint16_t samplebits);
+void size_wave_header(struct wave_header *header, uint32_t size);
+
 #endif
index 1b996d430f21ca5764df2abfb983051c8c32c2c7..b8b6c116ea5d0399f372f1c6686fb3ce2cd22a89 100644 (file)
@@ -1,7 +1,7 @@
 bin_PROGRAMS = cplay crecord
 
 cplay_SOURCES = cplay.c
-crecord_SOURCES = crecord.c
+crecord_SOURCES = crecord.c wave.c
 
 cplay_CFLAGS = -I$(top_srcdir)/include
 crecord_CFLAGS = -I$(top_srcdir)/include
index 41a90e08832d0ed9a73bdb12f7361a4a7372bd9a..0121e0abfbdb73aad3aad6a20f5625eb674f9847 100644 (file)
@@ -113,47 +113,6 @@ static const struct {
 };
 #define CREC_NUM_CODEC_IDS (sizeof(codec_ids) / sizeof(codec_ids[0]))
 
-static const struct wave_header blank_wave_header = {
-       .riff = {
-               .chunk = {
-                       .desc = "RIFF",
-               },
-               .format = "WAVE",
-       },
-       .fmt = {
-               .chunk = {
-                       .desc = "fmt ", /* Note the space is important here */
-                       .size = sizeof(blank_wave_header.fmt) -
-                               sizeof(blank_wave_header.fmt.chunk),
-               },
-               .type = 0x01,   /* PCM */
-       },
-       .data = {
-               .chunk = {
-                       .desc = "data",
-               },
-       },
-};
-
-static void init_wave_header(struct wave_header *header, uint16_t channels,
-                            uint32_t rate, uint16_t samplebits)
-{
-       memcpy(header, &blank_wave_header, sizeof(blank_wave_header));
-
-       header->fmt.channels = channels;
-       header->fmt.rate = rate;
-       header->fmt.byterate = channels * rate * (samplebits / 8);
-       header->fmt.blockalign = channels * (samplebits / 8);
-       header->fmt.samplebits = samplebits;
-}
-
-static void size_wave_header(struct wave_header *header, uint32_t size)
-{
-       header->riff.chunk.size = sizeof(*header) -
-                                 sizeof(header->riff.chunk) + size;
-       header->data.chunk.size = size;
-}
-
 static const char *codec_name_from_id(unsigned int id)
 {
        static char hexname[12];
diff --git a/src/utils/wave.c b/src/utils/wave.c
new file mode 100644 (file)
index 0000000..23691fc
--- /dev/null
@@ -0,0 +1,52 @@
+//SPDX-License-Identifier: (LGPL-2.1-only OR BSD-3-Clause)
+
+//
+// WAVE helper functions
+//
+// Copyright 2021 NXP
+
+#include <stdint.h>
+#include <string.h>
+
+#include "tinycompress/tinywave.h"
+
+static const struct wave_header blank_wave_header = {
+       .riff = {
+               .chunk = {
+                       .desc = "RIFF",
+               },
+               .format = "WAVE",
+       },
+       .fmt = {
+               .chunk = {
+                       .desc = "fmt ", /* Note the space is important here */
+                       .size = sizeof(blank_wave_header.fmt) -
+                               sizeof(blank_wave_header.fmt.chunk),
+               },
+               .type = 0x01,   /* PCM */
+       },
+       .data = {
+               .chunk = {
+                       .desc = "data",
+               },
+       },
+};
+
+void init_wave_header(struct wave_header *header, uint16_t channels,
+                     uint32_t rate, uint16_t samplebits)
+{
+       memcpy(header, &blank_wave_header, sizeof(blank_wave_header));
+
+       header->fmt.channels = channels;
+       header->fmt.rate = rate;
+       header->fmt.byterate = channels * rate * (samplebits / 8);
+       header->fmt.blockalign = channels * (samplebits / 8);
+       header->fmt.samplebits = samplebits;
+}
+
+void size_wave_header(struct wave_header *header, uint32_t size)
+{
+       header->riff.chunk.size = sizeof(*header) -
+                                 sizeof(header->riff.chunk) + size;
+       header->data.chunk.size = size;
+}