r663: This commit was generated by cvs2svn to compensate for changes in r662,
[cinelerra_cv.git] / libsndfile / src / sfendian.h
blob8dca717c5f1890d3b14e3f48d2bdcdcb1d57ec85
1 /*
2 ** Copyright (C) 1999-2003 Erik de Castro Lopo <erikd@zip.com.au>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "config.h"
21 /*
22 ** Many file types (ie WAV, AIFF) use sets of four consecutive bytes as a
23 ** marker indicating different sections of the file.
24 ** The following MAKE_MARKER macro allows th creation of integer constants
25 ** for these markers.
28 #if (CPU_IS_LITTLE_ENDIAN == 1)
29 #define MAKE_MARKER(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
30 #elif (CPU_IS_BIG_ENDIAN == 1)
31 #define MAKE_MARKER(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
32 #else
33 #error "Target CPU endian-ness unknown. May need to hand edit src/config.h"
34 #endif
36 /* wo standard endswap macros. */
38 #define ENDSWAP_SHORT(x) ((((x)>>8)&0xFF)+(((x)&0xFF)<<8))
39 #define ENDSWAP_INT(x) ((((x)>>24)&0xFF)+(((x)>>8)&0xFF00)+(((x)&0xFF00)<<8)+(((x)&0xFF)<<24))
41 ** Macros to handle reading of data of a specific endian-ness into host endian
42 ** shorts and ints. The single input is an unsigned char* pointer to the start
43 ** of the object. There are two versions of each macro as we need to deal with
44 ** both big and little endian CPUs.
47 #if (CPU_IS_LITTLE_ENDIAN == 1)
48 #define LES2H_SHORT(x) (x)
49 #define LEI2H_INT(x) (x)
51 #define LES2H_SHORT_PTR(x) (((short*) x) [0])
52 #define LES2H_INT_PTR(x) ((((short*) x) [0]) << 16)
54 #define LET2H_SHORT_PTR(x) ((x) [1] + ((x) [2] << 8))
55 #define LET2H_INT_PTR(x) (((x) [0] << 8) + ((x) [1] << 16) + ((x) [2] << 24))
57 #define LEI2H_SHORT_PTR(x) ((((int*) x) [0]) >> 16)
58 #define LEI2H_INT_PTR(x) (((int*) x) [0])
60 #define BES2H_SHORT(x) ENDSWAP_SHORT(x)
61 #define BEI2H_INT(x) ENDSWAP_INT(x)
63 #define BES2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
64 #define BES2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16))
66 #define BET2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
67 #define BET2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16) + ((x) [2] << 8))
69 #define BEI2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
70 #define BEI2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16) + ((x) [2] << 8) + (x) [3])
72 #elif (CPU_IS_BIG_ENDIAN == 1)
73 #define LES2H_SHORT(x) ENDSWAP_SHORT(x)
74 #define LEI2H_INT(x) ENDSWAP_INT(x)
76 #define LES2H_SHORT_PTR(x) ((x) [0] + ((x) [1] << 8))
77 #define LES2H_INT_PTR(x) (((x) [0] << 16) + ((x) [1] << 24))
79 #define LET2H_SHORT_PTR(x) ((x) [1] + ((x) [2] << 8))
80 #define LET2H_INT_PTR(x) (((x) [0] << 8) + ((x) [1] << 16) + ((x) [2] << 24))
82 #define LEI2H_SHORT_PTR(x) ((x) [2] + ((x) [3] << 8))
83 #define LEI2H_INT_PTR(x) ((x) [0] + ((x) [1] << 8) + ((x) [2] << 16) + ((x) [3] << 24))
85 #define BES2H_SHORT(x) (x)
86 #define BEI2H_INT(x) (x)
88 #define BES2H_SHORT_PTR(x) (((short*) x) [0])
89 #define BES2H_INT_PTR(x) ((((short*) x) [0]) << 16)
91 #define BET2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
92 #define BET2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16) + ((x) [2] << 8))
94 #define BEI2H_SHORT_PTR(x) ((((int*) x) [0]) >> 16)
95 #define BEI2H_INT_PTR(x) (((int*) x) [0])
97 #else
98 #error "Target CPU endian-ness unknown. May need to hand edit src/config.h"
99 #endif
101 /* Endian swapping routines implemented in sfendian.c. */
103 void endswap_short_array (short *ptr, int len) ;
104 void endswap_int_array (int *ptr, int len) ;
106 /* Always swaps 8 byte values whether sizeof (long) == 8 or not. */
107 void endswap_long_array (long *ptr, int len) ;
109 void endswap_short_copy (short *dest, short *src, int len) ;
110 void endswap_int_copy (int *dest, int *src, int len) ;
112 /* Always swaps 8 byte values whether sizeof (long) == 8 or not. */
113 void endswap_long_copy (long *dest, long *src, int len) ;