src/*.c: New format specifiers for psf_binheader_writef 31/162531/1 tizen_4.0_tv accepted/tizen/4.0/unified/20171219.072304 submit/tizen_4.0/20171218.045843 tizen_4.0.IoT.p2_release
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sun, 16 Jul 2017 01:58:17 +0000 (11:58 +1000)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 30 Nov 2017 06:11:06 +0000 (15:11 +0900)
There was a long standing problem where the compiler was not able to
check format speficiers for `psf_binheader_writef`. This is a standard
problem with using non-standard format specifiers with stdargs.

This solution wraps all non-format parameters pass to that functions
with a macro which performs an explicit type cast. The second step is
to have a Python program make sure these macro wrappers match the
format specifiers.

Change-Id: I8bc65d9671c98d11f87e07979372877f4e9ff048
Closes: https://github.com/erikd/libsndfile/issues/241

24 files changed:
src/aiff.c
src/au.c
src/avr.c
src/caf.c
src/common.h
src/htk.c
src/ircam.c
src/mat4.c
src/mat5.c
src/mpc2k.c
src/ms_adpcm.c
src/nist.c
src/paf.c
src/rf64.c
src/sd2.c
src/sds.c
src/svx.c
src/test_binheader_writef.c
src/voc.c
src/w64.c
src/wav.c
src/wavlike.c
src/wve.c
src/xi.c

index faf2e11..5107afc 100644 (file)
@@ -1157,30 +1157,30 @@ aiff_rewrite_header (SF_PRIVATE *psf)
        psf->header.indx = 0 ;
 
        /* FORM chunk. */
-       psf_binheader_writef (psf, "Etm8", FORM_MARKER, psf->filelength - 8) ;
+       psf_binheader_writef (psf, "Etm8", BHWm (FORM_MARKER), BHW8 (psf->filelength - 8)) ;
 
        /* COMM chunk. */
        if ((k = psf_find_read_chunk_m32 (&psf->rchunks, COMM_MARKER)) >= 0)
        {       psf->header.indx = psf->rchunks.chunks [k].offset - 8 ;
                comm_frames = psf->sf.frames ;
                comm_size = psf->rchunks.chunks [k].len ;
-               psf_binheader_writef (psf, "Em42t4", COMM_MARKER, comm_size, psf->sf.channels, comm_frames) ;
+               psf_binheader_writef (psf, "Em42t4", BHWm (COMM_MARKER), BHW4 (comm_size), BHW2 (psf->sf.channels), BHW4 (comm_frames)) ;
                } ;
 
        /* PEAK chunk. */
        if ((k = psf_find_read_chunk_m32 (&psf->rchunks, PEAK_MARKER)) >= 0)
        {       psf->header.indx = psf->rchunks.chunks [k].offset - 8 ;
-               psf_binheader_writef (psf, "Em4", PEAK_MARKER, AIFF_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
-               psf_binheader_writef (psf, "E44", 1, time (NULL)) ;
+               psf_binheader_writef (psf, "Em4", BHWm (PEAK_MARKER), BHW4 (AIFF_PEAK_CHUNK_SIZE (psf->sf.channels))) ;
+               psf_binheader_writef (psf, "E44", BHW4 (1), BHW4 (time (NULL))) ;
                for (ch = 0 ; ch < psf->sf.channels ; ch++)
-                       psf_binheader_writef (psf, "Eft8", (float) psf->peak_info->peaks [ch].value, psf->peak_info->peaks [ch].position) ;
+                       psf_binheader_writef (psf, "Eft8", BHWf ((float) psf->peak_info->peaks [ch].value), BHW8 (psf->peak_info->peaks [ch].position)) ;
                } ;
 
 
        /* SSND chunk. */
        if ((k = psf_find_read_chunk_m32 (&psf->rchunks, SSND_MARKER)) >= 0)
        {       psf->header.indx = psf->rchunks.chunks [k].offset - 8 ;
-               psf_binheader_writef (psf, "Etm8", SSND_MARKER, psf->datalength + SIZEOF_SSND_CHUNK) ;
+               psf_binheader_writef (psf, "Etm8", BHWm (SSND_MARKER), BHW8 (psf->datalength + SIZEOF_SSND_CHUNK)) ;
                } ;
 
        /* Header mangling complete so write it out. */
@@ -1409,29 +1409,29 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length)
        psf->header.indx = 0 ;
        psf_fseek (psf, 0, SEEK_SET) ;
 
-       psf_binheader_writef (psf, "Etm8", FORM_MARKER, psf->filelength - 8) ;
+       psf_binheader_writef (psf, "Etm8", BHWm (FORM_MARKER), BHW8 (psf->filelength - 8)) ;
 
        /* Write AIFF/AIFC marker and COM chunk. */
        if (comm_type == AIFC_MARKER)
                /* AIFC must have an FVER chunk. */
-               psf_binheader_writef (psf, "Emm44", comm_type, FVER_MARKER, 4, 0xA2805140) ;
+               psf_binheader_writef (psf, "Emm44", BHWm (comm_type), BHWm (FVER_MARKER), BHW4 (4), BHW4 (0xA2805140)) ;
        else
-               psf_binheader_writef (psf, "Em", comm_type) ;
+               psf_binheader_writef (psf, "Em", BHWm (comm_type)) ;
 
        paiff->comm_offset = psf->header.indx - 8 ;
 
        memset (comm_sample_rate, 0, sizeof (comm_sample_rate)) ;
        uint2tenbytefloat (psf->sf.samplerate, comm_sample_rate) ;
 
-       psf_binheader_writef (psf, "Em42t42", COMM_MARKER, comm_size, psf->sf.channels, comm_frames, bit_width) ;
-       psf_binheader_writef (psf, "b", comm_sample_rate, sizeof (comm_sample_rate)) ;
+       psf_binheader_writef (psf, "Em42t42", BHWm (COMM_MARKER), BHW4 (comm_size), BHW2 (psf->sf.channels), BHW4 (comm_frames), BHW2 (bit_width)) ;
+       psf_binheader_writef (psf, "b", BHWv (comm_sample_rate), BHWz (sizeof (comm_sample_rate))) ;
 
        /* AIFC chunks have some extra data. */
        if (comm_type == AIFC_MARKER)
-               psf_binheader_writef (psf, "mb", comm_encoding, comm_zero_bytes, sizeof (comm_zero_bytes)) ;
+               psf_binheader_writef (psf, "mb", BHWm (comm_encoding), BHWv (comm_zero_bytes), BHWz (sizeof (comm_zero_bytes))) ;
 
        if (psf->channel_map && paiff->chanmap_tag)
-               psf_binheader_writef (psf, "Em4444", CHAN_MARKER, 12, paiff->chanmap_tag, 0, 0) ;
+               psf_binheader_writef (psf, "Em4444", BHWm (CHAN_MARKER), BHW4 (12), BHW4 (paiff->chanmap_tag), BHW4 (0), BHW4 (0)) ;
 
        /* Check if there's a INST chunk to write */
        if (psf->instrument != NULL && psf->cues != NULL)
@@ -1583,29 +1583,29 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length)
                        } ;
 
                psf_binheader_writef (psf, "Em42",
-                       MARK_MARKER, 2 + psf->cues->cue_count * (2 + 4) + totalStringLength, psf->cues->cue_count) ;
+                       BHWm (MARK_MARKER), BHW4 (2 + psf->cues->cue_count * (2 + 4) + totalStringLength), BHW2 (psf->cues->cue_count)) ;
 
                for (idx = 0 ; idx < psf->cues->cue_count ; idx++)
-                       psf_binheader_writef (psf, "E24p", psf->cues->cue_points [idx].indx, psf->cues->cue_points [idx].sample_offset, psf->cues->cue_points [idx].name) ;
+                       psf_binheader_writef (psf, "E24p", BHW2 (psf->cues->cue_points [idx].indx), BHW4 (psf->cues->cue_points [idx].sample_offset), BHWp (psf->cues->cue_points [idx].name)) ;
                } ;
 
        if (psf->strings.flags & SF_STR_LOCATE_START)
                aiff_write_strings (psf, SF_STR_LOCATE_START) ;
 
        if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_START)
