r663: This commit was generated by cvs2svn to compensate for changes in r662,
[cinelerra_cv.git] / libsndfile / src / sfendian.c
blob0f2b5c213e1636e669af763755dfadaacdb01e40
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 "sfendian.h"
21 /*-----------------------------------------------------------------------------------------------
22 ** Generic functions for performing endian swapping on integer arrays.
25 void
26 endswap_short_array (short *ptr, int len)
29 #if 0
30 unsigned char *ucptr, temp ;
32 ucptr = ((unsigned char *) ptr) + 2 * len ;
33 while (len > 0)
34 { len -- ;
35 ucptr -= 2 ;
36 temp = ucptr [0] ;
37 ucptr [0] = ucptr [1] ;
38 ucptr [1] = temp ;
39 } ;
40 #else
41 short temp ;
42 while (len > 0)
43 { len -- ;
44 temp = ptr [len] ;
45 ptr [len] = ENDSWAP_SHORT (temp) ;
47 #endif
48 } /* endswap_short_array */
50 void
51 endswap_int_array (int *ptr, int len)
53 #if 0
54 unsigned char *ucptr, temp ;
56 ucptr = ((unsigned char *) ptr) + 4 * len ;
57 while (len > 0)
58 { len -- ;
59 ucptr -= 4 ;
61 temp = ucptr [0] ;
62 ucptr [0] = ucptr [3] ;
63 ucptr [3] = temp ;
65 temp = ucptr [1] ;
66 ucptr [1] = ucptr [2] ;
67 ucptr [2] = temp ;
68 } ;
69 #else
70 int temp ;
72 while (len > 0)
73 { len -- ;
74 temp = ptr [len] ;
75 ptr [len] = ENDSWAP_INT (temp) ;
76 } ;
77 #endif
78 } /* endswap_int_array */
80 /* This function assumes that sizeof (long) == 8, but works correctly even
81 ** is sizeof (long) == 4.
83 void
84 endswap_long_array (long *ptr, int len)
85 { unsigned char *ucptr, temp ;
87 ucptr = (unsigned char *) ptr + 8 * len ;
88 while (len > 0)
89 { len -- ;
90 ucptr -= 8 ;
92 temp = ucptr [0] ;
93 ucptr [0] = ucptr [7] ;
94 ucptr [7] = temp ;
96 temp = ucptr [1] ;
97 ucptr [1] = ucptr [6] ;
98 ucptr [6] = temp ;
100 temp = ucptr [2] ;
101 ucptr [2] = ucptr [5] ;
102 ucptr [5] = temp ;
104 temp = ucptr [3] ;
105 ucptr [3] = ucptr [4] ;
106 ucptr [4] = temp ;
108 } /* endswap_long_array */
110 /*========================================================================================
113 void
114 endswap_short_copy (short *dest, short *src, int len)
116 #if 0
117 char *psrc, *pdest ;
119 psrc = ((char *) src) + 2 * len ;
120 pdest = ((char *) dest) + 2 * len ;
121 while (len > 0)
122 { len -- ;
123 psrc -= 2 ;
124 pdest -= 2 ;
126 pdest [0] = psrc [1] ;
127 pdest [1] = psrc [0] ;
129 #else
130 while (len > 0)
131 { len -- ;
132 dest [len] = ENDSWAP_SHORT (src [len]) ;
134 #endif
135 } /* endswap_short_copy */
137 void
138 endswap_int_copy (int *dest, int *src, int len)
140 #if 0
141 char *psrc, *pdest ;
143 psrc = ((char *) src) + 4 * len ;
144 pdest = ((char *) dest) + 4 * len ;
145 while (len > 0)
146 { len -- ;
147 psrc -= 4 ;
148 pdest -= 4 ;
150 pdest [0] = psrc [3] ;
151 pdest [1] = psrc [2] ;
152 pdest [2] = psrc [1] ;
153 pdest [3] = psrc [0] ;
155 #else
156 while (len > 0)
157 { len -- ;
158 dest [len] = ENDSWAP_INT (src [len]) ;
160 #endif
161 } /* endswap_int_copy */
163 /* This function assumes that sizeof (long) == 8, but works correctly even
164 ** is sizeof (long) == 4.
166 void
167 endswap_long_copy (long *dest, long *src, int len)
168 { char *psrc, *pdest ;
170 psrc = (char *) src + 8 * len ;
171 pdest = (char *) dest + 8 * len ;
172 while (len > 0)
173 { len -- ;
174 psrc -= 8 ;
175 pdest -= 8 ;
177 pdest [0] = psrc [7] ;
178 pdest [1] = psrc [6] ;
179 pdest [2] = psrc [5] ;
180 pdest [3] = psrc [4] ;
181 pdest [4] = psrc [3] ;
182 pdest [5] = psrc [2] ;
183 pdest [6] = psrc [1] ;
184 pdest [7] = psrc [0] ;
186 } /* endswap_long_copy */