Edinburgh Speech Tools  2.1-release
EST_swapping.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author : Alan Black */
34 /* Date : June 1996 */
35 /*-----------------------------------------------------------------------*/
36 /* General byte swapping routines */
37 /*************************************************************************/
38 
39 #include "EST_cutils.h"
40 
41 /* For endian tests */
43 
44 void swapdouble(double *d)
45 {
46  int *ii = (int *)d;
47  int t;
48  t = SWAPINT(ii[0]);
49  ii[0] = SWAPINT(ii[1]);
50  ii[1] = t;
51 }
52 
53 void swapfloat(float *f)
54 {
55  int *ii = (int *)f;
56  ii[0] = SWAPINT(ii[0]);
57 }
58 
59 void swap_bytes_float(float *data, int length)
60 {
61  /* Swap floats in an array */
62  int i;
63 
64  for (i=0; i<length; i++)
65  swapfloat(&data[i]);
66 }
67 
68 void swap_bytes_double(double *data, int length)
69 {
70  /* Swap doubles in an array */
71  int i;
72 
73  for (i=0; i<length; i++)
74  swapdouble(&data[i]);
75 }
76 
77 void swap_bytes_int(int *data, int length)
78 {
79  /* Swap ints in an array */
80  int i;
81 
82  for (i=0; i<length; i++)
83  data[i] = SWAPINT(data[i]);
84 
85 }
86 
87 void swap_bytes_uint(unsigned int *data, int length)
88 {
89  /* Swap ints in an array */
90  int i;
91 
92  for (i=0; i<length; i++)
93  data[i] = SWAPINT(data[i]);
94 
95 }
96 
97 void swap_bytes_short(short *data, int length)
98 {
99  /* Swap shorts in an array */
100  int i;
101 
102  for (i=0; i<length; i++)
103  data[i] = SWAPSHORT(data[i]);
104 
105 }
106 
107 void swap_bytes_ushort(unsigned short *data, int length)
108 {
109  /* Swap shorts in an array */
110  int i;
111 
112  for (i=0; i<length; i++)
113  data[i] = SWAPSHORT(data[i]);
114 
115 }
116 
#define SWAPSHORT(x)
Definition: EST_cutils.h:79
#define SWAPINT(x)
Definition: EST_cutils.h:75
void swap_bytes_float(float *data, int length)
Definition: EST_swapping.cc:59
void swap_bytes_uint(unsigned int *data, int length)
Definition: EST_swapping.cc:87
void swapfloat(float *f)
Definition: EST_swapping.cc:53
void swap_bytes_int(int *data, int length)
Definition: EST_swapping.cc:77
void swap_bytes_short(short *data, int length)
Definition: EST_swapping.cc:97
int est_endian_loc
Definition: EST_swapping.cc:42
f
Definition: EST_item_aux.cc:48
void swap_bytes_ushort(unsigned short *data, int length)
void swap_bytes_double(double *data, int length)
Definition: EST_swapping.cc:68
void swapdouble(double *d)
Definition: EST_swapping.cc:44