-       {       psf_binheader_writef (psf, "Em4", PEAK_MARKER, AIFF_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
-               psf_binheader_writef (psf, "E44", 1, time (NULL)) ;
+       {       psf_binheader_writef (psf, "Em4", BHWm (PEAK_MARKER), BHW4 (AIFF_PEAK_CHUNK_SIZE (psf->sf.channels))) ;
+               psf_binheader_writef (psf, "E44", BHW4 (1), BHW4 (time (NULL))) ;
                for (k = 0 ; k < psf->sf.channels ; k++)
-                       psf_binheader_writef (psf, "Eft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
+                       psf_binheader_writef (psf, "Eft8", BHWf ((float) psf->peak_info->peaks [k].value), BHW8 (psf->peak_info->peaks [k].position)) ;
                } ;
 
        /* Write custom headers. */
        for (uk = 0 ; uk < psf->wchunks.used ; uk++)
-               psf_binheader_writef (psf, "Em4b", psf->wchunks.chunks [uk].mark32, psf->wchunks.chunks [uk].len, psf->wchunks.chunks [uk].data, make_size_t (psf->wchunks.chunks [uk].len)) ;
+               psf_binheader_writef (psf, "Em4b", BHWm (psf->wchunks.chunks [uk].mark32), BHW4 (psf->wchunks.chunks [uk].len), BHWv (psf->wchunks.chunks [uk].data), BHWz (psf->wchunks.chunks [uk].len)) ;
 
        /* Write SSND chunk. */
        paiff->ssnd_offset = psf->header.indx ;
-       psf_binheader_writef (psf, "Etm844", SSND_MARKER, psf->datalength + SIZEOF_SSND_CHUNK, 0, 0) ;
+       psf_binheader_writef (psf, "Etm844", BHWm (SSND_MARKER), BHW8 (psf->datalength + SIZEOF_SSND_CHUNK), BHW4 (0), BHW4 (0)) ;
 
        /* Header construction complete so write it out. */
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
@@ -1643,10 +1643,10 @@ aiff_write_tailer (SF_PRIVATE *psf)
                } ;
 
        if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_END)
-       {       psf_binheader_writef (psf, "Em4", PEAK_MARKER, AIFF_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
-               psf_binheader_writef (psf, "E44", 1, time (NULL)) ;
+       {       psf_binheader_writef (psf, "Em4", BHWm (PEAK_MARKER), BHW4 (AIFF_PEAK_CHUNK_SIZE (psf->sf.channels))) ;
+               psf_binheader_writef (psf, "E44", BHW4 (1), BHW4 (time (NULL))) ;
                for (k = 0 ; k < psf->sf.channels ; k++)
-                       psf_binheader_writef (psf, "Eft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
+                       psf_binheader_writef (psf, "Eft8", BHWf ((float) psf->peak_info->peaks [k].value), BHW8 (psf->peak_info->peaks [k].position)) ;
                } ;
 
        if (psf->strings.flags & SF_STR_LOCATE_END)
@@ -1673,28 +1673,28 @@ aiff_write_strings (SF_PRIVATE *psf, int location)
                switch (psf->strings.data [k].type)
                {       case SF_STR_SOFTWARE :
                                slen = strlen (psf->strings.storage + psf->strings.data [k].offset) ;
-                               psf_binheader_writef (psf, "Em4mb", APPL_MARKER, slen + 4, m3ga_MARKER, psf->strings.storage + psf->strings.data [k].offset, make_size_t (slen + (slen & 1))) ;
+                               psf_binheader_writef (psf, "Em4mb", BHWm (APPL_MARKER), BHW4 (slen + 4), BHWm (m3ga_MARKER), BHWv (psf->strings.storage + psf->strings.data [k].offset), BHWz (slen + (slen & 1))) ;
                                break ;
 
                        case SF_STR_TITLE :
-                               psf_binheader_writef (psf, "EmS", NAME_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "EmS", BHWm (NAME_MARKER), BHWS (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_COPYRIGHT :
-                               psf_binheader_writef (psf, "EmS", c_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "EmS", BHWm (c_MARKER), BHWS (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_ARTIST :
-                               psf_binheader_writef (psf, "EmS", AUTH_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "EmS", BHWm (AUTH_MARKER), BHWS (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_COMMENT :
-                               psf_binheader_writef (psf, "EmS", ANNO_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "EmS", BHWm (ANNO_MARKER), BHWS (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        /*
                        case SF_STR_DATE :
-                               psf_binheader_writef (psf, "Ems", ICRD_MARKER, psf->strings.data [k].str) ;
+                               psf_binheader_writef (psf, "Ems", BHWm (ICRD_MARKER), BHWs (psf->strings.data [k].str)) ;
                                break ;
                        */
                        } ;
index fd0072e..cfe3060 100644 (file)
--- a/src/au.c
+++ b/src/au.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -225,12 +225,12 @@ au_write_header (SF_PRIVATE *psf, int calc_length)
                datalength = (int) (psf->datalength & 0x7FFFFFFF) ;
 
        if (psf->endian == SF_ENDIAN_BIG)
-       {       psf_binheader_writef (psf, "Em4", DOTSND_MARKER, AU_DATA_OFFSET) ;
-               psf_binheader_writef (psf, "E4444", datalength, encoding, psf->sf.samplerate, psf->sf.channels) ;
+       {       psf_binheader_writef (psf, "Em4", BHWm (DOTSND_MARKER), BHW4 (AU_DATA_OFFSET)) ;
+               psf_binheader_writef (psf, "E4444", BHW4 (datalength), BHW4 (encoding), BHW4 (psf->sf.samplerate), BHW4 (psf->sf.channels)) ;
                }
        else if (psf->endian == SF_ENDIAN_LITTLE)
-       {       psf_binheader_writef (psf, "em4", DNSDOT_MARKER, AU_DATA_OFFSET) ;
-               psf_binheader_writef (psf, "e4444", datalength, encoding, psf->sf.samplerate, psf->sf.channels) ;
+       {       psf_binheader_writef (psf, "em4", BHWm (DNSDOT_MARKER), BHW4 (AU_DATA_OFFSET)) ;
+               psf_binheader_writef (psf, "e4444", BHW4 (datalength), BHW4 (encoding), BHW4 (psf->sf.samplerate), BHW4 (psf->sf.channels)) ;
                }
        else
                return (psf->error = SFE_BAD_OPEN_FORMAT) ;
index a66bb47..5d9ecbe 100644 (file)
--- a/src/avr.c
+++ b/src/avr.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2004-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2004-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -211,15 +211,15 @@ avr_write_header (SF_PRIVATE *psf, int calc_length)
        if (psf->is_pipe == SF_FALSE)
                psf_fseek (psf, 0, SEEK_SET) ;
 
-       psf_binheader_writef (psf, "Emz22", TWOBIT_MARKER, make_size_t (8),
-                       psf->sf.channels == 2 ? 0xFFFF : 0, psf->bytewidth * 8) ;
+       psf_binheader_writef (psf, "Emz22", BHWm (TWOBIT_MARKER), BHWz (8),
+                       BHW2 (psf->sf.channels == 2 ? 0xFFFF : 0), BHW2 (psf->bytewidth * 8)) ;
 
        sign = ((SF_CODEC (psf->sf.format)) == SF_FORMAT_PCM_U8) ? 0 : 0xFFFF ;
 
-       psf_binheader_writef (psf, "E222", sign, 0, 0xFFFF) ;
-       psf_binheader_writef (psf, "E4444", psf->sf.samplerate, psf->sf.frames, 0, 0) ;
+       psf_binheader_writef (psf, "E222", BHW2 (sign), BHW2 (0), BHW2 (0xFFFF)) ;
+       psf_binheader_writef (psf, "E4444", BHW4 (psf->sf.samplerate), BHW4 (psf->sf.frames), BHW4 (0), BHW4 (0)) ;
 
-       psf_binheader_writef (psf, "E222zz", 0, 0, 0, make_size_t (20), make_size_t (64)) ;
+       psf_binheader_writef (psf, "E222zz", BHW2 (0), BHW2 (0), BHW2 (0), BHWz (20), BHWz (64)) ;
 
        /* Header construction complete so write it out. */
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
index 6546d6d..133731d 100644 (file)
--- a/src/caf.c
+++ b/src/caf.c
@@ -608,13 +608,13 @@ caf_write_header (SF_PRIVATE *psf, int calc_length)
        psf_fseek (psf, 0, SEEK_SET) ;
 
        /* 'caff' marker, version and flags. */
-       psf_binheader_writef (psf, "Em22", caff_MARKER, 1, 0) ;
+       psf_binheader_writef (psf, "Em22", BHWm (caff_MARKER), BHW2 (1), BHW2 (0)) ;
 
        /* 'desc' marker and chunk size. */
-       psf_binheader_writef (psf, "Em8", desc_MARKER, (sf_count_t) (sizeof (DESC_CHUNK))) ;
+       psf_binheader_writef (psf, "Em8", BHWm (desc_MARKER), BHW8 ((sf_count_t) (sizeof (DESC_CHUNK)))) ;
 
        double64_be_write (1.0 * psf->sf.samplerate, ubuf.ucbuf) ;
-       psf_binheader_writef (psf, "b", ubuf.ucbuf, make_size_t (8)) ;
+       psf_binheader_writef (psf, "b", BHWv (ubuf.ucbuf), BHWz (8)) ;
 
        subformat = SF_CODEC (psf->sf.format) ;
 
@@ -721,33 +721,33 @@ caf_write_header (SF_PRIVATE *psf, int calc_length)
                        return SFE_UNIMPLEMENTED ;
                } ;
 
-       psf_binheader_writef (psf, "mE44444", desc.fmt_id, desc.fmt_flags, desc.pkt_bytes, desc.frames_per_packet, desc.channels_per_frame, desc.bits_per_chan) ;
+       psf_binheader_writef (psf, "mE44444", BHWm (desc.fmt_id), BHW4 (desc.fmt_flags), BHW4 (desc.pkt_bytes), BHW4 (desc.frames_per_packet), BHW4 (desc.channels_per_frame), BHW4 (desc.bits_per_chan)) ;
 
        caf_write_strings (psf, SF_STR_LOCATE_START) ;
 
        if (psf->peak_info != NULL)
        {       int k ;
-               psf_binheader_writef (psf, "Em84", peak_MARKER, (sf_count_t) CAF_PEAK_CHUNK_SIZE (psf->sf.channels), psf->peak_info->edit_number) ;
+               psf_binheader_writef (psf, "Em84", BHWm (peak_MARKER), BHW8 ((sf_count_t) CAF_PEAK_CHUNK_SIZE (psf->sf.channels)), BHW4 (psf->peak_info->edit_number)) ;
                for (k = 0 ; k < psf->sf.channels ; k++)
-                       psf_binheader_writef (psf, "Ef8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
+                       psf_binheader_writef (psf, "Ef8", BHWf ((float) psf->peak_info->peaks [k].value), BHW8 (psf->peak_info->peaks [k].position)) ;
                } ;
 
        if (psf->channel_map && pcaf->chanmap_tag)
-               psf_binheader_writef (psf, "Em8444", chan_MARKER, (sf_count_t) 12, pcaf->chanmap_tag, 0, 0) ;
+               psf_binheader_writef (psf, "Em8444", BHWm (chan_MARKER), BHW8 ((sf_count_t) 12), BHW4 (pcaf->chanmap_tag), BHW4 (0), BHW4 (0)) ;
 
        /* Write custom headers. */
        for (uk = 0 ; uk < psf->wchunks.used ; uk++)
-               psf_binheader_writef (psf, "m44b", (int) psf->wchunks.chunks [uk].mark32, 0, psf->wchunks.chunks [uk].len, psf->wchunks.chunks [uk].data, make_size_t (psf->wchunks.chunks [uk].len)) ;
+               psf_binheader_writef (psf, "m44b", BHWm ((int) psf->wchunks.chunks [uk].mark32), BHW4 (0), BHW4 (psf->wchunks.chunks [uk].len), BHWv (psf->wchunks.chunks [uk].data), BHWz (psf->wchunks.chunks [uk].len)) ;
 
        if (append_free_block)
        {       /* Add free chunk so that the actual audio data starts at a multiple 0x1000. */
                sf_count_t free_len = 0x1000 - psf->header.indx - 16 - 12 ;
                while (free_len < 0)
                        free_len += 0x1000 ;
-               psf_binheader_writef (psf, "Em8z", free_MARKER, free_len, make_size_t (free_len)) ;
+               psf_binheader_writef (psf, "Em8z", BHWm (free_MARKER), BHW8 (free_len), BHWz (free_len)) ;
                } ;
 
-       psf_binheader_writef (psf, "Em84", data_MARKER, psf->datalength + 4, 0) ;
+       psf_binheader_writef (psf, "Em84", BHWm (data_MARKER), BHW8 (psf->datalength + 4), BHW4 (0)) ;
 
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
        if (psf->error)
@@ -780,7 +780,7 @@ caf_write_tailer (SF_PRIVATE *psf)
                psf->dataend = psf_fseek (psf, 0, SEEK_END) ;
 
        if (psf->dataend & 1)
-               psf_binheader_writef (psf, "z", 1) ;
+               psf_binheader_writef (psf, "z", BHWz (1)) ;
 
        if (psf->strings.flags & SF_STR_LOCATE_END)
                caf_write_strings (psf, SF_STR_LOCATE_END) ;
@@ -982,7 +982,7 @@ caf_write_strings (SF_PRIVATE * psf, int location)
        if (string_count == 0 || buf.index == 0)
                return ;
 
-       psf_binheader_writef (psf, "Em84b", info_MARKER, make_size_8 (buf.index + 4), string_count, buf.s, make_size_t (buf.index)) ;
+       psf_binheader_writef (psf, "Em84b", BHWm (info_MARKER), BHW8 (buf.index + 4), BHW4 (string_count), BHWv (buf.s), BHWz (buf.index)) ;
 } /* caf_write_strings */
 
 /*==============================================================================
index 8e01e25..63eb785 100644 (file)
@@ -42,7 +42,7 @@
 #endif
 
 #ifdef INT64_C
-#      define  SF_PLATFORM_S64(x)              INT64_C(x)
+#      define  SF_PLATFORM_S64(x)              INT64_C (x)
 #elif (SIZEOF_LONG == 8)
 #      define  SF_PLATFORM_S64(x)              x##l
 #elif (SIZEOF_LONG_LONG == 8)
 #define SF_CODEC(x)                    ((x) & SF_FORMAT_SUBMASK)
 #define SF_ENDIAN(x)           ((x) & SF_FORMAT_ENDMASK)
 
+/*
+**     Binheader cast macros.
+*/
+
+#define BHW1(x) ((uint8_t) (x))
+#define BHW2(x) ((uint16_t) (x))
+#define BHW3(x) ((uint32_t) (x))
+#define BHW4(x) ((uint32_t) (x))
+#define BHW8(x) ((uint64_t) (x))
+
+#define BHWm(x) ((uint32_t) (x))
+#define BHWS(x) ((char *) (x))
+
+#define BHWf(x) ((double) (x))
+#define BHWd(x) ((double) (x))
+
+#define BHWh(x) ((void *) (x))
+#define BHWj(x) ((size_t) (x))
+#define BHWp(x) ((char *) (x))
+#define BHWo(x) ((size_t) (x))
+#define BHWs(x) ((char *) (x))
+#define BHWv(x) ((const void *) (x))
+#define BHWz(x) ((size_t) (x))
+
+/*------------------------------------------------------------------------------
+*/
+
 enum
 {      /* PEAK chunk location. */
        SF_PEAK_START           = 42,
@@ -281,11 +308,6 @@ make_size_t (int x)
 {      return (size_t) x ;
 } /* make_size_t */
 
-static inline uint64_t
-make_size_8 (int x)
-{      return (uint64_t) x ;
-} /* make_size_8 */
-
 typedef SF_BROADCAST_INFO_VAR (16 * 1024) SF_BROADCAST_INFO_16K ;
 
 typedef SF_CART_INFO_VAR (16 * 1024) SF_CART_INFO_16K ;
index 32d392e..1041a84 100644 (file)
--- a/src/htk.c
+++ b/src/htk.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -123,7 +123,7 @@ htk_write_header (SF_PRIVATE *psf, int calc_length)
 
        sample_period = 10000000 / psf->sf.samplerate ;
 
-       psf_binheader_writef (psf, "E444", sample_count, sample_period, 0x20000) ;
+       psf_binheader_writef (psf, "E444", BHW4 (sample_count), BHW4 (sample_period), BHW4 (0x20000)) ;
 
        /* Header construction complete so write it out. */
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
index 7c3e924..8e7cdba 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2001-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2001-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -266,19 +266,19 @@ ircam_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
 
        switch (psf->endian)
        {       case SF_ENDIAN_BIG :
-                       psf_binheader_writef (psf, "Emf", IRCAM_02B_MARKER, samplerate) ;
-                       psf_binheader_writef (psf, "E44", psf->sf.channels, encoding) ;
+                       psf_binheader_writef (psf, "Emf", BHWm (IRCAM_02B_MARKER), BHWf (samplerate)) ;
+                       psf_binheader_writef (psf, "E44", BHW4 (psf->sf.channels), BHW4 (encoding)) ;
                        break ;
 
                case SF_ENDIAN_LITTLE :
-                       psf_binheader_writef (psf, "emf", IRCAM_03L_MARKER, samplerate) ;
-                       psf_binheader_writef (psf, "e44", psf->sf.channels, encoding) ;
+                       psf_binheader_writef (psf, "emf", BHWm (IRCAM_03L_MARKER), BHWf (samplerate)) ;
+                       psf_binheader_writef (psf, "e44", BHW4 (psf->sf.channels), BHW4 (encoding)) ;
                        break ;
 
                default : return SFE_BAD_OPEN_FORMAT ;
                } ;
 
-       psf_binheader_writef (psf, "z", (size_t) (IRCAM_DATA_OFFSET - psf->header.indx)) ;
+       psf_binheader_writef (psf, "z", BHWz ((size_t) (IRCAM_DATA_OFFSET - psf->header.indx))) ;
 
        /* Header construction complete so write it out. */
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
index 3c73680..40e61c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -173,16 +173,16 @@ mat4_write_header (SF_PRIVATE *psf, int calc_length)
        samplerate = psf->sf.samplerate ;
 
        if (psf->endian == SF_ENDIAN_BIG)
-       {       psf_binheader_writef (psf, "Em444", MAT4_BE_DOUBLE, 1, 1, 0) ;
-               psf_binheader_writef (psf, "E4bd", 11, "samplerate", make_size_t (11), samplerate) ;
-               psf_binheader_writef (psf, "tEm484", encoding, psf->sf.channels, psf->sf.frames, 0) ;
-               psf_binheader_writef (psf, "E4b", 9, "wavedata", make_size_t (9)) ;
+       {       psf_binheader_writef (psf, "Em444", BHWm (MAT4_BE_DOUBLE), BHW4 (1), BHW4 (1), BHW4 (0)) ;
+               psf_binheader_writef (psf, "E4bd", BHW4 (11), BHWv ("samplerate"), BHWz (11), BHWd (samplerate)) ;
+               psf_binheader_writef (psf, "tEm484", BHWm (encoding), BHW4 (psf->sf.channels), BHW8 (psf->sf.frames), BHW4 (0)) ;
+               psf_binheader_writef (psf, "E4b", BHW4 (9), BHWv ("wavedata"), BHWz (9)) ;
                }
        else if (psf->endian == SF_ENDIAN_LITTLE)
-       {       psf_binheader_writef (psf, "em444", MAT4_LE_DOUBLE, 1, 1, 0) ;
-               psf_binheader_writef (psf, "e4bd", 11, "samplerate", make_size_t (11), samplerate) ;
-               psf_binheader_writef (psf, "tem484", encoding, psf->sf.channels, psf->sf.frames, 0) ;
-               psf_binheader_writef (psf, "e4b", 9, "wavedata", make_size_t (9)) ;
+       {       psf_binheader_writef (psf, "em444", BHWm (MAT4_LE_DOUBLE), BHW4 (1), BHW4 (1), BHW4 (0)) ;
+               psf_binheader_writef (psf, "e4bd", BHW4 (11), BHWv ("samplerate"), BHWz (11), BHWd (samplerate)) ;
+               psf_binheader_writef (psf, "tem484", BHWm (encoding), BHW4 (psf->sf.channels), BHW8 (psf->sf.frames), BHW4 (0)) ;
+               psf_binheader_writef (psf, "e4b", BHW4 (9), BHWv ("wavedata"), BHWz (9)) ;
                }
        else
                return SFE_BAD_OPEN_FORMAT ;
index 11a57f4..57d2f1e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -206,41 +206,41 @@ mat5_write_header (SF_PRIVATE *psf, int calc_length)
        psf_fseek (psf, 0, SEEK_SET) ;
 
        psf_get_date_str (buffer, sizeof (buffer)) ;
-       psf_binheader_writef (psf, "bb", filename, strlen (filename), buffer, strlen (buffer) + 1) ;
+       psf_binheader_writef (psf, "bb", BHWv (filename), BHWz (strlen (filename)), BHWv (buffer), BHWz (strlen (buffer) + 1)) ;
 
        memset (buffer, ' ', 124 - psf->header.indx) ;
-       psf_binheader_writef (psf, "b", buffer, make_size_t (124 - psf->header.indx)) ;
+       psf_binheader_writef (psf, "b", BHWv (buffer), BHWz (124 - psf->header.indx)) ;
 
        psf->rwf_endian = psf->endian ;
 
        if (psf->rwf_endian == SF_ENDIAN_BIG)
-               psf_binheader_writef (psf, "2b", 0x0100, "MI", make_size_t (2)) ;
+               psf_binheader_writef (psf, "2b", BHW2 (0x0100), BHWv ("MI"), BHWz (2)) ;
        else
-               psf_binheader_writef (psf, "2b", 0x0100, "IM", make_size_t (2)) ;
+               psf_binheader_writef (psf, "2b", BHW2 (0x0100), BHWv ("IM"), BHWz (2)) ;
 
-       psf_binheader_writef (psf, "444444", MAT5_TYPE_ARRAY, 64, MAT5_TYPE_UINT32, 8, 6, 0) ;
-       psf_binheader_writef (psf, "4444", MAT5_TYPE_INT32, 8, 1, 1) ;
-       psf_binheader_writef (psf, "44b", MAT5_TYPE_SCHAR, strlen (sr_name), sr_name, make_size_t (16)) ;
+       psf_binheader_writef (psf, "444444", BHW4 (MAT5_TYPE_ARRAY), BHW4 (64), BHW4 (MAT5_TYPE_UINT32), BHW4 (8), BHW4 (6), BHW4 (0)) ;
+       psf_binheader_writef (psf, "4444", BHW4 (MAT5_TYPE_INT32), BHW4 (8), BHW4 (1), BHW4 (1)) ;
+       psf_binheader_writef (psf, "44b", BHW4 (MAT5_TYPE_SCHAR), BHW4 (strlen (sr_name)), BHWv (sr_name), BHWz (16)) ;
 
        if (psf->sf.samplerate > 0xFFFF)
-               psf_binheader_writef (psf, "44", MAT5_TYPE_COMP_UINT, psf->sf.samplerate) ;
+               psf_binheader_writef (psf, "44", BHW4 (MAT5_TYPE_COMP_UINT), BHW4 (psf->sf.samplerate)) ;
        else
        {       unsigned short samplerate = psf->sf.samplerate ;
 
-               psf_binheader_writef (psf, "422", MAT5_TYPE_COMP_USHORT, samplerate, 0) ;
+               psf_binheader_writef (psf, "422", BHW4 (MAT5_TYPE_COMP_USHORT), BHW2 (samplerate), BHW2 (0)) ;
                } ;
 
        datasize = psf->sf.frames * psf->sf.channels * psf->bytewidth ;
 
-       psf_binheader_writef (psf, "t484444", MAT5_TYPE_ARRAY, datasize + 64, MAT5_TYPE_UINT32, 8, 6, 0) ;
-       psf_binheader_writef (psf, "t4448", MAT5_TYPE_INT32, 8, psf->sf.channels, psf->sf.frames) ;
-       psf_binheader_writef (psf, "44b", MAT5_TYPE_SCHAR, strlen (wd_name), wd_name, strlen (wd_name)) ;
+       psf_binheader_writef (psf, "t484444", BHW4 (MAT5_TYPE_ARRAY), BHW8 (datasize + 64), BHW4 (MAT5_TYPE_UINT32), BHW4 (8), BHW4 (6), BHW4 (0)) ;
+       psf_binheader_writef (psf, "t4448", BHW4 (MAT5_TYPE_INT32), BHW4 (8), BHW4 (psf->sf.channels), BHW8 (psf->sf.frames)) ;
+       psf_binheader_writef (psf, "44b", BHW4 (MAT5_TYPE_SCHAR), BHW4 (strlen (wd_name)), BHWv (wd_name), BHWz (strlen (wd_name))) ;
 
        datasize = psf->sf.frames * psf->sf.channels * psf->bytewidth ;
        if (datasize > 0x7FFFFFFF)
                datasize = 0x7FFFFFFF ;
 
-       psf_binheader_writef (psf, "t48", encoding, datasize) ;
+       psf_binheader_writef (psf, "t48", BHW4 (encoding), BHW8 (datasize)) ;
 
        /* Header construction complete so write it out. */
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
index f004ca1..7ba8f1b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2008-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2008-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -133,10 +133,10 @@ mpc2k_write_header (SF_PRIVATE *psf, int calc_length)
 
        snprintf (sample_name, sizeof (sample_name), "%s                    ", psf->file.name.c) ;
 
-       psf_binheader_writef (psf, "e11b", 1, 4, sample_name, make_size_t (HEADER_NAME_LEN)) ;
-       psf_binheader_writef (psf, "e111", 100, 0, (psf->sf.channels - 1) & 1) ;
-       psf_binheader_writef (psf, "et4888", 0, psf->sf.frames, psf->sf.frames, psf->sf.frames) ;
-       psf_binheader_writef (psf, "e112", 0, 1, (uint16_t) psf->sf.samplerate) ;
+       psf_binheader_writef (psf, "e11b", BHW1 (1), BHW1 (4), BHWv (sample_name), BHWz (HEADER_NAME_LEN)) ;
+       psf_binheader_writef (psf, "e111", BHW1 (100), BHW1 (0), BHW1 ((psf->sf.channels - 1) & 1)) ;
+       psf_binheader_writef (psf, "et4888", BHW4 (0), BHW8 (psf->sf.frames), BHW8 (psf->sf.frames), BHW8 (psf->sf.frames)) ;
+       psf_binheader_writef (psf, "e112", BHW1 (0), BHW1 (1), BHW2 ((uint16_t) psf->sf.samplerate)) ;
 
        /* Always 16 bit little endian data. */
        psf->bytewidth = 2 ;
index bbc3002..062b838 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -510,7 +510,7 @@ wavlike_msadpcm_write_adapt_coeffs  (SF_PRIVATE *psf)
 {      int k ;
 
        for (k = 0 ; k < WAVLIKE_MSADPCM_ADAPT_COEFF_COUNT ; k++)
-               psf_binheader_writef (psf, "22", AdaptCoeff1 [k], AdaptCoeff2 [k]) ;
+               psf_binheader_writef (psf, "22", BHW2 (AdaptCoeff1 [k]), BHW2 (AdaptCoeff2 [k])) ;
 } /* wavlike_msadpcm_write_adapt_coeffs */
 
 /*==========================================================================================
index b6e2ff3..657c4d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -357,7 +357,7 @@ nist_write_header (SF_PRIVATE *psf, int calc_length)
        psf_asciiheader_printf (psf, "end_head\n") ;
 
        /* Zero fill to dataoffset. */
-       psf_binheader_writef (psf, "z", (size_t) (NIST_HEADER_LENGTH - psf->header.indx)) ;
+       psf_binheader_writef (psf, "z", BHWz ((size_t) (NIST_HEADER_LENGTH - psf->header.indx))) ;
 
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
 
index e9e0ed4..7b94942 100644 (file)
--- a/src/paf.c
+++ b/src/paf.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -303,19 +303,19 @@ paf_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
 
        if (psf->endian == SF_ENDIAN_BIG)
        {       /* Marker, version, endianness, samplerate */
-               psf_binheader_writef (psf, "Em444", PAF_MARKER, 0, 0, psf->sf.samplerate) ;
+               psf_binheader_writef (psf, "Em444", BHWm (PAF_MARKER), BHW4 (0), BHW4 (0), BHW4 (psf->sf.samplerate)) ;
                /* format, channels, source */
-               psf_binheader_writef (psf, "E444", paf_format, psf->sf.channels, 0) ;
+               psf_binheader_writef (psf, "E444", BHW4 (paf_format), BHW4 (psf->sf.channels), BHW4 (0)) ;
                }
        else if (psf->endian == SF_ENDIAN_LITTLE)
        {       /* Marker, version, endianness, samplerate */
-               psf_binheader_writef (psf, "em444", FAP_MARKER, 0, 1, psf->sf.samplerate) ;
+               psf_binheader_writef (psf, "em444", BHWm (FAP_MARKER), BHW4 (0), BHW4 (1), BHW4 (psf->sf.samplerate)) ;
                /* format, channels, source */
-               psf_binheader_writef (psf, "e444", paf_format, psf->sf.channels, 0) ;
+               psf_binheader_writef (psf, "e444", BHW4 (paf_format), BHW4 (psf->sf.channels), BHW4 (0)) ;
                } ;
 
        /* Zero fill to dataoffset. */
-       psf_binheader_writef (psf, "z", (size_t) (psf->dataoffset - psf->header.indx)) ;
+       psf_binheader_writef (psf, "z", BHWz ((size_t) (psf->dataoffset - psf->header.indx))) ;
 
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
 
index 60a3309..d57f0f3 100644 (file)
@@ -543,25 +543,25 @@ rf64_write_fmt_chunk (SF_PRIVATE *psf)
                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 + 2 + 4 + 4 + 2 + 2 + 8 ;
 
                        /* fmt : format, channels, samplerate */
-                       psf_binheader_writef (psf, "4224", fmt_size, WAVE_FORMAT_EXTENSIBLE, psf->sf.channels, psf->sf.samplerate) ;
+                       psf_binheader_writef (psf, "4224", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_EXTENSIBLE), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                        /*  fmt : bytespersec */
-                       psf_binheader_writef (psf, "4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                       psf_binheader_writef (psf, "4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                        /*  fmt : blockalign, bitwidth */
-                       psf_binheader_writef (psf, "22", psf->bytewidth * psf->sf.channels, psf->bytewidth * 8) ;
+                       psf_binheader_writef (psf, "22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (psf->bytewidth * 8)) ;
 
                        /* cbSize 22 is sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX) */
-                       psf_binheader_writef (psf, "2", 22) ;
+                       psf_binheader_writef (psf, "2", BHW2 (22)) ;
 
                        /* wValidBitsPerSample, for our use same as bitwidth as we use it fully */
-                       psf_binheader_writef (psf, "2", psf->bytewidth * 8) ;
+                       psf_binheader_writef (psf, "2", BHW2 (psf->bytewidth * 8)) ;
 
                        /* For an Ambisonic file set the channel mask to zero.
                        ** Otherwise use a default based on the channel count.
                        */
                        if (wpriv->wavex_ambisonic != SF_AMBISONIC_NONE)
-                               psf_binheader_writef (psf, "4", 0) ;
+                               psf_binheader_writef (psf, "4", BHW4 (0)) ;
                        else if (wpriv->wavex_channelmask != 0)
-                               psf_binheader_writef (psf, "4", wpriv->wavex_channelmask) ;
+                               psf_binheader_writef (psf, "4", BHW4 (wpriv->wavex_channelmask)) ;
                        else
                        {       /*
                                ** Ok some liberty is taken here to use the most commonly used channel masks
@@ -570,27 +570,27 @@ rf64_write_fmt_chunk (SF_PRIVATE *psf)
                                */
                                switch (psf->sf.channels)
                                {       case 1 :        /* center channel mono */
-                                               psf_binheader_writef (psf, "4", 0x4) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x4)) ;
                                                break ;
 
                                        case 2 :        /* front left and right */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2)) ;
                                                break ;
 
                                        case 4 :        /* Quad */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2 | 0x10 | 0x20) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2 | 0x10 | 0x20)) ;
                                                break ;
 
                                        case 6 :        /* 5.1 */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)) ;
                                                break ;
 
                                        case 8 :        /* 7.1 */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80)) ;
                                                break ;
 
                                        default :       /* 0 when in doubt , use direct out, ie NO mapping*/
-                                               psf_binheader_writef (psf, "4", 0x0) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x0)) ;
                                                break ;
                                        } ;
                                } ;
@@ -664,18 +664,18 @@ rf64_write_header (SF_PRIVATE *psf, int calc_length)
        psf_fseek (psf, 0, SEEK_SET) ;
 
        if (wpriv->rf64_downgrade && psf->filelength < RIFF_DOWNGRADE_BYTES)
-       {       psf_binheader_writef (psf, "etm8m", RIFF_MARKER, (psf->filelength < 8) ? 8 : psf->filelength - 8, WAVE_MARKER) ;
-               psf_binheader_writef (psf, "m4z", JUNK_MARKER, 24, 24) ;
+       {       psf_binheader_writef (psf, "etm8m", BHWm (RIFF_MARKER), BHW8 ((psf->filelength < 8) ? 8 : psf->filelength - 8), BHWm (WAVE_MARKER)) ;
+               psf_binheader_writef (psf, "m4z", BHWm (JUNK_MARKER), BHW4 (24), BHWz (24)) ;
                add_fact_chunk = 1 ;
                }
        else
-       {       psf_binheader_writef (psf, "em4m", RF64_MARKER, 0xffffffff, WAVE_MARKER) ;
+       {       psf_binheader_writef (psf, "em4m", BHWm (RF64_MARKER), BHW4 (0xffffffff), BHWm (WAVE_MARKER)) ;
                /* Currently no table. */
-               psf_binheader_writef (psf, "m48884", ds64_MARKER, 28, psf->filelength - 8, psf->datalength, psf->sf.frames, 0) ;
+               psf_binheader_writef (psf, "m48884", BHWm (ds64_MARKER), BHW4 (28), BHW8 (psf->filelength - 8), BHW8 (psf->datalength), BHW8 (psf->sf.frames), BHW4 (0)) ;
                } ;
 
        /* WAVE and 'fmt ' markers. */
-       psf_binheader_writef (psf, "m", fmt_MARKER) ;
+       psf_binheader_writef (psf, "m", BHWm (fmt_MARKER)) ;
 
        /* Write the 'fmt ' chunk. */
        switch (psf->sf.format & SF_FORMAT_TYPEMASK)
@@ -689,7 +689,7 @@ rf64_write_header (SF_PRIVATE *psf, int calc_length)
                                if ((error = rf64_write_fmt_chunk (psf)) != 0)
                                        return error ;
                                if (add_fact_chunk)
-                                       psf_binheader_writef (psf, "tm48", fact_MARKER, 4, psf->sf.frames) ;
+                                       psf_binheader_writef (psf, "tm48", BHWm (fact_MARKER), BHW4 (4), BHW8 (psf->sf.frames)) ;
                                break ;
 
                default :
@@ -718,14 +718,14 @@ rf64_write_header (SF_PRIVATE *psf, int calc_length)
        {       int             tmp ;
                double  dtune = (double) (0x40000000) / 25.0 ;
 
-               psf_binheader_writef (psf, "m4", smpl_MARKER, 9 * 4 + psf->instrument->loop_count * 6 * 4) ;
-               psf_binheader_writef (psf, "44", 0, 0) ; /* Manufacturer zero is everyone */
+               psf_binheader_writef (psf, "m4", BHWm (smpl_MARKER), BHW4 (9 * 4 + psf->instrument->loop_count * 6 * 4)) ;
+               psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (0)) ; /* Manufacturer zero is everyone */
                tmp = (int) (1.0e9 / psf->sf.samplerate) ; /* Sample period in nano seconds */
-               psf_binheader_writef (psf, "44", tmp, psf->instrument->basenote) ;
+               psf_binheader_writef (psf, "44", BHW4 (tmp), BHW4 (psf->instrument->basenote)) ;
                tmp = (unsigned int) (psf->instrument->detune * dtune + 0.5) ;
-               psf_binheader_writef (psf, "4", tmp) ;
-               psf_binheader_writef (psf, "44", 0, 0) ; /* SMTPE format */
-               psf_binheader_writef (psf, "44", psf->instrument->loop_count, 0) ;
+               psf_binheader_writef (psf, "4", BHW4 (tmp)) ;
+               psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (0)) ; /* SMTPE format */
+               psf_binheader_writef (psf, "44", BHW4 (psf->instrument->loop_count), BHW4 (0)) ;
 
                for (tmp = 0 ; tmp < psf->instrument->loop_count ; tmp++)
                {       int type ;
@@ -733,9 +733,9 @@ rf64_write_header (SF_PRIVATE *psf, int calc_length)
                        type = psf->instrument->loops [tmp].mode ;
                        type = (type == SF_LOOP_FORWARD ? 0 : type == SF_LOOP_BACKWARD ? 2 : type == SF_LOOP_ALTERNATING ? 1 : 32) ;
 
-                       psf_binheader_writef (psf, "44", tmp, type) ;
-                       psf_binheader_writef (psf, "44", psf->instrument->loops [tmp].start, psf->instrument->loops [tmp].end) ;
-                       psf_binheader_writef (psf, "44", 0, psf->instrument->loops [tmp].count) ;
+                       psf_binheader_writef (psf, "44", BHW4 (tmp), BHW4 (type)) ;
+                       psf_binheader_writef (psf, "44", BHW4 (psf->instrument->loops [tmp].start), BHW4 (psf->instrument->loops [tmp].end)) ;
+                       psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (psf->instrument->loops [tmp].count)) ;
                        } ;
                } ;
 
@@ -744,12 +744,12 @@ rf64_write_header (SF_PRIVATE *psf, int calc_length)
        /* Padding may be needed if string data sizes change. */
        pad_size = psf->dataoffset - 16 - psf->header.indx ;
        if (pad_size >= 0)
-               psf_binheader_writef (psf, "m4z", PAD_MARKER, (unsigned int) pad_size, make_size_t (pad_size)) ;
+               psf_binheader_writef (psf, "m4z", BHWm (PAD_MARKER), BHW4 ((unsigned int) pad_size), BHWz (pad_size)) ;
 
        if (wpriv->rf64_downgrade && (psf->filelength < RIFF_DOWNGRADE_BYTES))
-               psf_binheader_writef (psf, "tm8", data_MARKER, psf->datalength) ;
+               psf_binheader_writef (psf, "tm8", BHWm (data_MARKER), BHW8 (psf->datalength)) ;
        else
-               psf_binheader_writef (psf, "m4", data_MARKER, 0xffffffff) ;
+               psf_binheader_writef (psf, "m4", BHWm (data_MARKER), BHW4 (0xffffffff)) ;
 
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
        if (psf->error)
@@ -788,7 +788,7 @@ rf64_write_tailer (SF_PRIVATE *psf)
                psf->dataend = psf_fseek (psf, 0, SEEK_END) ;
 
        if (psf->dataend & 1)
-               psf_binheader_writef (psf, "z", 1) ;
+               psf_binheader_writef (psf, "z", BHWz (1)) ;
 
        if (psf->strings.flags & SF_STR_LOCATE_END)
                wavlike_write_strings (psf, SF_STR_LOCATE_END) ;
index b9dac95..4846c58 100644 (file)
--- a/src/sd2.c
+++ b/src/sd2.c
@@ -238,61 +238,61 @@ sd2_write_rsrc_fork (SF_PRIVATE *psf, int UNUSED (calc_length))
        rsrc.map_offset = rsrc.data_offset + rsrc.data_length ;
 
        /* Very start of resource fork. */
-       psf_binheader_writef (psf, "E444", rsrc.data_offset, rsrc.map_offset, rsrc.data_length) ;
+       psf_binheader_writef (psf, "E444", BHW4 (rsrc.data_offset), BHW4 (rsrc.map_offset), BHW4 (rsrc.data_length)) ;
 
-       psf_binheader_writef (psf, "Eop", make_size_t (0x30), psf->file.name.c) ;
-       psf_binheader_writef (psf, "Eo2mm", make_size_t (0x50), 0, Sd2f_MARKER, lsf1_MARKER) ;
+       psf_binheader_writef (psf, "Eop", BHWo (0x30), BHWp (psf->file.name.c)) ;
+       psf_binheader_writef (psf, "Eo2mm", BHWo (0x50), BHW2 (0), BHWm (Sd2f_MARKER), BHWm (lsf1_MARKER)) ;
 
        /* Very start of resource map. */
-       psf_binheader_writef (psf, "E4444", make_size_t (rsrc.map_offset), rsrc.data_offset, rsrc.map_offset, rsrc.data_length) ;
+       psf_binheader_writef (psf, "E4444", BHW4 (rsrc.map_offset), BHW4 (rsrc.data_offset), BHW4 (rsrc.map_offset), BHW4 (rsrc.data_length)) ;
 
        /* These I don't currently understand. */
        if (1)
-       {       psf_binheader_writef (psf, "Eo1422", make_size_t (rsrc.map_offset + 16), 1, 0x12345678, 0xabcd, 0) ;
+       {       psf_binheader_writef (psf, "Eo1422", BHWo (rsrc.map_offset + 16), BHW1 (1), BHW4 (0x12345678), BHW2 (0xabcd), BHW2 (0)) ;
                } ;
 
        /* Resource type offset. */
        rsrc.type_offset = rsrc.map_offset + 30 ;
-       psf_binheader_writef (psf, "Eo2", make_size_t (rsrc.map_offset + 24), rsrc.type_offset - rsrc.map_offset - 2) ;
+       psf_binheader_writef (psf, "Eo2", BHWo (rsrc.map_offset + 24), BHW2 (rsrc.type_offset - rsrc.map_offset - 2)) ;
 
        /* Type index max. */
        rsrc.type_count = 2 ;
-       psf_binheader_writef (psf, "Eo2", make_size_t (rsrc.map_offset + 28), rsrc.type_count - 1) ;
+       psf_binheader_writef (psf, "Eo2", BHWo (rsrc.map_offset + 28), BHW2 (rsrc.type_count - 1)) ;
 
        rsrc.item_offset = rsrc.type_offset + rsrc.type_count * 8 ;
 
        rsrc.str_count = ARRAY_LEN (str_rsrc) ;
        rsrc.string_offset = rsrc.item_offset + (rsrc.str_count + 1) * 12 - rsrc.map_offset ;
-       psf_binheader_writef (psf, "Eo2", make_size_t (rsrc.map_offset + 26), rsrc.string_offset) ;
+       psf_binheader_writef (psf, "Eo2", BHWo (rsrc.map_offset + 26), BHW2 (rsrc.string_offset)) ;
 
        /* Write 'STR ' resource type. */
        rsrc.str_count = 3 ;
-       psf_binheader_writef (psf, "Eom22", make_size_t (rsrc.type_offset), STR_MARKER, rsrc.str_count - 1, 0x12) ;
+       psf_binheader_writef (psf, "Eom22", BHWo (rsrc.type_offset), BHWm (STR_MARKER), BHW2 (rsrc.str_count - 1), BHW2 (0x12)) ;
 
        /* Write 'sdML' resource type. */
-       psf_binheader_writef (psf, "Em22", sdML_MARKER, 0, 0x36) ;
+       psf_binheader_writef (psf, "Em22", BHWm (sdML_MARKER), BHW2 (0), BHW2 (0x36)) ;
 
        str_offset = rsrc.map_offset + rsrc.string_offset ;
        next_str = 0 ;
        data_offset = rsrc.data_offset ;
        for (k = 0 ; k < ARRAY_LEN (str_rsrc) ; k++)
-       {       psf_binheader_writef (psf, "Eop", make_size_t (str_offset), str_rsrc [k].name) ;
-               psf_binheader_writef (psf, "Eo22", make_size_t (rsrc.item_offset + k * 12), str_rsrc [k].id, next_str) ;
+       {       psf_binheader_writef (psf, "Eop", BHWo (str_offset), BHWp (str_rsrc [k].name)) ;
+               psf_binheader_writef (psf, "Eo22", BHWo (rsrc.item_offset + k * 12), BHW2 (str_rsrc [k].id), BHW2 (next_str)) ;
 
                str_offset += strlen (str_rsrc [k].name) ;
                next_str += strlen (str_rsrc [k].name) ;
 
-               psf_binheader_writef (psf, "Eo4", make_size_t (rsrc.item_offset + k * 12 + 4), data_offset - rsrc.data_offset) ;
-               psf_binheader_writef (psf, "Eo4", make_size_t (data_offset), str_rsrc [k].value_len) ;
+               psf_binheader_writef (psf, "Eo4", BHWo (rsrc.item_offset + k * 12 + 4), BHW4 (data_offset - rsrc.data_offset)) ;
+               psf_binheader_writef (psf, "Eo4", BHWo (data_offset), BHW4 (str_rsrc [k].value_len)) ;
 
-               psf_binheader_writef (psf, "Eob", make_size_t (data_offset + 4), str_rsrc [k].value, make_size_t (str_rsrc [k].value_len)) ;
+               psf_binheader_writef (psf, "Eob", BHWo (data_offset + 4), BHWv (str_rsrc [k].value), BHWz (str_rsrc [k].value_len)) ;
                data_offset += 4 + str_rsrc [k].value_len ;
                } ;
 
        /* Finally, calculate and set map length. */
        rsrc.map_length = str_offset - rsrc.map_offset ;
-       psf_binheader_writef (psf, "Eo4o4", make_size_t (12), rsrc.map_length,
-                                                       make_size_t (rsrc.map_offset + 12), rsrc.map_length) ;
+       psf_binheader_writef (psf, "Eo4o4", BHWo (12), BHW4 (rsrc.map_length),
+                                                       BHWo (rsrc.map_offset + 12), BHW4 (rsrc.map_length)) ;
 
        psf->header.indx = rsrc.map_offset + rsrc.map_length ;
 
index 77c2313..85c8c11 100644 (file)
--- a/src/sds.c
+++ b/src/sds.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -372,7 +372,7 @@ sds_write_header (SF_PRIVATE *psf, int calc_length)
        if (psf->is_pipe == SF_FALSE)
                psf_fseek (psf, 0, SEEK_SET) ;
 
-       psf_binheader_writef (psf, "E211", 0xF07E, 0, 1) ;
+       psf_binheader_writef (psf, "E211", BHW2 (0xF07E), BHW1 (0), BHW1 (1)) ;
 
        switch (SF_CODEC (psf->sf.format))
        {       case SF_FORMAT_PCM_S8 :
@@ -390,13 +390,13 @@ sds_write_header (SF_PRIVATE *psf, int calc_length)
 
        samp_period = SDS_INT_TO_3BYTE_ENCODE (1000000000 / psf->sf.samplerate) ;
 
-       psf_binheader_writef (psf, "e213", 0, psds->bitwidth, samp_period) ;
+       psf_binheader_writef (psf, "e213", BHW2 (0), BHW1 (psds->bitwidth), BHW3 (samp_period)) ;
 
        data_length                     = SDS_INT_TO_3BYTE_ENCODE (psds->total_written) ;
        sustain_loop_start      = SDS_INT_TO_3BYTE_ENCODE (0) ;
        sustain_loop_end        = SDS_INT_TO_3BYTE_ENCODE (0) ;
 
-       psf_binheader_writef (psf, "e33311", data_length, sustain_loop_start, sustain_loop_end, loop_type, 0xF7) ;
+       psf_binheader_writef (psf, "e33311", BHW3 (data_length), BHW3 (sustain_loop_start), BHW3 (sustain_loop_end), BHW1 (loop_type), BHW1 (0xF7)) ;
 
        /* Header construction complete so write it out. */
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
index 2dc322c..72d803f 100644 (file)
--- a/src/svx.c
+++ b/src/svx.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -362,29 +362,29 @@ svx_write_header (SF_PRIVATE *psf, int calc_length)
        psf_fseek (psf, 0, SEEK_SET) ;
 
        /* FORM marker and FORM size. */
-       psf_binheader_writef (psf, "Etm8", FORM_MARKER, (psf->filelength < 8) ?
-                       psf->filelength * 0 : psf->filelength - 8) ;
+       psf_binheader_writef (psf, "Etm8", BHWm (FORM_MARKER), BHW8 ((psf->filelength < 8) ?
+                       psf->filelength * 0 : psf->filelength - 8)) ;
 
-       psf_binheader_writef (psf, "m", (psf->bytewidth == 1) ? SVX8_MARKER : SV16_MARKER) ;
+       psf_binheader_writef (psf, "m", BHWm ((psf->bytewidth == 1) ? SVX8_MARKER : SV16_MARKER)) ;
 
        /* VHDR chunk. */
-       psf_binheader_writef (psf, "Em4", VHDR_MARKER, sizeof (VHDR_CHUNK)) ;
+       psf_binheader_writef (psf, "Em4", BHWm (VHDR_MARKER), BHW4 (sizeof (VHDR_CHUNK))) ;
        /* VHDR : oneShotHiSamples, repeatHiSamples, samplesPerHiCycle */
-       psf_binheader_writef (psf, "E444", psf->sf.frames, 0, 0) ;
+       psf_binheader_writef (psf, "E444", BHW4 (psf->sf.frames), BHW4 (0), BHW4 (0)) ;
        /* VHDR : samplesPerSec, octave, compression */
-       psf_binheader_writef (psf, "E211", psf->sf.samplerate, 1, 0) ;
+       psf_binheader_writef (psf, "E211", BHW2 (psf->sf.samplerate), BHW1 (1), BHW1 (0)) ;
        /* VHDR : volume */
-       psf_binheader_writef (psf, "E4", (psf->bytewidth == 1) ? 0xFF : 0xFFFF) ;
+       psf_binheader_writef (psf, "E4", BHW4 ((psf->bytewidth == 1) ? 0xFF : 0xFFFF)) ;
 
        if (psf->sf.channels == 2)
-               psf_binheader_writef (psf, "Em44", CHAN_MARKER, 4, 6) ;
+               psf_binheader_writef (psf, "Em44", BHWm (CHAN_MARKER), BHW4 (4), BHW4 (6)) ;
 
        /* Filename and annotation strings. */
-       psf_binheader_writef (psf, "Emsms", NAME_MARKER, psf->file.name.c, ANNO_MARKER, annotation) ;
+       psf_binheader_writef (psf, "Emsms", BHWm (NAME_MARKER), BHWs (psf->file.name.c), BHWm (ANNO_MARKER), BHWs (annotation)) ;
 
        /* BODY marker and size. */
-       psf_binheader_writef (psf, "Etm8", BODY_MARKER, (psf->datalength < 0) ?
-                       psf->datalength * 0 : psf->datalength) ;
+       psf_binheader_writef (psf, "Etm8", BHWm (BODY_MARKER), BHW8 ((psf->datalength < 0) ?
+                       psf->datalength * 0 : psf->datalength)) ;
 
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
 
index b76c825..8b1f9c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -43,7 +43,7 @@ test_binheader_writef (void)
        {       psf_strlcpy (buffer, sizeof (buffer), "abcdefghijklmnop") ;
                buffer [k] = 0 ;
 
-               psf_binheader_writef (psf, "Ep", buffer) ;
+               psf_binheader_writef (psf, "Ep", BHWp (buffer)) ;
 
                if ((psf->header.indx & 1) != 0)
                        errors = 1 ;
index e783b68..579bc29 100644 (file)
--- a/src/voc.c
+++ b/src/voc.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2001-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2001-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -441,10 +441,10 @@ voc_write_header (SF_PRIVATE *psf, int calc_length)
        psf_fseek (psf, 0, SEEK_SET) ;
 
        /* VOC marker and 0x1A byte. */
-       psf_binheader_writef (psf, "eb1", "Creative Voice File", make_size_t (19), 0x1A) ;
+       psf_binheader_writef (psf, "eb1", BHWv ("Creative Voice File"), BHWz (19), BHW1 (0x1A)) ;
 
        /* Data offset, version and other. */
-       psf_binheader_writef (psf, "e222", 26, 0x0114, 0x111F) ;
+       psf_binheader_writef (psf, "e222", BHW2 (26), BHW2 (0x0114), BHW2 (0x111F)) ;
 
        /*      Use same logic as SOX.
        **      If the file is mono 8 bit data, use VOC_SOUND_DATA.
@@ -457,7 +457,7 @@ voc_write_header (SF_PRIVATE *psf, int calc_length)
                rate_const = 256 - 1000000 / psf->sf.samplerate ;
 
                /* First type marker, length, rate_const and compression */
-               psf_binheader_writef (psf, "e1311", VOC_SOUND_DATA, (int) (psf->datalength + 1), rate_const, 0) ;
+               psf_binheader_writef (psf, "e1311", BHW1 (VOC_SOUND_DATA), BHW3 ((int) (psf->datalength + 1)), BHW1 (rate_const), BHW1 (0)) ;
                }
        else if (subformat == SF_FORMAT_PCM_U8 && psf->sf.channels == 2)
        {       /* sample_rate = 128000000 / (65536 - rate_short) ; */
@@ -466,7 +466,7 @@ voc_write_header (SF_PRIVATE *psf, int calc_length)
                /* First write the VOC_EXTENDED section
                **              marker, length, rate_const and compression
                */
-               psf_binheader_writef (psf, "e13211", VOC_EXTENDED, 4, rate_const, 0, 1) ;
+               psf_binheader_writef (psf, "e13211", BHW1 (VOC_EXTENDED), BHW3 (4), BHW2 (rate_const), BHW1 (0), BHW1 (1)) ;
 
                /* samplerate = 1000000 / (256 - rate_const) ; */
                rate_const = 256 - 1000000 / psf->sf.samplerate ;
@@ -474,7 +474,7 @@ voc_write_header (SF_PRIVATE *psf, int calc_length)
                /*      Now write the VOC_SOUND_DATA section
                **              marker, length, rate_const and compression
                */
-               psf_binheader_writef (psf, "e1311", VOC_SOUND_DATA, (int) (psf->datalength + 1), rate_const, 0) ;
+               psf_binheader_writef (psf, "e1311", BHW1 (VOC_SOUND_DATA), BHW3 ((int) (psf->datalength + 1)), BHW1 (rate_const), BHW1 (0)) ;
                }
        else
        {       int length ;
@@ -487,26 +487,26 @@ voc_write_header (SF_PRIVATE *psf, int calc_length)
                                        psf->bytewidth = 1 ;
                                        length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;
                                        /* Marker, length, sample rate, bitwidth, stereo flag, encoding and fourt zero bytes. */
-                                       psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 16, psf->sf.channels, 4, 0) ;
+                                       psf_binheader_writef (psf, "e1341124", BHW1 (VOC_EXTENDED_II), BHW3 (length), BHW4 (psf->sf.samplerate), BHW1 (16), BHW1 (psf->sf.channels), BHW2 (4), BHW4 (0)) ;
                                        break ;
 
                        case SF_FORMAT_PCM_16 :
                                        psf->bytewidth = 2 ;
                                        length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;
                                        /* Marker, length, sample rate, bitwidth, stereo flag, encoding and fourt zero bytes. */
-                                       psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 16, psf->sf.channels, 4, 0) ;
+                                       psf_binheader_writef (psf, "e1341124", BHW1 (VOC_EXTENDED_II), BHW3 (length), BHW4 (psf->sf.samplerate), BHW1 (16), BHW1 (psf->sf.channels), BHW2 (4), BHW4 (0)) ;
                                        break ;
 
                        case SF_FORMAT_ALAW :
                                        psf->bytewidth = 1 ;
                                        length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;
-                                       psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 8, psf->sf.channels, 6, 0) ;
+                                       psf_binheader_writef (psf, "e1341124", BHW1 (VOC_EXTENDED_II), BHW3 (length), BHW4 (psf->sf.samplerate), BHW1 (8), BHW1 (psf->sf.channels), BHW2 (6), BHW4 (0)) ;
                                        break ;
 
                        case SF_FORMAT_ULAW :
                                        psf->bytewidth = 1 ;
                                        length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;
-                                       psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 8, psf->sf.channels, 7, 0) ;
+                                       psf_binheader_writef (psf, "e1341124", BHW1 (VOC_EXTENDED_II), BHW3 (length), BHW4 (psf->sf.samplerate), BHW1 (8), BHW1 (psf->sf.channels), BHW2 (7), BHW4 (0)) ;
                                        break ;
 
                        default : return SFE_UNIMPLEMENTED ;
index 824ef83..e508c69 100644 (file)
--- a/src/w64.c
+++ b/src/w64.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -461,7 +461,7 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
        psf_fseek (psf, 0, SEEK_SET) ;
 
        /* riff marker, length, wave and 'fmt ' markers. */
-       psf_binheader_writef (psf, "eh8hh", riff_MARKER16, psf->filelength, wave_MARKER16, fmt_MARKER16) ;
+       psf_binheader_writef (psf, "eh8hh", BHWh (riff_MARKER16), BHW8 (psf->filelength), BHWh (wave_MARKER16), BHWh (fmt_MARKER16)) ;
 
        subformat = SF_CODEC (psf->sf.format) ;
 
@@ -475,11 +475,11 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                        fmt_size += fmt_pad ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "e8224", fmt_size, WAVE_FORMAT_PCM, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "e8224", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_PCM), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "e4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "e4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth */
-                                       psf_binheader_writef (psf, "e22", psf->bytewidth * psf->sf.channels, psf->bytewidth * 8) ;
+                                       psf_binheader_writef (psf, "e22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (psf->bytewidth * 8)) ;
                                        break ;
 
                case SF_FORMAT_FLOAT :
@@ -489,11 +489,11 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                        fmt_size += fmt_pad ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "e8224", fmt_size, WAVE_FORMAT_IEEE_FLOAT, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "e8224", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_IEEE_FLOAT), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "e4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "e4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth */
-                                       psf_binheader_writef (psf, "e22", psf->bytewidth * psf->sf.channels, psf->bytewidth * 8) ;
+                                       psf_binheader_writef (psf, "e22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (psf->bytewidth * 8)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -504,11 +504,11 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                        fmt_size += fmt_pad ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "e8224", fmt_size, WAVE_FORMAT_MULAW, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "e8224", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_MULAW), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "e4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "e4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth */
-                                       psf_binheader_writef (psf, "e22", psf->bytewidth * psf->sf.channels, 8) ;
+                                       psf_binheader_writef (psf, "e22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (8)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -519,11 +519,11 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                        fmt_size += fmt_pad ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "e8224", fmt_size, WAVE_FORMAT_ALAW, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "e8224", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_ALAW), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "e4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "e4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth */
-                                       psf_binheader_writef (psf, "e22", psf->bytewidth * psf->sf.channels, 8) ;
+                                       psf_binheader_writef (psf, "e22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (8)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -542,13 +542,13 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                                fmt_size += fmt_pad ;
 
                                                /* fmt : size, WAV format type, channels. */
-                                               psf_binheader_writef (psf, "e822", fmt_size, WAVE_FORMAT_IMA_ADPCM, psf->sf.channels) ;
+                                               psf_binheader_writef (psf, "e822", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_IMA_ADPCM), BHW2 (psf->sf.channels)) ;
 
                                                /* fmt : samplerate, bytespersec. */
-                                               psf_binheader_writef (psf, "e44", psf->sf.samplerate, bytespersec) ;
+                                               psf_binheader_writef (psf, "e44", BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
 
                                                /* fmt : blockalign, bitwidth, extrabytes, framesperblock. */
-                                               psf_binheader_writef (psf, "e2222", blockalign, 4, 2, framesperblock) ;
+                                               psf_binheader_writef (psf, "e2222", BHW2 (blockalign), BHW2 (4), BHW2 (2), BHW2 (framesperblock)) ;
                                                } ;
 
                                        add_fact_chunk = SF_TRUE ;
@@ -568,13 +568,13 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                                fmt_size += fmt_pad ;
 
                                                /* fmt : size, W64 format type, channels. */
-                                               psf_binheader_writef (psf, "e822", fmt_size, WAVE_FORMAT_MS_ADPCM, psf->sf.channels) ;
+                                               psf_binheader_writef (psf, "e822", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_MS_ADPCM), BHW2 (psf->sf.channels)) ;
 
                                                /* fmt : samplerate, bytespersec. */
-                                               psf_binheader_writef (psf, "e44", psf->sf.samplerate, bytespersec) ;
+                                               psf_binheader_writef (psf, "e44", BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
 
                                                /* fmt : blockalign, bitwidth, extrabytes, framesperblock. */
-                                               psf_binheader_writef (psf, "e22222", blockalign, 4, extrabytes, framesperblock, 7) ;
+                                               psf_binheader_writef (psf, "e22222", BHW2 (blockalign), BHW2 (4), BHW2 (extrabytes), BHW2 (framesperblock), BHW2 (7)) ;
 
                                                wavlike_msadpcm_write_adapt_coeffs (psf) ;
                                                } ;
@@ -594,13 +594,13 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
                                                fmt_size += fmt_pad ;
 
                                                /* fmt : size, WAV format type, channels. */
-                                               psf_binheader_writef (psf, "e822", fmt_size, WAVE_FORMAT_GSM610, psf->sf.channels) ;
+                                               psf_binheader_writef (psf, "e822", BHW8 (fmt_size), BHW2 (WAVE_FORMAT_GSM610), BHW2 (psf->sf.channels)) ;
 
                                                /* fmt : samplerate, bytespersec. */
-                                               psf_binheader_writef (psf, "e44", psf->sf.samplerate, bytespersec) ;
+                                               psf_binheader_writef (psf, "e44", BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
 
                                                /* fmt : blockalign, bitwidth, extrabytes, framesperblock. */
-                                               psf_binheader_writef (psf, "e2222", WAVLIKE_GSM610_BLOCKSIZE, 0, 2, WAVLIKE_GSM610_SAMPLES) ;
+                                               psf_binheader_writef (psf, "e2222", BHW2 (WAVLIKE_GSM610_BLOCKSIZE), BHW2 (0), BHW2 (2), BHW2 (WAVLIKE_GSM610_SAMPLES)) ;
                                                } ;
 
                                        add_fact_chunk = SF_TRUE ;
@@ -611,12 +611,12 @@ w64_write_header (SF_PRIVATE *psf, int calc_length)
 
        /* Pad to 8 bytes with zeros. */
        if (fmt_pad > 0)
-               psf_binheader_writef (psf, "z", fmt_pad) ;
+               psf_binheader_writef (psf, "z", BHWz (fmt_pad)) ;
 
        if (add_fact_chunk)
-               psf_binheader_writef (psf, "eh88", fact_MARKER16, (sf_count_t) (16 + 8 + 8), psf->sf.frames) ;
+               psf_binheader_writef (psf, "eh88", BHWh (fact_MARKER16), BHW8 ((sf_count_t) (16 + 8 + 8)), BHW8 (psf->sf.frames)) ;
 
-       psf_binheader_writef (psf, "eh8", data_MARKER16, psf->datalength + 24) ;
+       psf_binheader_writef (psf, "eh8", BHWh (data_MARKER16), BHW8 (psf->datalength + 24)) ;
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
 
        if (psf->error)
index 7452ae2..bade3fc 100644 (file)
--- a/src/wav.c
+++ b/src/wav.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 ** Copyright (C) 2004-2005 David Viens <davidv@plogue.com>
 **
 ** This program is free software; you can redistribute it and/or modify
@@ -725,11 +725,11 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "4224", fmt_size, WAVE_FORMAT_PCM, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "4224", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_PCM), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth */
-                                       psf_binheader_writef (psf, "22", psf->bytewidth * psf->sf.channels, psf->bytewidth * 8) ;
+                                       psf_binheader_writef (psf, "22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (psf->bytewidth * 8)) ;
                                        break ;
 
                case SF_FORMAT_FLOAT :
@@ -737,11 +737,11 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "4224", fmt_size, WAVE_FORMAT_IEEE_FLOAT, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "4224", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_IEEE_FLOAT), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth */
-                                       psf_binheader_writef (psf, "22", psf->bytewidth * psf->sf.channels, psf->bytewidth * 8) ;
+                                       psf_binheader_writef (psf, "22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (psf->bytewidth * 8)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -750,11 +750,11 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "4224", fmt_size, WAVE_FORMAT_MULAW, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "4224", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_MULAW), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth, extrabytes */
-                                       psf_binheader_writef (psf, "222", psf->bytewidth * psf->sf.channels, 8, 0) ;
+                                       psf_binheader_writef (psf, "222", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (8), BHW2 (0)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -763,11 +763,11 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 ;
 
                                        /* fmt : format, channels, samplerate */
-                                       psf_binheader_writef (psf, "4224", fmt_size, WAVE_FORMAT_ALAW, psf->sf.channels, psf->sf.samplerate) ;
+                                       psf_binheader_writef (psf, "4224", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_ALAW), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                                        /*  fmt : bytespersec */
-                                       psf_binheader_writef (psf, "4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                                       psf_binheader_writef (psf, "4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                                        /*  fmt : blockalign, bitwidth, extrabytes */
-                                       psf_binheader_writef (psf, "222", psf->bytewidth * psf->sf.channels, 8, 0) ;
+                                       psf_binheader_writef (psf, "222", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (8), BHW2 (0)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -784,11 +784,11 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                                fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 + 2 ;
 
                                                /* fmt : size, WAV format type, channels, samplerate, bytespersec */
-                                               psf_binheader_writef (psf, "42244", fmt_size, WAVE_FORMAT_IMA_ADPCM,
-                                                                       psf->sf.channels, psf->sf.samplerate, bytespersec) ;
+                                               psf_binheader_writef (psf, "42244", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_IMA_ADPCM),
+                                                                       BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
 
                                                /* fmt : blockalign, bitwidth, extrabytes, framesperblock. */
-                                               psf_binheader_writef (psf, "2222", blockalign, 4, 2, framesperblock) ;
+                                               psf_binheader_writef (psf, "2222", BHW2 (blockalign), BHW2 (4), BHW2 (2), BHW2 (framesperblock)) ;
                                                } ;
 
                                        add_fact_chunk = SF_TRUE ;
@@ -806,13 +806,13 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                                fmt_size        = 2 + 2 + 4 + 4 + 2 + 2 + 2 + extrabytes ;
 
                                                /* fmt : size, WAV format type, channels. */
-                                               psf_binheader_writef (psf, "422", fmt_size, WAVE_FORMAT_MS_ADPCM, psf->sf.channels) ;
+                                               psf_binheader_writef (psf, "422", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_MS_ADPCM), BHW2 (psf->sf.channels)) ;
 
                                                /* fmt : samplerate, bytespersec. */
-                                               psf_binheader_writef (psf, "44", psf->sf.samplerate, bytespersec) ;
+                                               psf_binheader_writef (psf, "44", BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
 
                                                /* fmt : blockalign, bitwidth, extrabytes, framesperblock. */
-                                               psf_binheader_writef (psf, "22222", blockalign, 4, extrabytes, framesperblock, 7) ;
+                                               psf_binheader_writef (psf, "22222", BHW2 (blockalign), BHW2 (4), BHW2 (extrabytes), BHW2 (framesperblock), BHW2 (7)) ;
 
                                                wavlike_msadpcm_write_adapt_coeffs (psf) ;
                                                } ;
@@ -826,11 +826,11 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 + 2 ;
 
                                        /* fmt : size, WAV format type, channels, samplerate, bytespersec */
-                                       psf_binheader_writef (psf, "42244", fmt_size, WAVE_FORMAT_G721_ADPCM,
-                                                               psf->sf.channels, psf->sf.samplerate, psf->sf.samplerate * psf->sf.channels / 2) ;
+                                       psf_binheader_writef (psf, "42244", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_G721_ADPCM),
+                                                               BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate), BHW4 (psf->sf.samplerate * psf->sf.channels / 2)) ;
 
                                        /* fmt : blockalign, bitwidth, extrabytes, auxblocksize. */
-                                       psf_binheader_writef (psf, "2222", 64, 4, 2, 0) ;
+                                       psf_binheader_writef (psf, "2222", BHW2 (64), BHW2 (4), BHW2 (2), BHW2 (0)) ;
 
                                        add_fact_chunk = SF_TRUE ;
                                        break ;
@@ -848,13 +848,13 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                                                fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 + 2 ;
 
                                                /* fmt : size, WAV format type, channels. */
-                                               psf_binheader_writef (psf, "422", fmt_size, WAVE_FORMAT_GSM610, psf->sf.channels) ;
+                                               psf_binheader_writef (psf, "422", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_GSM610), BHW2 (psf->sf.channels)) ;
 
                                                /* fmt : samplerate, bytespersec. */
-                                               psf_binheader_writef (psf, "44", psf->sf.samplerate, bytespersec) ;
+                                               psf_binheader_writef (psf, "44", BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
 
                                                /* fmt : blockalign, bitwidth, extrabytes, framesperblock. */
-                                               psf_binheader_writef (psf, "2222", blockalign, 0, 2, framesperblock) ;
+                                               psf_binheader_writef (psf, "2222", BHW2 (blockalign), BHW2 (0), BHW2 (2), BHW2 (framesperblock)) ;
                                                } ;
 
                                        add_fact_chunk = SF_TRUE ;
@@ -864,7 +864,7 @@ wav_write_fmt_chunk (SF_PRIVATE *psf)
                } ;
 
        if (add_fact_chunk)
-               psf_binheader_writef (psf, "tm48", fact_MARKER, 4, psf->sf.frames) ;
+               psf_binheader_writef (psf, "tm48", BHWm (fact_MARKER), BHW4 (4), BHW8 (psf->sf.frames)) ;
 
        return 0 ;
 } /* wav_write_fmt_chunk */
