changeset 11:a3aa152c4653

libtest: pcmwrite helper function and module
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 20 Nov 2022 00:31:42 +0000
parents 820d88b97924
children f88817a233fb
files libtest/Makefile libtest/pcmwrite.c libtest/pcmwrite.h
diffstat 3 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libtest/Makefile	Sat Nov 19 23:57:42 2022 +0000
+++ b/libtest/Makefile	Sun Nov 20 00:31:42 2022 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	binreader.o wavreader.o wavwriter.o
+OBJS=	binreader.o pcmwrite.o wavreader.o wavwriter.o
 LIB=	libtest.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtest/pcmwrite.c	Sun Nov 20 00:31:42 2022 +0000
@@ -0,0 +1,22 @@
+/*
+ * Here we implement our PCM write helper function.
+ */
+
+#include <stdint.h>
+#include "wavwriter.h"
+#include "pcmwrite.h"
+
+void write_pcm_to_wav(void *wav, const int16_t *pcm)
+{
+	uint8_t bytes[320], *dp;
+	int16_t samp;
+	unsigned n;
+
+	dp = bytes;
+	for (n = 0; n < 160; n++) {
+		samp = pcm[n];
+		*dp++ = samp & 0xFF;
+		*dp++ = (samp >> 8) & 0xFF;
+	}
+	wav_write_data(wav, bytes, 320);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtest/pcmwrite.h	Sun Nov 20 00:31:42 2022 +0000
@@ -0,0 +1,6 @@
+/*
+ * This header file declares the interface to our helper function
+ * for writing 16-bit linear PCM samples to WAV output file.
+ */
+
+extern void write_pcm_to_wav(void *wav, const int16_t *pcm);