diff OpenAL32/alThunk.c @ 0:f9476ff7637e

initial forking of open-al to create multiple listeners
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:02:31 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/OpenAL32/alThunk.c	Tue Oct 25 13:02:31 2011 -0700
     1.3 @@ -0,0 +1,93 @@
     1.4 +/**
     1.5 + * OpenAL cross platform audio library
     1.6 + * Copyright (C) 1999-2007 by authors.
     1.7 + * This library is free software; you can redistribute it and/or
     1.8 + *  modify it under the terms of the GNU Library General Public
     1.9 + *  License as published by the Free Software Foundation; either
    1.10 + *  version 2 of the License, or (at your option) any later version.
    1.11 + *
    1.12 + * This library is distributed in the hope that it will be useful,
    1.13 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 + *  Library General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU Library General Public
    1.18 + *  License along with this library; if not, write to the
    1.19 + *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 + *  Boston, MA  02111-1307, USA.
    1.21 + * Or go to http://www.gnu.org/copyleft/lgpl.html
    1.22 + */
    1.23 +
    1.24 +#include "config.h"
    1.25 +
    1.26 +#include <stdlib.h>
    1.27 +
    1.28 +#include "alMain.h"
    1.29 +#include "alThunk.h"
    1.30 +
    1.31 +
    1.32 +static ALboolean  *ThunkArray;
    1.33 +static ALuint      ThunkArraySize;
    1.34 +
    1.35 +static CRITICAL_SECTION ThunkLock;
    1.36 +
    1.37 +void ThunkInit(void)
    1.38 +{
    1.39 +    InitializeCriticalSection(&ThunkLock);
    1.40 +    ThunkArraySize = 1;
    1.41 +    ThunkArray = calloc(1, ThunkArraySize * sizeof(*ThunkArray));
    1.42 +}
    1.43 +
    1.44 +void ThunkExit(void)
    1.45 +{
    1.46 +    free(ThunkArray);
    1.47 +    ThunkArray = NULL;
    1.48 +    ThunkArraySize = 0;
    1.49 +    DeleteCriticalSection(&ThunkLock);
    1.50 +}
    1.51 +
    1.52 +ALenum NewThunkEntry(ALuint *index)
    1.53 +{
    1.54 +    ALuint i;
    1.55 +
    1.56 +    EnterCriticalSection(&ThunkLock);
    1.57 +
    1.58 +    for(i = 0;i < ThunkArraySize;i++)
    1.59 +    {
    1.60 +        if(ThunkArray[i] == AL_FALSE)
    1.61 +            break;
    1.62 +    }
    1.63 +
    1.64 +    if(i == ThunkArraySize)
    1.65 +    {
    1.66 +        ALboolean *NewList;
    1.67 +
    1.68 +        NewList = realloc(ThunkArray, ThunkArraySize*2 * sizeof(*ThunkArray));
    1.69 +        if(!NewList)
    1.70 +        {
    1.71 +            LeaveCriticalSection(&ThunkLock);
    1.72 +            ERR("Realloc failed to increase to %u enties!\n", ThunkArraySize*2);
    1.73 +            return AL_OUT_OF_MEMORY;
    1.74 +        }
    1.75 +        memset(&NewList[ThunkArraySize], 0, ThunkArraySize*sizeof(*ThunkArray));
    1.76 +        ThunkArraySize *= 2;
    1.77 +        ThunkArray = NewList;
    1.78 +    }
    1.79 +
    1.80 +    ThunkArray[i] = AL_TRUE;
    1.81 +    *index = i+1;
    1.82 +
    1.83 +    LeaveCriticalSection(&ThunkLock);
    1.84 +
    1.85 +    return AL_NO_ERROR;
    1.86 +}
    1.87 +
    1.88 +void FreeThunkEntry(ALuint index)
    1.89 +{
    1.90 +    EnterCriticalSection(&ThunkLock);
    1.91 +
    1.92 +    if(index > 0 && index <= ThunkArraySize)
    1.93 +        ThunkArray[index-1] = AL_FALSE;
    1.94 +
    1.95 +    LeaveCriticalSection(&ThunkLock);
    1.96 +}