@@ -892,25 +892,25 @@ wavex_write_fmt_chunk (SF_PRIVATE *psf)
                        fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 + 2 + 4 + 4 + 2 + 2 + 8 ;
 
                        /* fmt : format, channels, samplerate */
-                       psf_binheader_writef (psf, "4224", fmt_size, WAVE_FORMAT_EXTENSIBLE, psf->sf.channels, psf->sf.samplerate) ;
+                       psf_binheader_writef (psf, "4224", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_EXTENSIBLE), BHW2 (psf->sf.channels), BHW4 (psf->sf.samplerate)) ;
                        /*  fmt : bytespersec */
-                       psf_binheader_writef (psf, "4", psf->sf.samplerate * psf->bytewidth * psf->sf.channels) ;
+                       psf_binheader_writef (psf, "4", BHW4 (psf->sf.samplerate * psf->bytewidth * psf->sf.channels)) ;
                        /*  fmt : blockalign, bitwidth */
-                       psf_binheader_writef (psf, "22", psf->bytewidth * psf->sf.channels, psf->bytewidth * 8) ;
+                       psf_binheader_writef (psf, "22", BHW2 (psf->bytewidth * psf->sf.channels), BHW2 (psf->bytewidth * 8)) ;
 
                        /* cbSize 22 is sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX) */
