summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dabplus-enc-alsa-zmq.cpp17
-rw-r--r--src/utils.c1
-rw-r--r--src/utils.h31
3 files changed, 46 insertions, 3 deletions
diff --git a/src/dabplus-enc-alsa-zmq.cpp b/src/dabplus-enc-alsa-zmq.cpp
index caadfc9..699a256 100644
--- a/src/dabplus-enc-alsa-zmq.cpp
+++ b/src/dabplus-enc-alsa-zmq.cpp
@@ -399,7 +399,10 @@ int main(int argc, char *argv[])
}
int outbuf_size = subchannel_index*120;
- uint8_t outbuf[20480];
+ uint8_t zmqframebuf[2048];
+ zmq_frame_header_t *zmq_frame_header = (zmq_frame_header_t*)zmqframebuf;
+
+ uint8_t outbuf[2048];
if(outbuf_size % 5 != 0) {
fprintf(stderr, "(outbuf_size mod 5) = %d\n", outbuf_size % 5);
@@ -585,7 +588,17 @@ int main(int argc, char *argv[])
// ------------ ZeroMQ transmit
try {
- zmq_sock.send(outbuf, outbuf_size, ZMQ_DONTWAIT);
+ zmq_frame_header->version = 1;
+ zmq_frame_header->encoder = ZMQ_ENCODER_FDK;
+ zmq_frame_header->datasize = outbuf_size;
+ zmq_frame_header->audiolevel_left = peak_left;
+ zmq_frame_header->audiolevel_right = peak_right;
+
+ memcpy(ZMQ_FRAME_DATA(zmq_frame_header),
+ outbuf, outbuf_size);
+
+ zmq_sock.send(zmqframebuf, ZMQ_FRAME_SIZE(zmq_frame_header),
+ ZMQ_DONTWAIT);
}
catch (zmq::error_t& e) {
fprintf(stderr, "ZeroMQ send error !\n");
diff --git a/src/utils.c b/src/utils.c
index 3b0bee4..a9aefbe 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,6 +1,7 @@
#include "utils.h"
#include <unistd.h>
#include <stdint.h>
+#include <math.h>
/* Taken from sox */
const char* level(int channel, int* peak)
diff --git a/src/utils.h b/src/utils.h
index c7ddc1e..aa8dc8a 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -2,6 +2,7 @@
#define UTILS_H_
#include <math.h>
+#include <stdint.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
@@ -10,8 +11,36 @@
#define linear_to_dB(x) (log10(x) * 20)
-
+/* Calculate the little string containing a bargraph
+ * 'VU-meter' from the peak value measured
+ */
const char* level(int channel, int* peak);
+/* This defines the on-wire representation of a ZMQ message header.
+ *
+ * The data follows right after this header */
+struct zmq_frame_header_t
+{
+ uint16_t version; // we support version=1 now
+ uint16_t encoder; // see ZMQ_ENCODER_XYZ
+
+ /* length of the 'data' field */
+ uint32_t datasize;
+
+ /* Audio level, peak, linear PCM */
+ int16_t audiolevel_left;
+ int16_t audiolevel_right;
+
+ /* Data follows this header */
+} __attribute__ ((packed));
+
+#define ZMQ_ENCODER_FDK 1
+
+/* The expected frame size incl data of the given frame */
+#define ZMQ_FRAME_SIZE(f) (sizeof(zmq_frame_header_t) + f->datasize)
+
+#define ZMQ_FRAME_DATA(f) ( ((uint8_t*)f)+sizeof(zmq_frame_header_t) )
+
+
#endif