openalbridge/ssound.c
changeset 2468 0b62498c201a
parent 2454 c8b1fb10003c
equal deleted inserted replaced
2467:be6690c337fb 2468:0b62498c201a
    18  */
    18  */
    19 
    19 
    20 #include "ssound.h"
    20 #include "ssound.h"
    21 #include "loaders.h"
    21 #include "loaders.h"
    22 
    22 
       
    23 extern SSound_t aSounds[MAX_SOUNDS];
    23 extern ALuint sources[MAX_SOURCES];
    24 extern ALuint sources[MAX_SOURCES];
    24 extern const ALfloat NV[3];
    25 extern const ALfloat NV[3];
    25 extern const ALfloat LO[6];
    26 extern const ALfloat LO[6];
    26 
    27 extern int iNumSounds;
    27 extern char *prog;
    28 extern char *prog;
    28 
    29 
    29 char SSound_load (SSound_t* pSound, const char* cFilename) {
    30 char SSound_load (SSound_t* pSound, const char* cFilename) {
    30         uint32_t magic;
    31         uint32_t magic;
    31         ALenum format;
    32         ALenum format;
    88         alDeleteBuffers(1, &pSound->Buffer);
    89         alDeleteBuffers(1, &pSound->Buffer);
    89         return;
    90         return;
    90 }
    91 }
    91 
    92 
    92 void SSound_play(SSound_t* pSound, const char bLoop) {
    93 void SSound_play(SSound_t* pSound, const char bLoop) {
    93         int i;
    94         int i, j;
    94         
    95         
    95         if(pSound->source == -1) // need a new source
    96         if(pSound->source == -1) // need a new source
    96         {
    97         {
    97                 int i;
       
    98                 for(i = 0; i < MAX_SOURCES; i++)
    98                 for(i = 0; i < MAX_SOURCES; i++)
    99                 {
    99                 {
   100                         ALint state;
   100                         ALint state;
   101                         alGetSourcei(sources[i], AL_SOURCE_STATE, &state);
   101                         alGetSourcei(sources[i], AL_SOURCE_STATE, &state);
   102                         if(state != AL_PLAYING && state != AL_PAUSED)
   102                         if(state != AL_PLAYING && state != AL_PAUSED)
   104 #ifdef DEBUG
   104 #ifdef DEBUG
   105                                 printf("using source %d (state 0x%x) for buffer.\n", i, state);
   105                                 printf("using source %d (state 0x%x) for buffer.\n", i, state);
   106 #endif
   106 #endif
   107                                 alSourceStop(sources[pSound->source]);
   107                                 alSourceStop(sources[pSound->source]);
   108                                 alGetError();
   108                                 alGetError();
       
   109 
       
   110 								// lookup buffers associated with this source and reset them
       
   111 								for(j = 0; j < iNumSounds; j++)
       
   112 									if(aSounds[j].source == i)
       
   113 										aSounds[j].source = -1;
   109                                 break;
   114                                 break;
   110                         }
   115                         }
   111                 }
   116                 }
   112                 if(i == MAX_SOURCES) // no available source found; skip
   117                 if(i == MAX_SOURCES) // no available source found; skip
   113                 {
   118                 {