openalbridge/openalbridge.c
author koda
Fri, 16 Oct 2009 16:42:51 +0000
changeset 2494 1e10a47cabea
parent 2446 cbb3af76bcc0
child 2496 8ea93b0d49ee
permissions -rw-r--r--
THE fix for openalbridge faders are restored but need testing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     1
/*
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     2
 * OpenAL Bridge - a simple portable library for OpenAL interface
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
     3
 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     4
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2257
7eb31efcfb9b updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents: 2220
diff changeset
     6
 * it under the terms of the GNU Lesser General Public License as published by
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     8
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2257
7eb31efcfb9b updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents: 2220
diff changeset
    12
 * GNU Lesser General Public License for more details.
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    13
 *
2257
7eb31efcfb9b updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents: 2220
diff changeset
    14
 * You should have received a copy of the GNU Lesser General Public License
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    17
 */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    18
2326
0ddf641fddee rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents: 2261
diff changeset
    19
#include "openalbridge.h"
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents: 2415
diff changeset
    20
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    21
char oalbReady = 0;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    22
int iNumSounds = 0;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    23
char *prog;
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    24
/*Sources are points emitting sound*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    25
ALuint Sources[MAX_SOURCES];
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    26
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    27
/*structure that holds information about sounds*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    28
SSound_t *theSounds;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    29
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    30
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    31
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    33
/**
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    34
 * const char oalb_init (const char* programname, const char usehardware) 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    35
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    36
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    37
 * programname [const char*]: name of the program invoking OpenAL
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    38
 * usehardware [const char] : flag to enable audio hardware acceleration
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    39
 *  DESCRIPTION
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    40
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    41
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    42
 * 1 success
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    43
 * 2 error
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    44
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    45
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    46
const char oalb_init (const char* programname, const char usehardware) {	
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    47
        /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    48
        ALCcontext *context;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    49
        ALCdevice *device;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    50
        const ALCchar *default_device;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    51
        int i;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    52
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    53
        prog = (char *) programname;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    54
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    55
        /*Position of the listener*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    56
        ALfloat ListenerPos[] = {0.0, 0.0, 0.0};
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    57
        /*Velocity of the listener*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    58
        ALfloat ListenerVel[] = {0.0, 0.0, 0.0};
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    59
        /*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    60
        ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0};
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    61
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    62
        if (oalbReady == 1) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    63
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    64
                err_ret("(%s) WARN - OpenAL already initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    65
                return AL_FALSE;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
    66
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    67
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    68
#ifdef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    69
        /* Hardware acceleration is broken on some windows card*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    70
        if (usehardware != 0)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    71
                device = alcOpenDevice(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    72
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    73
        {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    74
                device = alcOpenDevice("Generic Software");
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    75
                if(!device)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    76
                {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    77
                        err_msg("(%s) WARN - Failed to open software device", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    78
                        device = alcOpenDevice(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    79
                }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    80
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    81
#else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    82
        /*always hardware for UNIX systems*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    83
        device = alcOpenDevice(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    84
#endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    85
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    86
        if (device == NULL) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    87
                errno = ENODEV;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    88
                err_ret("(%s) WARN - Failed to open sound device", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    89
                return AL_FALSE;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    90
        }
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    91
        err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER));
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    92
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    93
        context = alcCreateContext(device, NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    94
        alcMakeContextCurrent(context);
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    95
        alcProcessContext(context);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    96
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
    97
        if (AlGetError("(%s) ERROR - Failed to create a new contex") != AL_TRUE)
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    98
                return AL_FALSE;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    99
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   100
        /*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   101
        alListenerf (AL_GAIN,        1.0f       );
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   102
        alListenerfv(AL_POSITION,    ListenerPos);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   103
        alListenerfv(AL_VELOCITY,    ListenerVel);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   104
        alListenerfv(AL_ORIENTATION, ListenerOri);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   105
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   106
        if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   107
                return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   108
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   109
        theSounds = (SSound_t*) Malloc(sizeof(SSound_t)*MAX_SOUNDS);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   110
        for (i = 0; i < MAX_SOUNDS; i++) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   111
                theSounds->isLoaded = 0;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   112
                theSounds->sourceIndex = -1;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   113
        }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   114
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   115
        alGenSources(MAX_SOURCES, Sources);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   116
        oalbReady = 1;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   117
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   118
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   119
        return AL_TRUE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   120
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   121
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   122
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   123
/**
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   124
 * void oalb_close (void) 
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   125
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   126
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   127
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   128
 *  DESCRIPTION
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   129
 * Stop all sounds, deallocate all memory and close OpenAL
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   130
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   131
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   132
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   133
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   134
void oalb_close (void) {
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   135
        /*Stop all sounds, deallocate all memory and close OpenAL */
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   136
        ALCcontext *context;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   137
        ALCdevice  *device;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   138
        int i;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   139
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   140
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   141
                errno = EPERM;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   142
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   143
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   144
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   145
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   146
        alSourceStopv	(MAX_SOURCES, Sources);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   147
        alDeleteSources (MAX_SOURCES, Sources);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   148
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   149
        for (i = 0; i < MAX_SOUNDS; i++) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   150
                free(theSounds[i].filename);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   151
                alDeleteBuffers (1, &theSounds[i].Buffer);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   152
        }
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   153
        free(theSounds);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   154
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   155
        context = alcGetCurrentContext();
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   156
        device  = alcGetContextsDevice(context);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   157
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   158
        alcMakeContextCurrent(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   159
        alcDestroyContext(context);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   160
        alcCloseDevice(device);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   161
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   162
        oalbReady = 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   163
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   164
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   165
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   166
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   167
/**
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   168
 * char oalb_ready (void)  
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   169
 *
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   170
 *  ARGUMENTS
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   171
 * -
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   172
 *  DESCRIPTION
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   173
 *
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   174
 *  RETURN
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   175
 * -
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   176
 */
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   177
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   178
char oalb_ready (void) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   179
        return oalbReady;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   180
}
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   181
/*
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   182
 ALboolean helper_realloc (void) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   183
 expands allocated memory when loading more sound files than expected
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   184
 int oldsize = globalsize;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   185
 globalsize += increment;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   186
 
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   187
 #ifdef DEBUG
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   188
 err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   189
 #endif
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   190
 
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   191
 Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   192
 Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   193
 
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   194
 return AL_TRUE;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   195
 }*/
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   196
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   197
/**
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   198
 * const int32_t oalb_loadfile (const char *filename) 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   199
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   200
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   201
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   202
 *  DESCRIPTION
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   203
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   204
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   205
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   206
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   207
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   208
const int32_t oalb_loadfile (const char *filename){
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   209
        /*Open a file, load into memory and allocate the Source buffer for playing*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   210
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   211
        ALenum format, error;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   212
        ALsizei bitsize, freq;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   213
        char *data;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   214
        int namelength, i;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   215
        uint32_t magic;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   216
        FILE *fp;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   217
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   218
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   219
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   220
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   221
                return -1;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   222
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   223
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   224
        /*when the buffers are all used, we can expand memory to accept new files*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   225
        //     if (globalindex == globalsize)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   226
        //            helper_realloc();
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   227
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   228
        namelength=strlen(filename);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   229
        /*if this sound is already loaded return the index from theSounds*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   230
        for (i = 0; i < iNumSounds; i++){
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   231
                if (theSounds[iNumSounds].isLoaded == 1) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   232
                        if (strncmp(theSounds[iNumSounds].filename, filename, namelength) == 0)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   233
                                return i;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   234
                }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   235
        }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   236
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   237
        /*else load it and store it into a theSounds cell*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   238
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   239
        /*detect the file format, as written in the first 4 bytes of the header*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   240
        fp = Fopen (filename, "rb");
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   241
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   242
        if (fp == NULL)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   243
                return -1;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   244
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   245
        error = fread (&magic, sizeof(uint32_t), 1, fp);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   246
        fclose (fp);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   247
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   248
        if (error < 0) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   249
                errno = EIO;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   250
                err_ret("(%s) ERROR - File %s is too short", prog, filename);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   251
                return -2;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   252
        }
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   253
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   254
        switch (ENDIAN_BIG_32(magic)) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   255
                case OGG_FILE_FORMAT:
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   256
                        error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   257
                        break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   258
                case WAV_FILE_FORMAT:
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   259
                        error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   260
                        break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   261
                default:
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   262
                        errno = EINVAL;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   263
                        err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(magic));
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   264
                        return -5;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   265
                        break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   266
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   267
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   268
        theSounds[iNumSounds].filename = (char*) Malloc(sizeof(char) * namelength);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   269
        strncpy(theSounds[iNumSounds].filename, filename, namelength);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   270
        theSounds[iNumSounds].isLoaded = 1;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   271
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   272
        /*prepare the buffer to receive data*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   273
        alGenBuffers(1, &theSounds[iNumSounds].Buffer);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   274
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   275
        if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   276
                return -3;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   277
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   278
        /*copy pcm data in one buffer*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   279
        alBufferData(theSounds[iNumSounds].Buffer, format, data, bitsize, freq);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   280
        /*deallocate data to save memory*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   281
        free(data);		
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   282
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   283
        if (AlGetError("(%s) ERROR - Failed to write data to buffers") != AL_TRUE)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   284
                return -6;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   285
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   286
        alGetError();  /* clear any AL errors beforehand */
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   287
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   288
        /*returns the index of the source you just loaded, increments it and exits*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   289
        return iNumSounds++;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   290
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   291
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   292
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   293
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   294
void oalb_setvolume (const uint32_t iIndex,  const char cPercentage) {
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   295
        float percentage;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   296
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   297
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   298
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   299
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   300
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   301
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   302
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   303
        /*Set volume for sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   304
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   305
                errno = EINVAL;
2446
cbb3af76bcc0 partial italian translation and other fixes to lib
koda
parents: 2445
diff changeset
   306
                err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   307
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   308
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   309
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   310
        if(cPercentage > 100)
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   311
                percentage = 1.0f;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   312
        else
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   313
                percentage = cPercentage / 100.0f;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   314
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   315
        alSourcef(Sources[theSounds[iIndex].sourceIndex], AL_GAIN, percentage);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   316
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   317
        if (AlGetError2("(%s) ERROR -  Failed to set volume for sound %d\n", iIndex) != AL_TRUE)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   318
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   319
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   320
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   321
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   322
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   323
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   324
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   325
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   326
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   327
void oalb_setglobalvolume (const char cPercentage) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   328
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   329
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   330
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   331
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   332
        }
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   333
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   334
        /*Set volume for all sounds*/		
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   335
        if(cPercentage > 100)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   336
                alListenerf (AL_GAIN, 1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   337
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   338
                alListenerf (AL_GAIN, cPercentage / 100.0f);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   339
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   340
        if (AlGetError("(%s) ERROR -  Failed to set global volume") != AL_TRUE)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   341
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   342
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   343
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   344
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   345
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   346
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   347
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   348
void oalb_togglemute (void) {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   349
        /*Mute or unmute sound*/
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   350
        ALfloat mute;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   351
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   352
        if (oalbReady == AL_FALSE) {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   353
                errno = EPERM;                
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   354
                err_ret("(%s) WARN - OpenAL not initialized", prog);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   355
                return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   356
        }
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   357
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   358
        alGetListenerf (AL_GAIN, &mute);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   359
        if (mute > 0) 
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   360
                mute = 0;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   361
        else
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   362
                mute = 1.0;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   363
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   364
        alListenerf (AL_GAIN, mute);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   365
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   366
        if (AlGetError("(%s) ERROR -  Failed to set mute property") != AL_TRUE)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   367
                return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   368
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   369
        alGetError();  /* clear any AL errors beforehand */
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   370
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   371
        return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   372
}
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   373
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   374
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   375
void oalb_fade (uint32_t iIndex, uint16_t quantity, ALboolean direction) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   376
        /*Fade in or out by calling a helper thread*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   377
#ifndef _WIN32
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   378
        pthread_t thread;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   379
#else
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   380
        HANDLE Thread;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   381
        DWORD threadID;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   382
#endif
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   383
        fade_t *fade;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   384
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   385
        if (oalbReady == 0) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   386
                errno = EPERM;                
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   387
                err_ret("(%s) WARN - OpenAL not initialized", prog);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   388
                return ;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   389
        }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   390
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   391
        fade = (fade_t*) Malloc(sizeof(fade_t));
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   392
        fade->index = iIndex;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   393
        fade->quantity = quantity;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   394
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   395
        if(iIndex < 0 || iIndex >= iNumSounds) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   396
                errno = EINVAL;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   397
                err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   398
                return;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   399
        }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   400
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   401
        switch (direction) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   402
                case FADE_IN:
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   403
#ifndef _WIN32
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   404
                        pthread_create(&thread, NULL, helper_fadein, (void*) fade);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   405
#else
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   406
                        Thread = _beginthread(&helper_fadein, 0, (void*) fade);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   407
#endif
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   408
                        break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   409
                case FADE_OUT:
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   410
#ifndef _WIN32
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   411
                        pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   412
#else
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   413
                        Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   414
#endif	
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   415
                        break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   416
                default:
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   417
                        errno = EINVAL;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   418
                        err_ret("(%s) ERROR - Unknown direction for fading", prog, index);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   419
                        free(fade);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   420
                        return;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   421
                        break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   422
        }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   423
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   424
#ifndef _WIN32
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   425
        pthread_detach(thread);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   426
#endif
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   427
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   428
        alGetError();  /* clear any AL errors beforehand */
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   429
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   430
        return;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   431
}
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   432
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   433
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   434
void oalb_fadeout (uint32_t index, uint16_t quantity) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   435
        /*wrapper for fadeout*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   436
        oalb_fade(index, quantity, FADE_OUT);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   437
        return;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   438
}
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   439
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   440
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   441
void oalb_fadein (uint32_t index, uint16_t quantity) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   442
        /*wrapper for fadein*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   443
        oalb_fade(index, quantity, FADE_IN);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   444
        return;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   445
}
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   446
 
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   447
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   448
/*      ALboolean openal_setposition (uint32_t index, float x, float y, float z) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   449
 if (openalReady == AL_FALSE) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   450
 errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   451
 err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   452
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   453
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   454
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   455
 if (index >= globalsize) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   456
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   457
 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   458
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   459
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   460
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   461
 alSource3f(Sources[index], AL_POSITION, x, y, z);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   462
 if (AlGetError2("(%s) ERROR - Failed to set position for sound %d)", index) != AL_TRUE)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   463
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   464
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   465
 return AL_TRUE;
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   466
 }*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   467
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   468
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   469
void oalb_playsound (const uint32_t iIndex, const char bLoop){
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   470
        int findNewSource;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   471
        int i, j, state;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   472
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   473
        if (oalbReady == 0) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   474
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   475
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   476
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   477
        }
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   478
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   479
        /*Play sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   480
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   481
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   482
                err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   483
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   484
        }
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   485
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   486
        /*check if sound has already a source*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   487
        if (theSounds[iIndex].sourceIndex == -1) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   488
                /*needs a new source*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   489
                findNewSource = 1;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   490
        } else {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   491
                /*already has a source -- check it's not playing*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   492
                alGetSourcei(Sources[theSounds[iIndex].sourceIndex], AL_SOURCE_STATE, &state);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   493
                if(state == AL_PLAYING || state == AL_PAUSED) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   494
                        /*it is being played, so we have to allocate a new source*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   495
                        findNewSource = 1;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   496
                } else {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   497
                        /*it is not being played, so we can use it safely*/
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   498
                        findNewSource = 0;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   499
                }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   500
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   501
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   502
        if (findNewSource == 1) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   503