-                       psf_binheader_writef (psf, "2", 22) ;
+                       psf_binheader_writef (psf, "2", BHW2 (22)) ;
 
                        /* wValidBitsPerSample, for our use same as bitwidth as we use it fully */
-                       psf_binheader_writef (psf, "2", psf->bytewidth * 8) ;
+                       psf_binheader_writef (psf, "2", BHW2 (psf->bytewidth * 8)) ;
 
                        /* For an Ambisonic file set the channel mask to zero.
                        ** Otherwise use a default based on the channel count.
                        */
                        if (wpriv->wavex_ambisonic != SF_AMBISONIC_NONE)
-                               psf_binheader_writef (psf, "4", 0) ;
+                               psf_binheader_writef (psf, "4", BHW4 (0)) ;
                        else if (wpriv->wavex_channelmask != 0)
-                               psf_binheader_writef (psf, "4", wpriv->wavex_channelmask) ;
+                               psf_binheader_writef (psf, "4", BHW4 (wpriv->wavex_channelmask)) ;
                        else
                        {       /*
                                ** Ok some liberty is taken here to use the most commonly used channel masks
@@ -919,27 +919,27 @@ wavex_write_fmt_chunk (SF_PRIVATE *psf)
                                */
                                switch (psf->sf.channels)
                                {       case 1 :        /* center channel mono */
-                                               psf_binheader_writef (psf, "4", 0x4) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x4)) ;
                                                break ;
 
                                        case 2 :        /* front left and right */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2)) ;
                                                break ;
 
                                        case 4 :        /* Quad */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2 | 0x10 | 0x20) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2 | 0x10 | 0x20)) ;
                                                break ;
 
                                        case 6 :        /* 5.1 */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)) ;
                                                break ;
 
                                        case 8 :        /* 7.1 */
