openalbridge/openalbridge.c
author nemo
Fri, 16 Oct 2009 13:54:57 +0000
changeset 2488 1e48275a52b6
parent 2446 cbb3af76bcc0
child 2494 1e10a47cabea
permissions -rw-r--r--
increase molotov radius a bit
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
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
     3
 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>,
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
     4
 *                    Mario Liebisch <mario.liebisch+hw@googlemail.com>
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     5
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     6
 * 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
     7
 * it under the terms of the GNU Lesser General Public License as published by
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     9
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    12
 * 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
    13
 * GNU Lesser General Public License for more details.
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    14
 *
2257
7eb31efcfb9b updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents: 2220
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public License
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    18
 */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    19
2326
0ddf641fddee rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents: 2261
diff changeset
    20
#include "openalbridge.h"
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents: 2415
diff changeset
    21
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    22
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    23
char *prog;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    24
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    25
/*Buffers hold sound data*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    26
ALuint *Buffers;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    27
/*index for Sources and Buffers*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    28
ALuint globalindex, globalsize, increment;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    29
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    30
//null vector
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    31
const ALfloat NV[] = {0.0f, 0.0f, 0.0f};
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    32
//listener orientation
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    33
const ALfloat LO[] = {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f};
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    34
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    35
SSound_t aSounds[MAX_SOUNDS];
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    36
int iNumSounds = 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    37
char oalbReady = 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    38
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    39
ALCcontext *context;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    40
ALCdevice *device;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    41
ALuint sources[MAX_SOURCES];
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    42
2445
5033848d3afa committing some missing files
koda
parents: 2444
diff changeset
    43
2443
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
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    46
/**
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    47
 * 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
    48
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    49
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    50
 * 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
    51
 * 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
    52
 *  DESCRIPTION
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    53
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    54
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    55
 * 1 success
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    56
 * 2 error
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    57
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    58
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    59
const char oalb_init (const char* programname, const char usehardware) {                
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    60
        prog = (char *) programname;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    61
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    62
        if (oalbReady == AL_TRUE) {
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
        }
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    91
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    92
        err_msg("(%s) INFO - Using OpenAL device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER));
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    93
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    94
        context = alcCreateContext(device, NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    95
        alcMakeContextCurrent(context);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    96
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    97
        if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE)
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*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   101
        alListenerf (AL_GAIN,        1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   102
        alListenerfv(AL_POSITION,    NV);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   103
        alListenerfv(AL_VELOCITY,    NV);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   104
        alListenerfv(AL_ORIENTATION, LO);
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
        alcProcessContext(context);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   107
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   108
        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
   109
                return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   110
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   111
        alGenSources(MAX_SOURCES, sources);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   112
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   113
        oalbReady = AL_TRUE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   114
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   115
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   116
        return AL_TRUE;
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
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   119
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   120
/**
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   121
 * void oalb_close (void) 
2443
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
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   124
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   125
 *  DESCRIPTION
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   126
 * 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
   127
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   128
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   129
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   130
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   131
void oalb_close (void) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   132
        int i;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   133
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   134
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   135
                errno = EPERM;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   136
                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
   137
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   138
        }
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
        for(i = 0; i < iNumSounds; i++) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   141
                SSound_stop(&aSounds[i]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   142
                SSound_close(&aSounds[i]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   143
        }
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
        alSourceStopv (MAX_SOURCES, sources);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   146
        alDeleteSources (MAX_SOURCES, sources);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   147
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   148
        alcMakeContextCurrent(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   149
        alcDestroyContext(context);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   150
        alcCloseDevice(device);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   151
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   152
        oalbReady = 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   153
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   154
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   155
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   156
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   157
/**
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   158
 * char oalb_ready (void)  
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   159
 *
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   160
 *  ARGUMENTS
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   161
 * -
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   162
 *  DESCRIPTION
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   163
 *
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   164
 *  RETURN
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   165
 * -
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   166
 */
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) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   169
        return oalbReady;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   170
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   171
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   172
/**
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   173
 * 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
   174
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   175
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   176
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   177
 *  DESCRIPTION
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   178
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   179
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   180
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   181
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   182
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   183
const int32_t oalb_loadfile (const char *filename) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   184
        int i;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   185
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   186
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   187
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   188
                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
   189
                return -1;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   190
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   191
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   192
        if(iNumSounds == MAX_SOUNDS) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   193
                err_msg("(%s) WARN - Maximum number of sound samples reached", prog);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   194
                return -3;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   195
        }
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   196
        
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   197
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   198
        for(i = 0; i < iNumSounds; i++)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   199
                if(strcmp(aSounds[i].Filename, filename) == 0)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   200
                        return i;
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
        if(SSound_load(&aSounds[iNumSounds], filename))
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   203
                return iNumSounds++;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   204
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   205
                return -2;
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
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   208
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   209
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   210
void oalb_setvolume (const uint32_t iIndex,  const char cPercentage) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   211
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   212
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   213
                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
   214
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   215
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   216
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   217
        /*Set volume for sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   218
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   219
                errno = EINVAL;
2446
cbb3af76bcc0 partial italian translation and other fixes to lib
koda
parents: 2445
diff changeset
   220
                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
   221
                return;
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
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   224
        if(cPercentage > 100)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   225
                SSound_volume(&aSounds[iIndex], 1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   226
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   227
                SSound_volume(&aSounds[iIndex], cPercentage / 100.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   228
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   229
        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
   230
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   231
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   232
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   233
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   234
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   235
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   236
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   237
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   238
void oalb_setglobalvolume (const char cPercentage) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   239
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   240
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   241
                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
   242
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   243
        }
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   244
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   245
        /*Set volume for all sounds*/		
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   246
        if(cPercentage > 100)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   247
                alListenerf (AL_GAIN, 1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   248
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   249
                alListenerf (AL_GAIN, cPercentage / 100.0f);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   250
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   251
        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
   252
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   253
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   254
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   255
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   256
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   257
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   258
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   259
    
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   260
void oalb_togglemute (void) {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   261
        /*Mute or unmute sound*/
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   262
        ALfloat mute;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   263
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   264
        if (oalbReady == AL_FALSE) {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   265
                errno = EPERM;                
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   266
                err_ret("(%s) WARN - OpenAL not initialized", prog);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   267
                return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   268
        }
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   269
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   270
        alGetListenerf (AL_GAIN, &mute);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   271
        if (mute > 0) 
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   272
                mute = 0;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   273
        else
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   274
                mute = 1.0;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   275
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   276
        alListenerf (AL_GAIN, mute);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   277
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   278
        if (AlGetError("(%s) ERROR -  Failed to set mute property") != AL_TRUE)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   279
                return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   280
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   281
        alGetError();  /* clear any AL errors beforehand */
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   282
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   283
        return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   284
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   285
 /*
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   286
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   287
 ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   288
 /*Fade in or out by calling a helper thread
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   289
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   290
 pthread_t thread;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   291
 #else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   292
 HANDLE Thread;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   293
 DWORD threadID;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   294
 #endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   295
 fade_t *fade;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   296
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   297
 if (oalbReady == AL_FALSE) {
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 AL_FALSE;
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
 fade = (fade_t*) Malloc(sizeof(fade_t));
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   304
 fade->index = index;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   305
 fade->quantity = quantity;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   306
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   307
 if (index >= globalsize) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   308
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   309
 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
   310
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   311
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   312
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   313
 switch (direction) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   314
 case FADE_IN:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   315
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   316
 pthread_create(&thread, NULL, helper_fadein, (void*) fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   317
 #else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   318
 Thread = _beginthread(&helper_fadein, 0, (void*) fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   319
 #endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   320
 break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   321
 case FADE_OUT:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   322
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   323
 pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   324
 #else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   325
 Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   326
 #endif	
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   327
 break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   328
 default:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   329
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   330
 err_ret("(%s) ERROR - Unknown direction for fading", prog, index, globalindex);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   331
 free(fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   332
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   333
 break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   334
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   335
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   336
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   337
 pthread_detach(thread);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   338
 #endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   339
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   340
 alGetError();  /* clear any AL errors beforehand 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   341
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   342
 return AL_TRUE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   343
 }
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
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   346
 ALboolean openal_fadeout (uint32_t index, uint16_t quantity) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   347
 /*wrapper for fadeout
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   348
 return openal_fade(index, quantity, FADE_OUT);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   349
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   350
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   351
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   352
 ALboolean openal_fadein (uint32_t index, uint16_t quantity) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   353
 /*wrapper for fadein
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   354
 return openal_fade(index, quantity, FADE_IN);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   355
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   356
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   357
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   358
 ALboolean openal_setposition (uint32_t index, float x, float y, float z) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   359
 if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   360
 errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   361
 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
   362
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   363
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   364
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   365
 if (index >= globalsize) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   366
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   367
 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
   368
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   369
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   370
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   371
 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
   372
 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
   373
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   374
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   375
 return AL_TRUE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   376
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   377
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   378
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   379
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   380
void oalb_playsound (const uint32_t iIndex, const char bLoop) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   381
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   382
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   383
                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
   384
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   385
        }
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   386
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   387
        /*Play sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   388
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   389
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   390
                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
   391
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   392
        }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   393
        SSound_play(&aSounds[iIndex], bLoop);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   394
        
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   395
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   396
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   397
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   398
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   399
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   400
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   401
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   402
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   403
void oalb_pausesound (const uint32_t iIndex) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   404
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   405
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   406
                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
   407
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   408
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   409
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   410
        /*Pause sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   411
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   412
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   413
                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
   414
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   415
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   416
        SSound_pause(&aSounds[iIndex]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   417
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   418
        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
   419
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   420
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   421
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   422
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   423
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   424
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   425
void oalb_stopsound (const uint32_t iIndex) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   426
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   427
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   428
                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
   429
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   430
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   431
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   432
        /*Stop sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   433
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   434
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   435
                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
   436
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   437
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   438
        SSound_stop(&aSounds[iIndex]);
2415
35d09cbf819a OpenALBridge updates
koda
parents: 2392
diff changeset
   439
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   440
        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
   441
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   442
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   443
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   444
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   445
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   446
}