File: endian.c

package info (click to toggle)
gramofile 1.6-11
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,436 kB
  • ctags: 1,125
  • sloc: ansic: 11,252; makefile: 60
file content (44 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (2)
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_int32_t
SwapFourBytes (u_int32_t dw)
{
  register u_int32_t 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);
}