-                                               psf_binheader_writef (psf, "4", 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80)) ;
                                                break ;
 
                                        default :       /* 0 when in doubt , use direct out, ie NO mapping*/
-                                               psf_binheader_writef (psf, "4", 0x0) ;
+                                               psf_binheader_writef (psf, "4", BHW4 (0x0)) ;
                                                break ;
                                        } ;
                                } ;
@@ -986,7 +986,7 @@ wavex_write_fmt_chunk (SF_PRIVATE *psf)
                default : return SFE_UNIMPLEMENTED ;
                } ;
 
-       psf_binheader_writef (psf, "tm48", fact_MARKER, 4, psf->sf.frames) ;
+       psf_binheader_writef (psf, "tm48", BHWm (fact_MARKER), BHW4 (4), BHW8 (psf->sf.frames)) ;
 
        return 0 ;
 } /* wavex_write_fmt_chunk */
@@ -1027,12 +1027,12 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
        /* RIFF/RIFX marker, length, WAVE and 'fmt ' markers. */
 
        if (psf->endian == SF_ENDIAN_LITTLE)
-               psf_binheader_writef (psf, "etm8", RIFF_MARKER, (psf->filelength < 8) ? 8 : psf->filelength - 8) ;
+               psf_binheader_writef (psf, "etm8", BHWm (RIFF_MARKER), BHW8 ((psf->filelength < 8) ? 8 : psf->filelength - 8)) ;
        else
