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