openalbridge/openalbridge.c
author koda
Wed, 14 Oct 2009 22:21:25 +0000
changeset 2444 ace11b7d8eab
parent 2443 fececcbc2189
child 2445 5033848d3afa
permissions -rw-r--r--
code cleanup and restore the mute call
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
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    43
char SSound_load        (SSound_t* pSound, const char* cFilename);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    44
void SSound_close       (SSound_t* pSound);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    45
void SSound_play        (SSound_t* pSound, const char bLoop);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    46
void SSound_pause       (const SSound_t* pSound);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    47
void SSound_continue    (const SSound_t* pSound);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    48
void SSound_stop        (SSound_t* pSound);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    49
void SSound_volume      (const SSound_t* pSound, const float fPercentage);
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    50
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    51
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    52
/**
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    53
 * 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
    54
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    55
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    56
 * 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
    57
 * 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
    58
 *  DESCRIPTION
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    59
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    60
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    61
 * 1 success
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    62
 * 2 error
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    63
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    64
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    65
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
    66
        prog = (char *) programname;
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
        if (oalbReady == AL_TRUE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    69
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    70
                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
    71
                return AL_FALSE;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
    72
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    73
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    74
#ifdef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    75
        /* 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
    76
        if (usehardware != 0)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    77
                device = alcOpenDevice(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    78
        else
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
                device = alcOpenDevice("Generic Software");
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    81
                if(!device)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    82
                {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    83
                        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
    84
                        device = alcOpenDevice(NULL);
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
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    87
#else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    88
        /*always hardware for UNIX systems*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    89
        device = alcOpenDevice(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    90
#endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    91
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    92
        if (device == NULL) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    93
                errno = ENODEV;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    94
                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
    95
                return AL_FALSE;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    96
        }
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
    97
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
    98
        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
    99
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   100
        context = alcCreateContext(device, NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   101
        alcMakeContextCurrent(context);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   102
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   103
        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
   104
                return AL_FALSE;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   105
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   106
        /*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
   107
        alListenerf (AL_GAIN,        1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   108
        alListenerfv(AL_POSITION,    NV);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   109
        alListenerfv(AL_VELOCITY,    NV);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   110
        alListenerfv(AL_ORIENTATION, LO);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   111
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   112
        alcProcessContext(context);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   113
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   114
        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
   115
                return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   116
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   117
        alGenSources(MAX_SOURCES, sources);
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
        oalbReady = 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
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   122
        return AL_TRUE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   123
}
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
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   126
/**
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   127
 * void oalb_close (void) 
2443
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
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   130
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   131
 *  DESCRIPTION
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   132
 * 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
   133
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   134
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   135
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   136
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   137
void oalb_close (void) {
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
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   146
        for(i = 0; i < iNumSounds; i++) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   147
                SSound_stop(&aSounds[i]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   148
                SSound_close(&aSounds[i]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   149
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   150
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   151
        alSourceStopv (MAX_SOURCES, sources);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   152
        alDeleteSources (MAX_SOURCES, sources);
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
        alcMakeContextCurrent(NULL);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   155
        alcDestroyContext(context);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   156
        alcCloseDevice(device);
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
        oalbReady = 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   159
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   160
        return;
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
2444
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
 * char oalb_ready (void)  
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
 *  ARGUMENTS
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
 *  DESCRIPTION
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
 *  RETURN
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
 */
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
char oalb_ready (void) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   175
        return oalbReady;
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
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
 * 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
   180
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   181
 *  ARGUMENTS
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   182
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   183
 *  DESCRIPTION
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   184
 *
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   185
 *  RETURN
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   186
 * -
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   187
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   188
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   189
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
   190
        int i;
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 (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   193
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   194
                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
   195
                return -1;
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
        if(iNumSounds == MAX_SOUNDS) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   199
                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
   200
                return -3;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   201
        }
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   202
        
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   203
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   204
        for(i = 0; i < iNumSounds; i++)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   205
                if(strcmp(aSounds[i].Filename, filename) == 0)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   206
                        return i;
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
        if(SSound_load(&aSounds[iNumSounds], filename))
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   209
                return iNumSounds++;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   210
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   211
                return -2;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   212
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   213
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   214
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
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
   217
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   218
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   219
                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
   220
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   221
        }
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
        /*Set volume for sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   224
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   225
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   226
                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
   227
                return;
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
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   230
        if(cPercentage > 100)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   231
                SSound_volume(&aSounds[iIndex], 1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   232
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   233
                SSound_volume(&aSounds[iIndex], cPercentage / 100.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   234
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   235
        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
   236
                return;
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
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   239
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   240
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   241
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   242
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   243
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   244
void oalb_setglobalvolume (const char cPercentage) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   245
        if (oalbReady == 0) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   246
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   247
                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
   248
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   249
        }
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   250
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   251
        /*Set volume for all sounds*/		
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   252
        if(cPercentage > 100)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   253
                alListenerf (AL_GAIN, 1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   254
        else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   255
                alListenerf (AL_GAIN, cPercentage / 100.0f);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   256
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   257
        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
   258
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   259
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   260
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   261
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   262
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   263
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   264
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   265
    
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   266
void oalb_togglemute (void) {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   267
        /*Mute or unmute sound*/
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   268
        ALfloat mute;
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
        if (oalbReady == AL_FALSE) {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   271
                errno = EPERM;                
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   272
                err_ret("(%s) WARN - OpenAL not initialized", prog);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   273
                return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   274
        }
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
        alGetListenerf (AL_GAIN, &mute);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   277
        if (mute > 0) 
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   278
                mute = 0;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   279
        else
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   280
                mute = 1.0;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   281
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   282
        alListenerf (AL_GAIN, mute);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   283
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   284
        if (AlGetError("(%s) ERROR -  Failed to set mute property") != AL_TRUE)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   285
                return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   286
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   287
        alGetError();  /* clear any AL errors beforehand */
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   288
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   289
        return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   290
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
   291
 /*
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   292
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   293
 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
   294
 /*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
   295
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   296
 pthread_t thread;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   297
 #else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   298
 HANDLE Thread;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   299
 DWORD threadID;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   300
 #endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   301
 fade_t *fade;
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
 if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   304
 errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   305
 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
   306
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   307
 }
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
 fade = (fade_t*) Malloc(sizeof(fade_t));
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   310
 fade->index = index;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   311
 fade->quantity = quantity;
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
 if (index >= globalsize) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   314
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   315
 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
   316
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   317
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   318
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   319
 switch (direction) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   320
 case FADE_IN:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   321
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   322
 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
   323
 #else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   324
 Thread = _beginthread(&helper_fadein, 0, (void*) fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   325
 #endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   326
 break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   327
 case FADE_OUT:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   328
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   329
 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
   330
 #else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   331
 Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   332
 #endif	
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
 default:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   335
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   336
 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
   337
 free(fade);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   338
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   339
 break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   340
 }
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
 #ifndef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   343
 pthread_detach(thread);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   344
 #endif
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
 alGetError();  /* clear any AL errors beforehand 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   347
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   348
 return AL_TRUE;
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_fadeout (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 fadeout
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   354
 return openal_fade(index, quantity, FADE_OUT);
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_fadein (uint32_t index, uint16_t quantity) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   359
 /*wrapper for fadein
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   360
 return openal_fade(index, quantity, FADE_IN);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   361
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   362
 
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
 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
   365
 if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   366
 errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   367
 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
   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
 if (index >= globalsize) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   372
 errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   373
 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
   374
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   375
 }
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
 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
   378
 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
   379
 return AL_FALSE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   380
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   381
 return AL_TRUE;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   382
 }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   383
 
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   384
 */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   385
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   386
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
   387
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   388
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   389
                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
   390
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   391
        }
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
        /*Play sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   394
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   395
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   396
                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
   397
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   398
        }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   399
        SSound_play(&aSounds[iIndex], bLoop);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   400
        
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   401
        
2443
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
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   404
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   405
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   406
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   407
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
void oalb_pausesound (const uint32_t iIndex) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   410
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   411
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   412
                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
   413
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   414
        }
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
        /*Pause sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   417
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   418
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   419
                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
   420
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   421
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   422
        SSound_pause(&aSounds[iIndex]);
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
        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
   425
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   426
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   427
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   428
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   429
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   430
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   431
void oalb_stopsound (const uint32_t iIndex) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   432
        if (oalbReady == AL_FALSE) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   433
                errno = EPERM;                
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   434
                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
   435
                return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   436
        }
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   437
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   438
        /*Stop sound number index*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   439
        if(iIndex < 0 || iIndex >= iNumSounds) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   440
                errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   441
                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
   442
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   443
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   444
        SSound_stop(&aSounds[iIndex]);
2415
35d09cbf819a OpenALBridge updates
koda
parents: 2392
diff changeset
   445
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   446
        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
   447
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   448
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   449
        alGetError();  /* clear any AL errors beforehand */
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   450
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   451
        return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   452
}
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
/*SSOUND STUFF HERE*/
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   456
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   457
char SSound_load (SSound_t* pSound, const char* cFilename) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   458
        uint32_t magic;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   459
        ALenum format;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   460
        ALsizei bitsize, freq;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   461
        char *data;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   462
        FILE* fp;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   463
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   464
        snprintf(pSound->Filename, 256, "%s", cFilename);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   465
        pSound->source = -1;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   466
        alGenBuffers(1, &pSound->Buffer);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   467
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   468
        if(alGetError() != AL_NO_ERROR) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   469
                fprintf(stderr, "CSound: Couldn't create buffer.\n");
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   470
                return 0;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   471
        }
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   472
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   473
        fp = fopen(pSound->Filename, "rb");
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   474
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   475
        if(!fp) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   476
                fprintf(stderr, "CSound: Couldn't open file for reading.\n");
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   477
                return 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   478
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   479
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   480
        if(fread(&magic, sizeof(uint32_t), 1, fp) < 1)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   481
        {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   482
                fclose(fp);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   483
                fprintf(stderr, "CSound: Couldn't read file header.\n");
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   484
                return 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   485
        }
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   486
        fclose(fp);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   487
        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   488
        switch (ENDIAN_BIG_32(magic)) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   489
                case OGG_FILE_FORMAT:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   490
                        load_oggvorbis (pSound->Filename, &format, &data, &bitsize, &freq);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   491
                        break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   492
                case WAV_FILE_FORMAT:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   493
                        load_wavpcm (pSound->Filename, &format, &data, &bitsize, &freq);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   494
                        break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   495
                default:
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   496
                        errno = EINVAL;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   497
                        err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(magic));
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   498
                        return 0;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   499
                        break;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   500
        }
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   501
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   502
        alBufferData(pSound->Buffer, format, data, bitsize, freq);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   503
        if(alGetError() != AL_NO_ERROR)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   504
        {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   505
                fprintf(stderr, "CSound: Couldn't write buffer data.\n");
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   506
                return 0;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   507
        }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   508
        free(data);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   509
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   510
        return 1;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   511
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   512
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   513
void SSound_close(SSound_t* pSound)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   514
{
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   515
        SSound_stop(pSound);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   516
        alDeleteBuffers(1, &pSound->Buffer);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   517
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   518
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   519
void SSound_play(SSound_t* pSound, const char bLoop) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   520
        int i;
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   521
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   522
        if(pSound->source == -1) // need a new source
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   523
        {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   524
                int i;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   525
                for(i = 0; i < MAX_SOURCES; i++)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   526
                {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   527
                        ALint state;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   528
                        alGetSourcei(sources[i], AL_SOURCE_STATE, &state);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   529
                        if(state != AL_PLAYING && state != AL_PAUSED)
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   530
                        {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   531
#ifdef DEBUG
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   532
                                printf("using source %d (state 0x%x) for buffer.\n", i, state);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   533
#endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   534
                                alSourceStop(sources[pSound->source]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   535
                                alGetError();
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   536
                                break;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   537
                        }
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   538
                }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   539
                if(i == MAX_SOURCES) // no available source found; skip
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
#ifdef DEBUG
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   542
                        printf("no source to play buffer %d!\n", i);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   543
#endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   544
                        return;
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   545
                }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   546
                pSound->source = i;
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
        else // reuse already playing source
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   549
        {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   550
                alSourceStop(sources[pSound->source]);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   551
        }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   552
        alSourcei (sources[pSound->source], AL_BUFFER, pSound->Buffer);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   553
        alSourcef (sources[pSound->source], AL_PITCH,            1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   554
        alSourcef (sources[pSound->source], AL_GAIN,             1.0f);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   555
        alSourcefv(sources[pSound->source], AL_POSITION, NV          );
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   556
        alSourcefv(sources[pSound->source], AL_VELOCITY, NV          );
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   557
        alSourcei (sources[pSound->source], AL_LOOPING,  bLoop       );
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   558
        alSourcePlay(sources[pSound->source]);
2259
ca42efdce3ce fix indentation and other cosmetic changes to lib
koda
parents: 2257
diff changeset
   559
        
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   560
        if((i = alGetError()) != AL_NO_ERROR)
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
                fprintf(stderr, "CSound: SourcePlay error 0x%4x in source %d\n", i, pSound->source);
2419
dbaaba09146d really fix build and completes transition to errlib
koda
parents: 2418
diff changeset
   563
        }
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   564
#ifdef DEBUG
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   565
        fprintf(stderr, "play %s%s [%d]\n", pSound->Filename, bLoop ? " forever" : " once", pSound->source);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   566
#endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   567
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   568
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   569
void SSound_pause(const SSound_t* pSound) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   570
        if(pSound->source == -1) // not playing
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   571
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   572
        alSourcePause(sources[pSound->source]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   573
#ifdef DEBUG
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   574
        fprintf(stderr, "pause %s\n", pSound->Filename);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   575
#endif
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   576
}
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   577
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   578
void SSound_continue(const SSound_t* pSound) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   579
        if(pSound->source == -1) // not playing
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   580
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   581
        alSourcePlay(sources[pSound->source]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   582
#ifdef DEBUG
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   583
        fprintf(stderr, "pause %s\n", pSound->Filename);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   584
#endif
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   585
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   586
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   587
void SSound_stop(SSound_t* pSound) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   588
        if(pSound->source == -1) // not playing
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   589
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   590
        alSourceStop(sources[pSound->source]);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   591
        pSound->source = -1;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   592
#ifdef DEBUG
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   593
        fprintf(stderr, "stop %s\n", pSound->Filename);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   594
#endif
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   595
}
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   596
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   597
void SSound_volume(const SSound_t* pSound, const float fPercentage) {
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   598
        if(pSound->source == -1) // not playing
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   599
                return;
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   600
        alSourcef(sources[pSound->source], AL_GAIN, fPercentage);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   601
}        
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2437
diff changeset
   602