From: Bert Vermeulen Date: Tue, 26 Aug 2014 20:48:12 +0000 (+0200) Subject: input/wav: use our own endian macros. X-Git-Tag: libsigrok-0.4.0~1092 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=962d43440a95f67d365f7e8174b2af89c34bae9a;p=libsigrok.git input/wav: use our own endian macros. These should work better on non-aligned memory locations. --- diff --git a/src/input/wav.c b/src/input/wav.c index fabe92c7..05b43ba4 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "libsigrok.h" #include "libsigrok-internal.h" @@ -58,10 +59,10 @@ static int parse_wav_header(GString *buf, struct context *inc) return SR_ERR; } - fmt_code = GUINT16_FROM_LE(*(uint16_t *)(buf->str + 20)); - samplerate = GUINT32_FROM_LE(*(uint32_t *)(buf->str + 24)); - samplesize = GUINT16_FROM_LE(*(uint16_t *)(buf->str + 32)); - num_channels = GUINT16_FROM_LE(*(uint16_t *)(buf->str + 22)); + fmt_code = RL16(buf->str + 20); + samplerate = RL32(buf->str + 24); + samplesize = RL16(buf->str + 32); + num_channels = RL16(buf->str + 22); /* TODO div0 */ unitsize = samplesize / num_channels; @@ -139,7 +140,7 @@ static int find_data_chunk(GString *buf, int initial_offset) return -1; } /* Skip past this chunk. */ - offset += 8 + GUINT32_FROM_LE(*(uint32_t *)(buf->str + offset + 4)); + offset += 8 + RL32(buf->str + offset + 4); } return offset; @@ -204,13 +205,13 @@ static void send_chunk(const struct sr_input *in, int offset, int num_samples) switch (inc->samplesize) { case 1: /* 8-bit PCM samples are unsigned. */ - fdata[samplenum] = (uint8_t)sample / 255.0; + fdata[samplenum] = (uint8_t)sample / (float)255; break; case 2: - fdata[samplenum] = GINT16_FROM_LE(sample) / 32767.0; + fdata[samplenum] = RL16S(&sample) / (float)INT16_MAX; break; case 4: - fdata[samplenum] = GINT32_FROM_LE(sample) / 65535.0; + fdata[samplenum] = RL32S(&sample) / (float)INT32_MAX; break; } } else { @@ -258,7 +259,7 @@ static int receive(const struct sr_input *in, GString *buf) if (!inc->found_data) { /* Skip past size of 'fmt ' chunk. */ - i = 20 + GUINT32_FROM_LE(*(uint32_t *)(in->buf->str + 16)); + i = 20 + RL32(in->buf->str + 16); offset = find_data_chunk(in->buf, i); if (offset < 0) { if (in->buf->len > MAX_DATA_CHUNK_OFFSET) {