openalbridge/common.h
author nemo
Thu, 15 Oct 2009 15:33:43 +0000
changeset 2452 a6edc408a376
parent 2445 5033848d3afa
child 2454 c8b1fb10003c
permissions -rw-r--r--
Remove sprFlake from set of clamped textures
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
5033848d3afa committing some missing files
koda
parents:
diff changeset
    20
#ifndef COMMON_H
5033848d3afa committing some missing files
koda
parents:
diff changeset
    21
#define COMMON_H
5033848d3afa committing some missing files
koda
parents:
diff changeset
    22
5033848d3afa committing some missing files
koda
parents:
diff changeset
    23
#include <stdio.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    24
#include <stdlib.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    25
#include <stdint.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    26
#include <string.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    27
#include <stdarg.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    28
#include <errno.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    29
#include "al.h"
5033848d3afa committing some missing files
koda
parents:
diff changeset
    30
#include "errlib.h"
5033848d3afa committing some missing files
koda
parents:
diff changeset
    31
5033848d3afa committing some missing files
koda
parents:
diff changeset
    32
#ifndef _WIN32
5033848d3afa committing some missing files
koda
parents:
diff changeset
    33
#include <pthread.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    34
#include <syslog.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    35
#else
5033848d3afa committing some missing files
koda
parents:
diff changeset
    36
#include <process.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    37
#define syslog(x,y) fprintf(stderr,y)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    38
#define LOG_INFO 6
5033848d3afa committing some missing files
koda
parents:
diff changeset
    39
#define LOG_ERR 3
5033848d3afa committing some missing files
koda
parents:
diff changeset
    40
#endif
5033848d3afa committing some missing files
koda
parents:
diff changeset
    41
5033848d3afa committing some missing files
koda
parents:
diff changeset
    42
/* magics */
5033848d3afa committing some missing files
koda
parents:
diff changeset
    43
#define OGG_FILE_FORMAT 0x4F676753
5033848d3afa committing some missing files
koda
parents:
diff changeset
    44
#define WAV_FILE_FORMAT 0x52494646
5033848d3afa committing some missing files
koda
parents:
diff changeset
    45
#define WAV_HEADER_SUBCHUNK2ID 0x64617461
5033848d3afa committing some missing files
koda
parents:
diff changeset
    46
5033848d3afa committing some missing files
koda
parents:
diff changeset
    47
#define MAX_SOUNDS 1024
5033848d3afa committing some missing files
koda
parents:
diff changeset
    48
#define MAX_SOURCES 16
5033848d3afa committing some missing files
koda
parents:
diff changeset
    49
5033848d3afa committing some missing files
koda
parents:
diff changeset
    50
/* check compiler requirements */    /*FIXME*/
5033848d3afa committing some missing files
koda
parents:
diff changeset
    51
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    52
#warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default
5033848d3afa committing some missing files
koda
parents:
diff changeset
    53
#define __LITTLE_ENDIAN__ 1
5033848d3afa committing some missing files
koda
parents:
diff changeset
    54
//#error Do not know the endianess of this architecture
5033848d3afa committing some missing files
koda
parents:
diff changeset
    55
#endif
5033848d3afa committing some missing files
koda
parents:
diff changeset
    56
5033848d3afa committing some missing files
koda
parents:
diff changeset
    57
/* use byteswap macros from the host system, hopefully optimized ones ;-) 
5033848d3afa committing some missing files
koda
parents:
diff changeset
    58
 * or define our own version, simple, stupid, straight-forward... */
5033848d3afa committing some missing files
koda
parents:
diff changeset
    59
#ifdef HAVE_BYTESWAP_H
5033848d3afa committing some missing files
koda
parents:
diff changeset
    60
#include <byteswap.h>
5033848d3afa committing some missing files
koda
parents:
diff changeset
    61
#else        
5033848d3afa committing some missing files
koda
parents:
diff changeset
    62
#define bswap_16(x)	((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
5033848d3afa committing some missing files
koda
parents:
diff changeset
    63
#define bswap_32(x)	((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8)  | \
5033848d3afa committing some missing files
koda
parents:
diff changeset
    64
                         (((x) & 0x0000FF00) << 8)  | (((x) & 0x000000FF) << 24) )
5033848d3afa committing some missing files
koda
parents:
diff changeset
    65
#endif /* HAVE_BYTESWAP_H */
5033848d3afa committing some missing files
koda
parents:
diff changeset
    66
5033848d3afa committing some missing files
koda
parents:
diff changeset
    67
/* swap numbers accordingly to architecture automatically */
5033848d3afa committing some missing files
koda
parents:
diff changeset
    68
#ifdef __LITTLE_ENDIAN__
5033848d3afa committing some missing files
koda
parents:
diff changeset
    69
#define ENDIAN_LITTLE_32(x) x
5033848d3afa committing some missing files
koda
parents:
diff changeset
    70
#define ENDIAN_BIG_32(x)    bswap_32(x)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    71
#define ENDIAN_LITTLE_16(x) x
5033848d3afa committing some missing files
koda
parents:
diff changeset
    72
#define ENDIAN_BIG_16(x)    bswap_16(x)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    73
#elif __BIG_ENDIAN__
5033848d3afa committing some missing files
koda
parents:
diff changeset
    74
#define ENDIAN_LITTLE_32(x) bswap_32(x)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    75
#define ENDIAN_BIG_32(x)    x
5033848d3afa committing some missing files
koda
parents:
diff changeset
    76
#define ENDIAN_LITTLE_16(x) bswap_16(x)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    77
#define ENDIAN_BIG_16(x)    x    
5033848d3afa committing some missing files
koda
parents:
diff changeset
    78
#endif
5033848d3afa committing some missing files
koda
parents:
diff changeset
    79
5033848d3afa committing some missing files
koda
parents:
diff changeset
    80
#pragma pack(1)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    81
typedef struct _WAV_header_t {
5033848d3afa committing some missing files
koda
parents:
diff changeset
    82
        uint32_t ChunkID;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    83
        uint32_t ChunkSize;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    84
        uint32_t Format;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    85
        uint32_t Subchunk1ID;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    86
        uint32_t Subchunk1Size;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    87
        uint16_t AudioFormat;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    88
        uint16_t NumChannels;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    89
        uint32_t SampleRate;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    90
        uint32_t ByteRate;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    91
        uint16_t BlockAlign;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    92
        uint16_t BitsPerSample;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    93
        uint32_t Subchunk2ID;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    94
        uint32_t Subchunk2Size;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    95
} WAV_header_t;
5033848d3afa committing some missing files
koda
parents:
diff changeset
    96
#pragma pack()
5033848d3afa committing some missing files
koda
parents:
diff changeset
    97
5033848d3afa committing some missing files
koda
parents:
diff changeset
    98
#pragma pack(1)
5033848d3afa committing some missing files
koda
parents:
diff changeset
    99
typedef struct _SSound_t {
5033848d3afa committing some missing files
koda
parents:
diff changeset
   100
        int source;
5033848d3afa committing some missing files
koda
parents:
diff changeset
   101
        char Filename[256];
5033848d3afa committing some missing files
koda
parents:
diff changeset
   102
        ALuint Buffer;
5033848d3afa committing some missing files
koda
parents:
diff changeset
   103
} SSound_t;
5033848d3afa committing some missing files
koda
parents:
diff changeset
   104
#pragma pack()
5033848d3afa committing some missing files
koda
parents:
diff changeset
   105
5033848d3afa committing some missing files
koda
parents:
diff changeset
   106
#endif
5033848d3afa committing some missing files
koda
parents:
diff changeset
   107