From: Daniel Baluta Date: Thu, 7 Jan 2021 18:36:22 +0000 (+0200) Subject: wave: Separate wave functions to wave file X-Git-Tag: v1.2.5~3^2~2 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=d6aa3e9b193865069d309815bbecde4a0ddc12bc;p=tinycompress.git wave: Separate wave functions to wave file 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 --- diff --git a/include/tinycompress/tinywave.h b/include/tinycompress/tinywave.h index c7e98aa..ac128e5 100644 --- a/include/tinycompress/tinywave.h +++ b/include/tinycompress/tinywave.h @@ -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 diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 1b996d4..b8b6c11 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -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 diff --git a/src/utils/crecord.c b/src/utils/crecord.c index 41a90e0..0121e0a 100644 --- a/src/utils/crecord.c +++ b/src/utils/crecord.c @@ -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 index 0000000..23691fc --- /dev/null +++ b/src/utils/wave.c @@ -0,0 +1,52 @@ +//SPDX-License-Identifier: (LGPL-2.1-only OR BSD-3-Clause) + +// +// WAVE helper functions +// +// Copyright 2021 NXP + +#include +#include + +#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; +}