-               psf_binheader_writef (psf, "Etm8", RIFX_MARKER, (psf->filelength < 8) ? 8 : psf->filelength - 8) ;
+               psf_binheader_writef (psf, "Etm8", BHWm (RIFX_MARKER), BHW8 ((psf->filelength < 8) ? 8 : psf->filelength - 8)) ;
 
        /* WAVE and 'fmt ' markers. */
-       psf_binheader_writef (psf, "mm", WAVE_MARKER, fmt_MARKER) ;
+       psf_binheader_writef (psf, "mm", BHWm (WAVE_MARKER), BHWm (fmt_MARKER)) ;
 
        /* Write the 'fmt ' chunk. */
        switch (SF_CONTAINER (psf->sf.format))
@@ -1066,26 +1066,26 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
        if (psf->cues != NULL)
        {       uint32_t k ;
 
-               psf_binheader_writef (psf, "em44", cue_MARKER, 4 + psf->cues->cue_count * 6 * 4, psf->cues->cue_count) ;
+               psf_binheader_writef (psf, "em44", BHWm (cue_MARKER), BHW4 (4 + psf->cues->cue_count * 6 * 4), BHW4 (psf->cues->cue_count)) ;
 
                for (k = 0 ; k < psf->cues->cue_count ; k++)
-                       psf_binheader_writef (psf, "e44m444", psf->cues->cue_points [k].indx, psf->cues->cue_points [k].position,
-                                               psf->cues->cue_points [k].fcc_chunk, psf->cues->cue_points [k].chunk_start,
-                                               psf->cues->cue_points [k].block_start, psf->cues->cue_points [k].sample_offset) ;
+                       psf_binheader_writef (psf, "e44m444", BHW4 (psf->cues->cue_points [k].indx), BHW4 (psf->cues->cue_points [k].position),
+                                               BHWm (psf->cues->cue_points [k].fcc_chunk), BHW4 (psf->cues->cue_points [k].chunk_start),
+                                               BHW4 (psf->cues->cue_points [k].block_start), BHW4 (psf->cues->cue_points [k].sample_offset)) ;
                } ;
 
        if (psf->instrument != NULL)
        {       int             tmp ;
                double  dtune = (double) (0x40000000) / 25.0 ;
 
-               psf_binheader_writef (psf, "m4", smpl_MARKER, 9 * 4 + psf->instrument->loop_count * 6 * 4) ;
-               psf_binheader_writef (psf, "44", 0, 0) ; /* Manufacturer zero is everyone */
+               psf_binheader_writef (psf, "m4", BHWm (smpl_MARKER), BHW4 (9 * 4 + psf->instrument->loop_count * 6 * 4)) ;
+               psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (0)) ; /* Manufacturer zero is everyone */
                tmp = (int) (1.0e9 / psf->sf.samplerate) ; /* Sample period in nano seconds */
