misc/openalbridge/openalbridge.c
author koda
Mon, 19 Apr 2010 15:30:11 +0000
changeset 3360 717b4e46e855
parent 3356 3ae3fccb439e
child 3361 cfc6cd502f85
permissions -rw-r--r--
updates to openalbridge (modified api and simplified some sections)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     1
/*
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     2
 * OpenAL Bridge - a simple portable library for OpenAL interface
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     3
 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     4
 *
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     6
 * it under the terms of the GNU Lesser General Public License as published by
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     8
 *
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    12
 * GNU Lesser General Public License for more details.
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    13
 *
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU Lesser General Public License
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    17
 */
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    18
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    19
#include "openalbridge.h"
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    20
#include "globals.h"
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    21
#include "wrappers.h"
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    22
#include "alc.h"
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    23
#include "loaders.h"
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    24
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    25
#ifdef __CPLUSPLUS
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    26
extern "C" {
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    27
#endif 
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    28
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    29
    /*Sources are points emitting sound*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    30
    ALuint *Sources;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    31
    /*Buffers hold sound data*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    32
    ALuint *Buffers;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    33
    /*index for Sources and Buffers*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    34
    ALuint globalindex, globalsize, increment;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    35
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    36
    ALboolean openalReady = AL_FALSE;
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    37
    ALfloat old_gain;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    38
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    39
    ALboolean openal_init(ALboolean usehardware, int memorysize) {	
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    40
        /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    41
        ALCcontext *context;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    42
        ALCdevice *device;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    43
        const ALCchar *default_device;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    44
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    45
        prog = "OpenAL subsystem";
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    46
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    47
	// set the memory dimentsion and the increment width when reallocating
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    48
        if (memorysize <= 0)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    49
            globalsize = 50;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    50
        else
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    51
            globalsize = memorysize;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    52
        increment = globalsize;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    53
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    54
	// reuse old context but keep the new value for increment
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    55
        if (openalReady == AL_TRUE) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    56
            err_msg("(%s) WARN - already initialized", prog);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    57
            return AL_FALSE;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    58
        }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    59
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    60
        if (usehardware == AL_TRUE)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    61
            device = alcOpenDevice(NULL);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    62
        else
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    63
            device = alcOpenDevice("Generic Software");
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    64
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    65
        err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER));
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    66
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    67
	if (device == NULL) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    68
            errno = ENODEV;                
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    69
            err_ret("(%s) WARN - failed to open sound device", prog);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    70
            return AL_FALSE;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    71
        }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    72
	
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    73
        context = alcCreateContext(device, NULL);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    74
        alcMakeContextCurrent(context);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    75
        alcProcessContext(context);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    76
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    77
        if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    78
            return AL_FALSE;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    79
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    80
        // allocate memory space for buffers and sources
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    81
        Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    82
        Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    83
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    84
        // set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    85
	// Position, Velocity and Orientation of the listener
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    86
        ALfloat ListenerPos[] = {0.0, 0.0, 0.0};
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    87
        ALfloat ListenerVel[] = {0.0, 0.0, 0.0};
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    88
        ALfloat ListenerOri[] = {0.0, 0.0, -1.0,  0.0, 1.0, 0.0};
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    89
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    90
        alListenerf (AL_GAIN,        1.0f       );
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    91
        alListenerfv(AL_POSITION,    ListenerPos);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    92
        alListenerfv(AL_VELOCITY,    ListenerVel);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    93
        alListenerfv(AL_ORIENTATION, ListenerOri);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    94
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    95
        if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    96
            return AL_FALSE;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    97
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    98
        openalReady = AL_TRUE;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
    99
        
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   100
        alGetError();  // clear any AL errors beforehand
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   101
        return AL_TRUE;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   102
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   103
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   104
    void openal_close (void) {
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   105
        /*Stop all sounds, deallocate all memory and close OpenAL */
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   106
        ALCcontext *context;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   107
        ALCdevice  *device;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   108
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   109
        if (openalReady == AL_FALSE) {
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   110
            errno = EPERM;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   111
            err_ret("(%s) WARN - OpenAL not initialized", prog);
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   112
            return;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   113
        }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   114
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   115
        alSourceStopv	(globalsize, Sources);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   116
        alDeleteSources (globalsize, Sources);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   117
        alDeleteBuffers (globalsize, Buffers);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   118
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   119
        free(Sources);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   120
        free(Buffers);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   121
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   122
        context = alcGetCurrentContext();
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   123
        device  = alcGetContextsDevice(context);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   124
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   125
        alcMakeContextCurrent(NULL);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   126
        alcDestroyContext(context);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   127
        alcCloseDevice(device);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   128
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   129
        openalReady = AL_FALSE;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   130
        
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   131
        err_msg("(%s) INFO - closed", prog);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   132
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   133
        return AL_TRUE;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   134
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   135
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   136
    ALboolean openal_ready(void) {
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   137
        return openalReady;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   138
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   139
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   140
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   141
    void helper_realloc (void) {
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   142
        /*expands allocated memory when loading more sound files than expected*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   143
        int oldsize = globalsize;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   144
        globalsize += increment;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   145
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   146
        err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   147
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   148
        Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   149
        Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   150
        
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   151
        return;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   152
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   153
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   154
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   155
    int openal_loadfile (const char *filename){
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   156
        /*Open a file, load into memory and allocate the Source buffer for playing*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   157
        ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   158
        ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   159
        ALenum format;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   160
        ALsizei bitsize, freq;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   161
        char *data;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   162
        uint32_t fileformat;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   163
        ALenum error;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   164
        FILE *fp;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   165
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   166
        if (openalReady == AL_FALSE) {
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   167
            err_msg("(%s) WARN - not initialized", prog);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   168
            return -1;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   169
        }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   170
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   171
        /*when the buffers are all used, we can expand memory to accept new files*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   172
        if (globalindex == globalsize)
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   173
            helper_realloc();
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   174
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   175
        /*detect the file format, as written in the first 4 bytes of the header*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   176
        fp = Fopen (filename, "rb");
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   177
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   178
        if (fp == NULL)
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   179
            return -2;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   180
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   181
        error = fread (&fileformat, sizeof(uint32_t), 1, fp);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   182
        fclose (fp);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   183
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   184
        if (error < 0) {
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   185
            err_msg("(%s) ERROR - File %s is too short", prog, filename);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   186
            return -3;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   187
        }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   188
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   189
        /*prepare the buffer to receive data*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   190
        alGenBuffers(1, &Buffers[globalindex]);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   191
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   192
        if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE)
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   193
            return -4;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   194
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   195
        /*prepare the source to emit sound*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   196
        alGenSources(1, &Sources[globalindex]);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   197
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   198
        if (AlGetError("(%s) ERROR - Failed to allocate memory for sources") != AL_TRUE)
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   199
            return -5;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   200
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   201
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   202
        switch (ENDIAN_BIG_32(fileformat)) {
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   203
            case OGG_FILE_FORMAT:
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   204
                error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   205
                break;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   206
            case WAV_FILE_FORMAT:
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   207
                error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   208
                break;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   209
            default:
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   210
                err_msg ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat));
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   211
                return -6;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   212
                break;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   213
        }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   214
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   215
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   216
        /*copy pcm data in one buffer*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   217
        alBufferData(Buffers[globalindex], format, data, bitsize, freq);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   218
        free(data);		/*deallocate data to save memory*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   219
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   220
        if (AlGetError("(%s) ERROR - Failed to write data to buffers") != AL_TRUE)
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   221
            return -6;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   222
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   223
        /*set source properties that it will use when it's in playback*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   224
        alSourcei (Sources[globalindex], AL_BUFFER,   Buffers[globalindex]  );
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   225
        alSourcef (Sources[globalindex], AL_PITCH,    1.0f                  );
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   226
        alSourcef (Sources[globalindex], AL_GAIN,     1.0f                  );
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   227
        alSourcefv(Sources[globalindex], AL_POSITION, SourcePos             );
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   228
        alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel             );
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   229
        alSourcei (Sources[globalindex], AL_LOOPING,  0                     );
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   230
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   231
        if (AlGetError("(%s) ERROR - Failed to set Source properties") != AL_TRUE)
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   232
            return -7;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   233
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   234
        alGetError();  /* clear any AL errors beforehand */
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   235
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   236
        /*returns the index of the source you just loaded, increments it and exits*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   237
        return globalindex++;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   238
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   239
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   240
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   241
    void openal_playsound (uint32_t index) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   242
        openal_playsound_loop (index, 0);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   243
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   244
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   245
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   246
    void openal_pausesound (uint32_t index) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   247
        if (openalReady == AL_TRUE && index < globalsize)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   248
            alSourcePause(Sources[index]);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   249
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   250
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   251
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   252
    void openal_stopsound (uint32_t index) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   253
        openal_stopsound_free(index, 0);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   254
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   255
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   256
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   257
    void openal_freesound (uint32_t index){
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   258
       if (openalReady == AL_TRUE && index < globalsize)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   259
            alSourceStop(Sources[index]);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   260
           // STUB
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   261
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   262
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   263
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   264
    void openal_playsound_loop (unsigned int index, char loops) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   265
	if (openalReady == AL_TRUE && index < globalsize) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   266
            alSourcePlay(Sources[index]);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   267
	    if (loops != 0)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   268
                openal_toggleloop(index);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   269
	}
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   270
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   271
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   272
    void openal_stopsound_free    (unsigned int index, char freesource) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   273
        if (openalReady == AL_TRUE && index < globalsize) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   274
            alSourceStop(Sources[index]);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   275
	    if (freesource != 0)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   276
	        openal_freesound(index);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   277
	}
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   278
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   279
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   280
    void openal_toggleloop (uint32_t index) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   281
        ALint loop;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   282
        
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   283
        if (openalReady == AL_TRUE && index < globalsize) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   284
            alGetSourcei (Sources[index], AL_LOOPING, &loop);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   285
            alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   286
	}
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   287
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   288
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   289
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   290
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   291
    void openal_setvolume (uint32_t index, float gain) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   292
        if (openalReady == AL_TRUE && index < globalsize)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   293
            alSourcef (Sources[index], AL_GAIN, gain);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   294
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   295
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   296
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   297
    void openal_setglobalvolume (float gain) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   298
        if (openalReady == AL_TRUE)
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   299
            alListenerf (AL_GAIN, gain);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   300
    }
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   301
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   302
    void openal_togglemute () {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   303
        ALfloat gain;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   304
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   305
        if (openalReady == AL_TRUE) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   306
            alGetListenerf (AL_GAIN, &gain);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   307
            if (gain > 0) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   308
		old_gain = gain; 
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   309
                gain = 0;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   310
	    } else 
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   311
                gain = old_gain;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   312
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   313
	    alListenerf (AL_GAIN, gain);
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   314
	}
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   315
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   316
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   317
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   318
    void openal_fade (uint32_t index, uint16_t quantity, char direction) {
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   319
        /*Fade in or out by calling a helper thread*/
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   320
#ifndef _WIN32
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   321
        pthread_t thread;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   322
#else
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   323
        HANDLE Thread;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   324
        DWORD threadID;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   325
#endif
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   326
        fade_t *fade;
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   327
        
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   328
        if (openalReady == AL_TRUE && index < globalsize) {
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   329
        
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   330
            fade = (fade_t*) Malloc(sizeof(fade_t));
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   331
            fade->index = index;
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   332
            fade->quantity = quantity;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   333
        
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   334
            if (direction > 0) {
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   335
#ifndef _WIN32
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   336
                pthread_create(&thread, NULL, helper_fadein, (void*) fade);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   337
#else
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   338
                Thread = _beginthread(&helper_fadein, 0, (void*) fade);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   339
#endif
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   340
            } else {
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   341
#ifndef _WIN32
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   342
                pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   343
#else
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   344
                Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   345
#endif	
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   346
            }
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   347
        
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   348
#ifndef _WIN32
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   349
            pthread_detach(thread);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   350
#endif
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   351
	}
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   352
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   353
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   354
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   355
    void openal_fadeout (uint32_t index, uint16_t quantity) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   356
        openal_fade(index, quantity, AL_FADE_OUT);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   357
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   358
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   359
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   360
    void openal_fadein (uint32_t index, uint16_t quantity) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   361
        openal_fade(index, quantity, AL_FADE_IN);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   362
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   363
    
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   364
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   365
    void openal_setposition (uint32_t index, float x, float y, float z) {
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   366
        if (openalReady == AL_TRUE && index < globalsize) 
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   367
            alSource3f(Sources[index], AL_POSITION, x, y, z);;
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   368
    }
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   369
    
3360
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   370
    
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   371
717b4e46e855 updates to openalbridge (modified api and simplified some sections)
koda
parents: 3356
diff changeset
   372
    
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   373
#ifdef __CPLUSPLUS
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   374
}
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
   375
#endif