From: Antonio Ospite Date: Thu, 6 Jan 2011 12:16:38 +0000 (+0100) Subject: Add functions fwrite_le16() and fwrite_le32() X-Git-Url: https://git.ao2.it/wav_header.git/commitdiff_plain/HEAD?ds=inline;hp=6b53484d0c99f28083876e22d4c43e64e4c21052 Add functions fwrite_le16() and fwrite_le32() These make the code more readable and fix the following error from some compilers: error: lvalue required as unary '&' operand Signed-off-by: Antonio Ospite --- diff --git a/wav_header.c b/wav_header.c index 6cb5157..2a90ea7 100644 --- a/wav_header.c +++ b/wav_header.c @@ -79,6 +79,18 @@ struct extradata { }; +static inline void fwrite_le16(uint16_t x, FILE *file) +{ + uint16_t tmp = htole16(x); + fwrite(&tmp, sizeof(tmp), 1, file); +} + +static inline void fwrite_le32(uint32_t x, FILE *file) +{ + uint32_t tmp = htole32(x); + fwrite(&tmp, sizeof(tmp), 1, file); +} + void write_wav_header(FILE *file, struct fmt *format, struct extradata *extradata, unsigned data_len) { @@ -104,27 +116,27 @@ void write_wav_header(FILE *file, struct fmt *format, /* RIFF */ fwrite(&r.riffheader, 1, 4, file); - fwrite(&htole32(r.WAVElen), 4, 1, file); + fwrite_le32(r.WAVElen, file); /* WAVE */ fwrite(&w.fmtheader, 1, 8, file); - fwrite(&htole32(w.fmtlen), 4, 1, file); + fwrite_le32(w.fmtlen, file); /* fmt */ - fwrite(&htole16(format->wFormatTag), 2, 1, file); - fwrite(&htole16(format->nChannels), 2, 1, file); - fwrite(&htole32(format->nSamplesPerSec), 4, 1, file); - fwrite(&htole32(format->nAvgBytesPerSec), 4, 1, file); - fwrite(&htole16(format->nBlockAlign), 2, 1, file); - fwrite(&htole16(format->wBitsPerSample), 2, 1, file); - fwrite(&htole16(format->cbSize), 2, 1, file); + fwrite_le16(format->wFormatTag, file); + fwrite_le16(format->nChannels, file); + fwrite_le32(format->nSamplesPerSec, file); + fwrite_le32(format->nAvgBytesPerSec, file); + fwrite_le16(format->nBlockAlign, file); + fwrite_le16(format->wBitsPerSample, file); + fwrite_le16(format->cbSize, file); /* extradata */ fwrite(extradata->data, 1, extradata->len, file); /* data */ fwrite(&d.dataheader, 1, 4, file); - fwrite(&htole32(d.datalen), 4, 1, file); + fwrite_le32(d.datalen, file); } int main(void)