openalbridge/common.h
changeset 2529 51e5df1c8462
parent 2528 a1e0306b9cd1
child 2530 5a11abbbdac8
equal deleted inserted replaced
2528:a1e0306b9cd1 2529:51e5df1c8462
     1 /*
       
     2  * OpenAL Bridge - a simple portable library for OpenAL interface
       
     3  * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>,
       
     4  *                    Mario Liebisch <mario.liebisch+hw@googlemail.com>
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU Lesser General Public License as published by
       
     8  * the Free Software Foundation; version 2 of the License
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    18  */
       
    19 
       
    20 
       
    21 #ifndef _COMMON_H
       
    22 #define _COMMON_H
       
    23 
       
    24 #include <stdio.h>
       
    25 #include <stdlib.h>
       
    26 #include <stdint.h>
       
    27 #include <string.h>
       
    28 #include <stdarg.h>
       
    29 #include <errno.h>
       
    30 #include "al.h"
       
    31 #include "errlib.h"
       
    32 
       
    33 #ifndef _WIN32
       
    34 #include <pthread.h>
       
    35 #include <syslog.h>
       
    36 #else
       
    37 #include <process.h>
       
    38 #define syslog(x,y) fprintf(stderr,y)
       
    39 #define LOG_INFO 6
       
    40 #define LOG_ERR 3
       
    41 #endif
       
    42 
       
    43 
       
    44 /* magics */
       
    45 #define OGG_FILE_FORMAT 0x4F676753
       
    46 #define WAV_FILE_FORMAT 0x52494646
       
    47 #define WAV_HEADER_SUBCHUNK2ID 0x64617461
       
    48 
       
    49 /* max allocations */
       
    50 #define MAX_SOUNDS 1024
       
    51 #define MAX_SOURCES 16
       
    52 
       
    53 /* check compiler requirements */    /*FIXME*/
       
    54 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
       
    55 #warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default
       
    56 #define __LITTLE_ENDIAN__ 1
       
    57 //#error Do not know the endianess of this architecture
       
    58 #endif
       
    59 
       
    60 /* use byteswap macros from the host system, hopefully optimized ones ;-) 
       
    61  * or define our own version, simple, stupid, straight-forward... */
       
    62 #ifdef HAVE_BYTESWAP_H
       
    63 #include <byteswap.h>
       
    64 #else        
       
    65 #define bswap_16(x)	((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
       
    66 #define bswap_32(x)	((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8)  | \
       
    67                          (((x) & 0x0000FF00) << 8)  | (((x) & 0x000000FF) << 24) )
       
    68 #endif /* HAVE_BYTESWAP_H */
       
    69 
       
    70 /* swap numbers accordingly to architecture automatically */
       
    71 #ifdef __LITTLE_ENDIAN__
       
    72 #define ENDIAN_LITTLE_32(x) x
       
    73 #define ENDIAN_BIG_32(x)    bswap_32(x)
       
    74 #define ENDIAN_LITTLE_16(x) x
       
    75 #define ENDIAN_BIG_16(x)    bswap_16(x)
       
    76 #elif __BIG_ENDIAN__
       
    77 #define ENDIAN_LITTLE_32(x) bswap_32(x)
       
    78 #define ENDIAN_BIG_32(x)    x
       
    79 #define ENDIAN_LITTLE_16(x) bswap_16(x)
       
    80 #define ENDIAN_BIG_16(x)    x    
       
    81 #endif
       
    82 
       
    83 /** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. [Wu Yongwei] **/
       
    84 #ifndef _SLEEP_H
       
    85 #define _SLEEP_H
       
    86 #ifdef _WIN32
       
    87 # if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__))
       
    88 #  include <stdlib.h>
       
    89 #  define sleep(t) _sleep((t) * 1000)
       
    90 # else
       
    91 #  define WIN32_LEAN_AND_MEAN
       
    92 #  include <windows.h>
       
    93 #  define sleep(t)  Sleep((t) * 1000)
       
    94 # endif
       
    95 # ifndef _NEED_SLEEP_ONLY
       
    96 #  define msleep(t) Sleep(t)
       
    97 #  define usleep(t) Sleep((t) / 1000)
       
    98 # endif
       
    99 #else
       
   100 # include <unistd.h>
       
   101 # ifndef _NEED_SLEEP_ONLY
       
   102 #  define msleep(t) usleep((t) * 1000)
       
   103 # endif
       
   104 #endif
       
   105 #endif /* _SLEEP_H */
       
   106 
       
   107 #pragma pack(1)
       
   108 typedef struct _WAV_header_t {
       
   109         uint32_t ChunkID;
       
   110         uint32_t ChunkSize;
       
   111         uint32_t Format;
       
   112         uint32_t Subchunk1ID;
       
   113         uint32_t Subchunk1Size;
       
   114         uint16_t AudioFormat;
       
   115         uint16_t NumChannels;
       
   116         uint32_t SampleRate;
       
   117         uint32_t ByteRate;
       
   118         uint16_t BlockAlign;
       
   119         uint16_t BitsPerSample;
       
   120         uint32_t Subchunk2ID;
       
   121         uint32_t Subchunk2Size;
       
   122 } WAV_header_t;
       
   123 #pragma pack()
       
   124 
       
   125 #pragma pack(1)
       
   126 typedef struct _SSound_t {
       
   127         int isLoaded;
       
   128         int sourceIndex;
       
   129         char *filename;
       
   130         ALuint Buffer;
       
   131 } SSound_t;
       
   132 #pragma pack()
       
   133 
       
   134 /*data type for passing data between threads*/
       
   135 #pragma pack(1)
       
   136 typedef struct _fade_t {
       
   137         uint32_t index;
       
   138         uint16_t quantity;
       
   139 } fade_t;
       
   140 #pragma pack()
       
   141 
       
   142 #define FADE_IN  0
       
   143 #define FADE_OUT 1
       
   144 
       
   145 #endif /* _COMMON_H*/