File: endian.c

package info (click to toggle)
gramofile 1.6-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 840 kB
  • ctags: 538
  • sloc: ansic: 10,238; makefile: 55
file content (44 lines) | stat: -rw-r--r-- 906 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*  Stolen from examples on the web          */
/*  Joshua Weage  gte855f@prism.gatech.edu   */
/*  Switches endianness                      */

#include <sys/types.h>
#include "signpr_general.h"
#include "endian.h"

u_short
SwapTwoBytes (u_short w)
{
  register u_short tmp;
  tmp = (w & 0x00FF);
  tmp = ((w & 0xFF00) >> 0x08) | (tmp << 0x08);
  return (tmp);
}

short
SwapTwo (short w)
{
  register short tmp;
  tmp = (w & 0x00FF);
  tmp = ((w & 0xFF00) >> 0x08) | (tmp << 0x08);
  return (tmp);
}

u_long
SwapFourBytes (u_long dw)
{
  register u_long tmp;
  tmp = (dw & 0x000000FF);
  tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08);
  tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08);
  tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08);
  return (tmp);
}

sample_t
SwapSample (sample_t sample)
{
  sample.left = SwapTwo (sample.left);
  sample.right = SwapTwo (sample.right);
  return (sample);
}