annotate 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
rev   line source
rlm@0 1 /**
rlm@0 2 * OpenAL cross platform audio library
rlm@0 3 * Copyright (C) 1999-2007 by authors.
rlm@0 4 * This library is free software; you can redistribute it and/or
rlm@0 5 * modify it under the terms of the GNU Library General Public
rlm@0 6 * License as published by the Free Software Foundation; either
rlm@0 7 * version 2 of the License, or (at your option) any later version.
rlm@0 8 *
rlm@0 9 * This library is distributed in the hope that it will be useful,
rlm@0 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rlm@0 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
rlm@0 12 * Library General Public License for more details.
rlm@0 13 *
rlm@0 14 * You should have received a copy of the GNU Library General Public
rlm@0 15 * License along with this library; if not, write to the
rlm@0 16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rlm@0 17 * Boston, MA 02111-1307, USA.
rlm@0 18 * Or go to http://www.gnu.org/copyleft/lgpl.html
rlm@0 19 */
rlm@0 20
rlm@0 21 #include "config.h"
rlm@0 22
rlm@0 23 #include <stdlib.h>
rlm@0 24
rlm@0 25 #include "alMain.h"
rlm@0 26 #include "alThunk.h"
rlm@0 27
rlm@0 28
rlm@0 29 static ALboolean *ThunkArray;
rlm@0 30 static ALuint ThunkArraySize;
rlm@0 31
rlm@0 32 static CRITICAL_SECTION ThunkLock;
rlm@0 33
rlm@0 34 void ThunkInit(void)
rlm@0 35 {
rlm@0 36 InitializeCriticalSection(&ThunkLock);
rlm@0 37 ThunkArraySize = 1;
rlm@0 38 ThunkArray = calloc(1, ThunkArraySize * sizeof(*ThunkArray));
rlm@0 39 }
rlm@0 40
rlm@0 41 void ThunkExit(void)
rlm@0 42 {
rlm@0 43 free(ThunkArray);
rlm@0 44 ThunkArray = NULL;
rlm@0 45 ThunkArraySize = 0;
rlm@0 46 DeleteCriticalSection(&ThunkLock);
rlm@0 47 }
rlm@0 48
rlm@0 49 ALenum NewThunkEntry(ALuint *index)
rlm@0 50 {
rlm@0 51 ALuint i;
rlm@0 52
rlm@0 53 EnterCriticalSection(&ThunkLock);
rlm@0 54
rlm@0 55 for(i = 0;i < ThunkArraySize;i++)
rlm@0 56 {
rlm@0 57 if(ThunkArray[i] == AL_FALSE)
rlm@0 58 break;
rlm@0 59 }
rlm@0 60
rlm@0 61 if(i == ThunkArraySize)
rlm@0 62 {
rlm@0 63 ALboolean *NewList;
rlm@0 64
rlm@0 65 NewList = realloc(ThunkArray, ThunkArraySize*2 * sizeof(*ThunkArray));
rlm@0 66 if(!NewList)
rlm@0 67 {
rlm@0 68 LeaveCriticalSection(&ThunkLock);
rlm@0 69 ERR("Realloc failed to increase to %u enties!\n", ThunkArraySize*2);
rlm@0 70 return AL_OUT_OF_MEMORY;
rlm@0 71 }
rlm@0 72 memset(&NewList[ThunkArraySize], 0, ThunkArraySize*sizeof(*ThunkArray));
rlm@0 73 ThunkArraySize *= 2;
rlm@0 74 ThunkArray = NewList;
rlm@0 75 }
rlm@0 76
rlm@0 77 ThunkArray[i] = AL_TRUE;
rlm@0 78 *index = i+1;
rlm@0 79
rlm@0 80 LeaveCriticalSection(&ThunkLock);
rlm@0 81
rlm@0 82 return AL_NO_ERROR;
rlm@0 83 }
rlm@0 84
rlm@0 85 void FreeThunkEntry(ALuint index)
rlm@0 86 {
rlm@0 87 EnterCriticalSection(&ThunkLock);
rlm@0 88
rlm@0 89 if(index > 0 && index <= ThunkArraySize)
rlm@0 90 ThunkArray[index-1] = AL_FALSE;
rlm@0 91
rlm@0 92 LeaveCriticalSection(&ThunkLock);
rlm@0 93 }