-               psf_binheader_writef (psf, "44", tmp, psf->instrument->basenote) ;
+               psf_binheader_writef (psf, "44", BHW4 (tmp), BHW4 (psf->instrument->basenote)) ;
                tmp = (uint32_t) (psf->instrument->detune * dtune + 0.5) ;
-               psf_binheader_writef (psf, "4", tmp) ;
-               psf_binheader_writef (psf, "44", 0, 0) ; /* SMTPE format */
-               psf_binheader_writef (psf, "44", psf->instrument->loop_count, 0) ;
+               psf_binheader_writef (psf, "4", BHW4 (tmp)) ;
+               psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (0)) ; /* SMTPE format */
+               psf_binheader_writef (psf, "44", BHW4 (psf->instrument->loop_count), BHW4 (0)) ;
 
                for (tmp = 0 ; tmp < psf->instrument->loop_count ; tmp++)
                {       int type ;
@@ -1093,9 +1093,9 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
                        type = psf->instrument->loops [tmp].mode ;
                        type = (type == SF_LOOP_FORWARD ? 0 : type == SF_LOOP_BACKWARD ? 2 : type == SF_LOOP_ALTERNATING ? 1 : 32) ;
 
-                       psf_binheader_writef (psf, "44", tmp, type) ;
-                       psf_binheader_writef (psf, "44", psf->instrument->loops [tmp].start, psf->instrument->loops [tmp].end - 1) ;
-                       psf_binheader_writef (psf, "44", 0, psf->instrument->loops [tmp].count) ;
+                       psf_binheader_writef (psf, "44", BHW4 (tmp), BHW4 (type)) ;
+                       psf_binheader_writef (psf, "44", BHW4 (psf->instrument->loops [tmp].start), BHW4 (psf->instrument->loops [tmp].end - 1)) ;
+                       psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (psf->instrument->loops [tmp].count)) ;
                        } ;
                } ;
 
@@ -1106,10 +1106,10 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
        if (psf->header.indx + 16 < psf->dataoffset)
        {       /* Add PAD data if necessary. */
                size_t k = psf->dataoffset - (psf->header.indx + 16) ;
-               psf_binheader_writef (psf, "m4z", PAD_MARKER, k, k) ;
+               psf_binheader_writef (psf, "m4z", BHWm (PAD_MARKER), BHW4 (k), BHWz (k)) ;
                } ;
 
-       psf_binheader_writef (psf, "tm8", data_MARKER, psf->datalength) ;
+       psf_binheader_writef (psf, "tm8", BHWm (data_MARKER), BHW8 (psf->datalength)) ;
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
        if (psf->error)
                return psf->error ;
@@ -1148,7 +1148,7 @@ wav_write_tailer (SF_PRIVATE *psf)
                psf->dataend = psf_fseek (psf, 0, SEEK_END) ;
 
        if (psf->dataend & 1)
-               psf_binheader_writef (psf, "z", 1) ;
+               psf_binheader_writef (psf, "z", BHWz (1)) ;
 
        /* Add a PEAK chunk if requested. */
        if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_END)
index 86ebf01..73b8636 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 ** Copyright (C) 2004-2005 David Viens <davidv@plogue.com>
 **
 ** This program is free software; you can redistribute it and/or modify
@@ -452,9 +452,9 @@ wavlike_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
 void
 wavlike_write_guid (SF_PRIVATE *psf, const EXT_SUBFORMAT * subformat)
 {
-       psf_binheader_writef (psf, "422b", subformat->esf_field1,
-                                       subformat->esf_field2, subformat->esf_field3,
-                                       subformat->esf_field4, make_size_t (8)) ;
+       psf_binheader_writef (psf, "422b", BHW4 (subformat->esf_field1),
+                                       BHW2 (subformat->esf_field2), BHW2 (subformat->esf_field3),
+                                       BHWv (subformat->esf_field4), BHWz (8)) ;
 } /* wavlike_write_guid */
 
 
@@ -746,11 +746,11 @@ wavlike_read_bext_chunk (SF_PRIVATE *psf, uint32_t chunksize)
                b->coding_history_size = chunksize - WAV_BEXT_MIN_CHUNK_SIZE ;
 
                /* We do not parse the coding history */
-               bytes += psf_binheader_readf (psf, "b", b->coding_history, b->coding_history_size) ;
+               bytes += psf_binheader_readf (psf, "b", BHWv (b->coding_history), BHWz (b->coding_history_size)) ;
                } ;
 
        if (bytes < chunksize)
-               psf_binheader_readf (psf, "j", chunksize - bytes) ;
+               psf_binheader_readf (psf, "j", BHWj (chunksize - bytes)) ;
 
        return 0 ;
 } /* wavlike_read_bext_chunk */
@@ -764,24 +764,24 @@ wavlike_write_bext_chunk (SF_PRIVATE *psf)
 
        b = psf->broadcast_16k ;
 
-       psf_binheader_writef (psf, "m4", bext_MARKER, WAV_BEXT_MIN_CHUNK_SIZE + b->coding_history_size) ;
+       psf_binheader_writef (psf, "m4", BHWm (bext_MARKER), BHW4 (WAV_BEXT_MIN_CHUNK_SIZE + b->coding_history_size)) ;
 
        /*
        **      Note that it is very important that the field widths of the SF_BROADCAST_INFO
        **      struct match those of the bext chunk fields.
        */
 
-       psf_binheader_writef (psf, "b", b->description, sizeof (b->description)) ;
-       psf_binheader_writef (psf, "b", b->originator, sizeof (b->originator)) ;
-       psf_binheader_writef (psf, "b", b->originator_reference, sizeof (b->originator_reference)) ;
-       psf_binheader_writef (psf, "b", b->origination_date, sizeof (b->origination_date)) ;
-       psf_binheader_writef (psf, "b", b->origination_time, sizeof (b->origination_time)) ;
-       psf_binheader_writef (psf, "442", b->time_reference_low, b->time_reference_high, b->version) ;
-       psf_binheader_writef (psf, "b", b->umid, sizeof (b->umid)) ;
-       psf_binheader_writef (psf, "z", make_size_t (190)) ;
+       psf_binheader_writef (psf, "b", BHWv (b->description), BHWz (sizeof (b->description))) ;
+       psf_binheader_writef (psf, "b", BHWv (b->originator), BHWz (sizeof (b->originator))) ;
+       psf_binheader_writef (psf, "b", BHWv (b->originator_reference), BHWz (sizeof (b->originator_reference))) ;
+       psf_binheader_writef (psf, "b", BHWv (b->origination_date), BHWz (sizeof (b->origination_date))) ;
+       psf_binheader_writef (psf, "b", BHWv (b->origination_time), BHWz (sizeof (b->origination_time))) ;
+       psf_binheader_writef (psf, "442", BHW4 (b->time_reference_low), BHW4 (b->time_reference_high), BHW2 (b->version)) ;
+       psf_binheader_writef (psf, "b", BHWv (b->umid), BHWz (sizeof (b->umid))) ;
+       psf_binheader_writef (psf, "z", BHWz (190)) ;
 
        if (b->coding_history_size > 0)