#ifdef DEBUG
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   504
             err_msg("(%s) DEBUG - Looking for a source for sound %d", prog, iIndex);   
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   505
#endif
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   506
                for (i = 0; i < MAX_SOURCES; i++) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   507
                        alGetSourcei(Sources[i], AL_SOURCE_STATE, &state);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   508
                        if(state != AL_PLAYING && state != AL_PAUSED) {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   509
                              //  alSourceStop(Sources[i]);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   510
                              //  alGetError();
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   511
                                for(j = 0; j < iNumSounds; j++)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   512
                                        if(theSounds[j].isLoaded && theSounds[j].sourceIndex == i)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   513
                                                theSounds[j].sourceIndex = -1;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   514
                                break;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   515
                        } else {
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   516
                                //TODO: what happens when all 16 sources are busy?
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   517
                        }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   518
                }
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   519
                theSounds[iIndex].sourceIndex = i;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   520
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   521
        
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   522
        alSourcei (Sources[theSounds[iIndex].sourceIndex], AL_BUFFER,   theSounds[iIndex].Buffer);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   523
        alSourcef (Sources[theSounds[iIndex].sourceIndex], AL_PITCH,    1.0f        );
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   524
        alSourcef (Sources[theSounds[iIndex].sourceIndex], AL_GAIN,     1.0f        );
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   525
        alSourcefv(Sources[theSounds[iIndex].sourceIndex], AL_POSITION, SourcePos   );
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   526
        alSourcefv(Sources[theSounds[iIndex].sourceIndex], AL_VELOCITY, SourceVel   );
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   527
        alSourcei (Sources[theSounds[iIndex].sourceIndex], AL_LOOPING,  bLoop       );
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   528
        if (AlGetError("(%s) ERROR - Failed to set Source properties") != AL_TRUE)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   529
                return;
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   530
        
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   531
        alSourcePlay(Sources[theSounds[iIndex].sourceIndex]);
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   532
        if (AlGetError2("(%s) ERROR - Failed to play sound %d)", iIndex) != AL_TRUE)
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   533
                return;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   534
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   535
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   536
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   537
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   538
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   539
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   540
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   541
void oalb_pausesound (const uint32_t iIndex) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   542
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   543
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   544
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   545
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   546
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   547
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   548
        /*Pause sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   549
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   550
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   551
                err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   552
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   553
        }
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   554
        alSourcePause(Sources[theSounds[iIndex].sourceIndex]);                             
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   555
        if (AlGetError2("(%s) ERROR - Failed to pause sound %d)", iIndex) != AL_TRUE)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   556
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   557
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   558
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   559
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   560
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   561
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   562
void oalb_stopsound (const uint32_t iIndex) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   563
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   564
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   565
                err_ret("(%s) WARN - OpenAL not initialized", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   566
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   567
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   568
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   569
        /*Stop sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   570
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   571
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   572
                err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   573
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   574
        }
2494
1e10a47cabea THE fix for openalbridge
koda
parents: 2446
diff changeset
   575
        alSourceStop(Sources[theSounds[iIndex].sourceIndex]);                             
2415
35d09cbf819a OpenALBridge updates
koda
parents: 2392
diff changeset
   576
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   577
        if (AlGetError2("(%s) ERROR - Failed to stop sound %d)", iIndex) != AL_TRUE)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   578
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   579
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   580
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   581
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   582
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   583
}