~ubuntu-branches/ubuntu/karmic/muse/karmic-proposed

« back to all changes in this revision

Viewing changes to sf/sfendian.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//  $Id: sfendian.h,v 1.2 2001/11/20 15:19:34 muse Exp $
 
5
//
 
6
//  (C) Copyright 2001 Werner Schweer (ws@seh.de)
 
7
//  based on libsndfile:
 
8
//  Copyright (C) 1999-2000 Erik de Castro Lopo <erikd@zip.com.au>
 
9
//=========================================================
 
10
 
 
11
#include        <endian.h>
 
12
        #if (__BYTE_ORDER == __LITTLE_ENDIAN)
 
13
                #define CPU_IS_LITTLE_ENDIAN            1
 
14
                #define CPU_IS_BIG_ENDIAN                       0
 
15
        #elif (__BYTE_ORDER == __BIG_ENDIAN)
 
16
                #define CPU_IS_LITTLE_ENDIAN            0
 
17
                #define CPU_IS_BIG_ENDIAN                       1
 
18
        #else
 
19
                #error "A bit confused about endian-ness! Have <endian.h> but not __BYTEORDER."
 
20
        #endif
 
21
 
 
22
#define         ENDSWAP_SHORT(x)                        ((((x)>>8)&0xFF)|(((x)&0xFF)<<8))
 
23
#define         ENDSWAP_INT(x)                          ((((x)>>24)&0xFF)|(((x)>>8)&0xFF00)|(((x)&0xFF00)<<8)|(((x)&0xFF)<<24))
 
24
 
 
25
#if (CPU_IS_LITTLE_ENDIAN == 1)
 
26
        #define H2LE_SHORT(x)                           (x)
 
27
        #define H2LE_INT(x)                                     (x)
 
28
        #define LE2H_SHORT(x)                           (x)
 
29
        #define LE2H_INT(x)                                     (x)
 
30
 
 
31
        #define BE2H_INT(x)                                     ENDSWAP_INT(x)
 
32
        #define BE2H_SHORT(x)                           ENDSWAP_SHORT(x)
 
33
        #define H2BE_INT(x)                                     ENDSWAP_INT(x)
 
34
        #define H2BE_SHORT(x)                           ENDSWAP_SHORT(x)
 
35
 
 
36
#elif (CPU_IS_BIG_ENDIAN == 1)
 
37
        #define H2LE_SHORT(x)                           ENDSWAP_SHORT(x)
 
38
        #define H2LE_INT(x)                                     ENDSWAP_INT(x)
 
39
        #define LE2H_SHORT(x)                           ENDSWAP_SHORT(x)
 
40
        #define LE2H_INT(x)                                     ENDSWAP_INT(x)
 
41
 
 
42
        #define BE2H_INT(x)                                     (x)
 
43
        #define BE2H_SHORT(x)                           (x)
 
44
        #define H2BE_INT(x)                                     (x)
 
45
        #define H2BE_SHORT(x)                           (x)
 
46
 
 
47
#else
 
48
        #error "Cannot determine endian-ness of processor."
 
49
#endif
 
50