-               psf_binheader_writef (psf, "b", b->coding_history, make_size_t (b->coding_history_size)) ;
+               psf_binheader_writef (psf, "b", BHWv (b->coding_history), BHWz (b->coding_history_size)) ;
 
        return 0 ;
 } /* wavlike_write_bext_chunk */
@@ -858,36 +858,36 @@ wavlike_write_cart_chunk (SF_PRIVATE *psf)
                return -1 ;
 
        c = psf->cart_16k ;
-       psf_binheader_writef (psf, "m4", cart_MARKER, WAV_CART_MIN_CHUNK_SIZE + c->tag_text_size) ;
+       psf_binheader_writef (psf, "m4", BHWm (cart_MARKER), BHW4 (WAV_CART_MIN_CHUNK_SIZE + c->tag_text_size)) ;
        /*
        **      Note that it is very important that the field widths of the SF_CART_INFO
        **      struct match those of the cart chunk fields.
        */
-       psf_binheader_writef (psf, "b", c->version, sizeof (c->version)) ;
-       psf_binheader_writef (psf, "b", c->title, sizeof (c->title)) ;
-       psf_binheader_writef (psf, "b", c->artist, sizeof (c->artist)) ;
-       psf_binheader_writef (psf, "b", c->cut_id, sizeof (c->cut_id)) ;
-       psf_binheader_writef (psf, "b", c->client_id, sizeof (c->client_id)) ;
-       psf_binheader_writef (psf, "b", c->category, sizeof (c->category)) ;
-       psf_binheader_writef (psf, "b", c->classification, sizeof (c->classification)) ;
-       psf_binheader_writef (psf, "b", c->out_cue, sizeof (c->out_cue)) ;
-       psf_binheader_writef (psf, "b", c->start_date, sizeof (c->start_date)) ;
-       psf_binheader_writef (psf, "b", c->start_time, sizeof (c->start_time)) ;
-       psf_binheader_writef (psf, "b", c->end_date, sizeof (c->end_date)) ;
-       psf_binheader_writef (psf, "b", c->end_time, sizeof (c->end_time)) ;
-       psf_binheader_writef (psf, "b", c->producer_app_id, sizeof (c->producer_app_id)) ;
-       psf_binheader_writef (psf, "b", c->producer_app_version, sizeof (c->producer_app_version)) ;
-       psf_binheader_writef (psf, "b", c->user_def, sizeof (c->user_def)) ;
-       psf_binheader_writef (psf, "4", c->level_reference, sizeof (c->level_reference)) ;
+       psf_binheader_writef (psf, "b", BHWv (c->version), BHWz (sizeof (c->version))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->title), BHWz (sizeof (c->title))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->artist), BHWz (sizeof (c->artist))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->cut_id), BHWz (sizeof (c->cut_id))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->client_id), BHWz (sizeof (c->client_id))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->category), BHWz (sizeof (c->category))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->classification), BHWz (sizeof (c->classification))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->out_cue), BHWz (sizeof (c->out_cue))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->start_date), BHWz (sizeof (c->start_date))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->start_time), BHWz (sizeof (c->start_time))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->end_date), BHWz (sizeof (c->end_date))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->end_time), BHWz (sizeof (c->end_time))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->producer_app_id), BHWz (sizeof (c->producer_app_id))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->producer_app_version), BHWz (sizeof (c->producer_app_version))) ;
+       psf_binheader_writef (psf, "b", BHWv (c->user_def), BHWz (sizeof (c->user_def))) ;
+       psf_binheader_writef (psf, "e4", BHW4 (c->level_reference)) ;
 
        for (k = 0 ; k < ARRAY_LEN (c->post_timers) ; k++)
-               psf_binheader_writef (psf, "b4", c->post_timers [k].usage, make_size_t (4), c->post_timers [k].value) ;
+               psf_binheader_writef (psf, "b4", BHWv (c->post_timers [k].usage), BHWz (4), BHW4 (c->post_timers [k].value)) ;
 
-       psf_binheader_writef (psf, "z", sizeof (c->reserved)) ; // just write zeros, we don't have any other use for it
-       psf_binheader_writef (psf, "b", c->url, sizeof (c->url)) ;
+       psf_binheader_writef (psf, "z", BHWz (sizeof (c->reserved))) ;  // just write zeros, we don't have any other use for it
+       psf_binheader_writef (psf, "b", BHWv (c->url), BHWz (sizeof (c->url))) ;
 
        if (c->tag_text_size > 0)
-               psf_binheader_writef (psf, "b", c->tag_text, make_size_t (c->tag_text_size)) ;
+               psf_binheader_writef (psf, "b", BHWv (c->tag_text), BHWz (c->tag_text_size)) ;
 
        return 0 ;
 } /* wavlike_write_cart_chunk */
@@ -1078,7 +1078,7 @@ wavlike_write_strings (SF_PRIVATE *psf, int location)
 
        prev_head_index = psf->header.indx + 4 ;
 
-       psf_binheader_writef (psf, "m4m", LIST_MARKER, 0xBADBAD, INFO_MARKER) ;
+       psf_binheader_writef (psf, "m4m", BHWm (LIST_MARKER), BHW4 (0xBADBAD), BHWm (INFO_MARKER)) ;
 
        for (k = 0 ; k < SF_MAX_STRINGS ; k++)
        {       if (psf->strings.data [k].type == 0)
@@ -1088,39 +1088,39 @@ wavlike_write_strings (SF_PRIVATE *psf, int location)
 
                switch (psf->strings.data [k].type)
                {       case SF_STR_SOFTWARE :
-                               psf_binheader_writef (psf, "ms", ISFT_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (ISFT_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_TITLE :
-                               psf_binheader_writef (psf, "ms", INAM_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (INAM_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_COPYRIGHT :
-                               psf_binheader_writef (psf, "ms", ICOP_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (ICOP_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_ARTIST :
-                               psf_binheader_writef (psf, "ms", IART_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (IART_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_COMMENT :
-                               psf_binheader_writef (psf, "ms", ICMT_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (ICMT_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_DATE :
-                               psf_binheader_writef (psf, "ms", ICRD_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (ICRD_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_GENRE :
-                               psf_binheader_writef (psf, "ms", IGNR_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (IGNR_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_ALBUM :
-                               psf_binheader_writef (psf, "ms", IPRD_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (IPRD_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        case SF_STR_TRACKNUMBER :
-                               psf_binheader_writef (psf, "ms", ITRK_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
+                               psf_binheader_writef (psf, "ms", BHWm (ITRK_MARKER), BHWs (psf->strings.storage + psf->strings.data [k].offset)) ;
                                break ;
 
                        default :
@@ -1130,7 +1130,7 @@ wavlike_write_strings (SF_PRIVATE *psf, int location)
 
        saved_head_index = psf->header.indx ;
        psf->header.indx = prev_head_index ;
-       psf_binheader_writef (psf, "4", saved_head_index - prev_head_index - 4) ;
+       psf_binheader_writef (psf, "4", BHW4 (saved_head_index - prev_head_index - 4)) ;
        psf->header.indx = saved_head_index ;
 
 } /* wavlike_write_strings */
@@ -1184,10 +1184,10 @@ wavlike_write_peak_chunk (SF_PRIVATE * psf)
        if (psf->peak_info == NULL)
                return ;
 
-       psf_binheader_writef (psf, "m4", PEAK_MARKER, WAVLIKE_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
-       psf_binheader_writef (psf, "44", 1, time (NULL)) ;
+       psf_binheader_writef (psf, "m4", BHWm (PEAK_MARKER), BHW4 (WAVLIKE_PEAK_CHUNK_SIZE (psf->sf.channels))) ;
+       psf_binheader_writef (psf, "44", BHW4 (1), BHW4 (time (NULL))) ;
        for (k = 0 ; k < psf->sf.channels ; k++)
-               psf_binheader_writef (psf, "ft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
+               psf_binheader_writef (psf, "ft8", BHWf (psf->peak_info->peaks [k].value), BHW8 (psf->peak_info->peaks [k].position)) ;
 } /* wavlike_write_peak_chunk */
 
 /*==============================================================================
@@ -1292,6 +1292,7 @@ wavlike_write_custom_chunks (SF_PRIVATE * psf)
 {      uint32_t k ;
 
        for (k = 0 ; k < psf->wchunks.used ; k++)
-               psf_binheader_writef (psf, "m4b", (int) psf->wchunks.chunks [k].mark32, psf->wchunks.chunks [k].len, psf->wchunks.chunks [k].data, make_size_t (psf->wchunks.chunks [k].len)) ;
+               psf_binheader_writef (psf, "m4b", BHWm (psf->wchunks.chunks [k].mark32), BHW4 (psf->wchunks.chunks [k].len),
+                                                       BHWv (psf->wchunks.chunks [k].data), BHWz (psf->wchunks.chunks [k].len)) ;
 
 } /* wavlike_write_custom_chunks */
index 845cafa..4b9fc8a 100644 (file)
--- a/src/wve.c
+++ b/src/wve.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 ** Copyright (C) 2007 Reuben Thomas
 **
 ** This program is free software; you can redistribute it and/or modify
@@ -174,8 +174,8 @@ wve_write_header (SF_PRIVATE *psf, int calc_length)
 
        /* Write header. */
        datalen = psf->datalength ;
-       psf_binheader_writef (psf, "Emmmm", ALAW_MARKER, SOUN_MARKER, DFIL_MARKER, ESSN_MARKER) ;
-       psf_binheader_writef (psf, "E2422222", PSION_VERSION, datalen, 0, 0, 0, 0, 0) ;
+       psf_binheader_writef (psf, "Emmmm", BHWm (ALAW_MARKER), BHWm (SOUN_MARKER), BHWm (DFIL_MARKER), BHWm (ESSN_MARKER)) ;
+       psf_binheader_writef (psf, "E2422222", BHW2 (PSION_VERSION), BHW4 (datalen), BHW2 (0), BHW2 (0), BHW2 (0), BHW2 (0), BHW2 (0)) ;
        psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
 
        if (psf->sf.channels != 1)
index 17d6277..9995389 100644 (file)
--- a/src/xi.c
+++ b/src/xi.c
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2003-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2003-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -285,32 +285,32 @@ xi_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
        psf_fseek (psf, 0, SEEK_SET) ;
 
        string = "Extended Instrument: " ;
-       psf_binheader_writef (psf, "b", string, strlen (string)) ;
-       psf_binheader_writef (psf, "b1", pxi->filename, sizeof (pxi->filename), 0x1A) ;
+       psf_binheader_writef (psf, "b", BHWv (string), BHWz (strlen (string))) ;
+       psf_binheader_writef (psf, "b1", BHWv (pxi->filename), BHWz (sizeof (pxi->filename)), BHW1 (0x1A)) ;
 
        /* Write software version and two byte XI version. */
-       psf_binheader_writef (psf, "eb2", pxi->software, sizeof (pxi->software), (1 << 8) + 2) ;
+       psf_binheader_writef (psf, "eb2", BHWv (pxi->software), BHWz (sizeof (pxi->software)), BHW2 ((1 << 8) + 2)) ;
 
        /*
        ** Jump note numbers (96), volume envelope (48), pan envelope (48),
        ** volume points (1), pan points (1)
        */
-       psf_binheader_writef (psf, "z", (size_t) (96 + 48 + 48 + 1 + 1)) ;
+       psf_binheader_writef (psf, "z", BHWz ((size_t) (96 + 48 + 48 + 1 + 1))) ;
 
        /* Jump volume loop (3 bytes), pan loop (3), envelope flags (3), vibrato (3)
        ** fade out (2), 22 unknown bytes, and then write sample_count (2 bytes).
        */
-       psf_binheader_writef (psf, "ez2z2", (size_t) (4 * 3), 0x1234, make_size_t (22), 1) ;
+       psf_binheader_writef (psf, "ez2z2", BHWz ((size_t) (4 * 3)), BHW2 (0x1234), BHWz (22), BHW2 (1)) ;
 
        pxi->loop_begin = 0 ;
        pxi->loop_end = 0 ;
 
-       psf_binheader_writef (psf, "et844", psf->sf.frames, pxi->loop_begin, pxi->loop_end) ;
+       psf_binheader_writef (psf, "et844", BHW8 (psf->sf.frames), BHW4 (pxi->loop_begin), BHW4 (pxi->loop_end)) ;
 
        /* volume, fine tune, flags, pan, note, namelen */
-       psf_binheader_writef (psf, "111111", 128, 0, pxi->sample_flags, 128, 0, strlen (pxi->sample_name)) ;
+       psf_binheader_writef (psf, "111111", BHW1 (128), BHW1 (0), BHW1 (pxi->sample_flags), BHW1 (128), BHW1 (0), BHW1 (strlen (pxi->sample_name))) ;
 
-       psf_binheader_writef (psf, "b", pxi->sample_name, sizeof (pxi->sample_name)) ;
+       psf_binheader_writef (psf, "b", BHWv (pxi->sample_name), BHWz (sizeof (pxi->sample_name))) ;