/* * Initializes the OpenAL backend */ qboolean AL_Init(void) { int i; if (!QAL_Init()) { Com_Printf("ERROR: OpenAL failed to initialize.\n"); return false; } s_openal_maxgain = Cvar_Get("s_openal_maxgain", "1.0", CVAR_ARCHIVE); /* check for linear distance extension */ if (!qalIsExtensionPresent("AL_EXT_LINEAR_DISTANCE")) { Com_Printf("ERROR: Required AL_EXT_LINEAR_DISTANCE extension is missing.\n"); QAL_Shutdown(); return false; } /* generate source names */ qalGetError(); qalGenSources(1, &streamSource); if (qalGetError() != AL_NO_ERROR) { Com_Printf("ERROR: Couldn't get a single Source.\n"); QAL_Shutdown(); return false; } else { /* -1 because we already got one channel for streaming */ for (i = 0; i < MAX_CHANNELS - 1; i++) { qalGenSources(1, &s_srcnums[i]); if (qalGetError() != AL_NO_ERROR) { break; } } if (i < MIN_CHANNELS - 1) { Com_Printf("ERROR: Required at least %d sources, but got %d.\n", MIN_CHANNELS, i + 1); QAL_Shutdown(); return false; } } s_numchannels = i; AL_InitStreamSource(); AL_InitUnderwaterFilter(); Com_Printf("Number of OpenAL sources: %d\n\n", s_numchannels); return true; }
/* ================= S_AL_SrcInit ================= */ static qboolean S_AL_SrcInit( void ) { int i; int limit; ALenum error; // Clear the sources data structure memset(srcList, 0, sizeof(srcList)); srcCount = 0; // Cap s_alSources to MAX_SRC limit = s_alSources->integer; if(limit > MAX_SRC) limit = MAX_SRC; else if(limit < 16) limit = 16; // Allocate as many sources as possible for(i = 0; i < limit; i++) { qalGenSources(1, &srcList[i].alSource); if((error = qalGetError()) != AL_NO_ERROR) break; srcCount++; } // All done. Print this for informational purposes Com_Printf( "Allocated %d sources.\n", srcCount); alSourcesInitialised = qtrue; return qtrue; }
/* * S_InitSources */ qboolean S_InitSources( int maxEntities, qboolean verbose ) { int i; memset( srclist, 0, sizeof( srclist ) ); src_count = 0; // Allocate as many sources as possible for( i = 0; i < MAX_SRC; i++ ) { qalGenSources( 1, &srclist[i].source ); if( qalGetError() != AL_NO_ERROR ) break; src_count++; } if( !src_count ) return qfalse; if( verbose ) Com_Printf( "allocated %d sources\n", src_count ); if( maxEntities < 1 ) return qfalse; entlist = ( sentity_t * )S_Malloc( sizeof( sentity_t ) * maxEntities ); src_inited = qtrue; return qtrue; }
qboolean AL_Init(void) { int i; Com_DPrintf("Initializing OpenAL\n"); if (!QAL_Init()) { goto fail0; } // check for linear distance extension if (!qalIsExtensionPresent("AL_EXT_LINEAR_DISTANCE")) { Com_SetLastError("AL_EXT_LINEAR_DISTANCE extension is missing"); goto fail1; } // generate source names qalGetError(); for (i = 0; i < MAX_CHANNELS; i++) { qalGenSources(1, &s_srcnums[i]); if (qalGetError() != AL_NO_ERROR) { break; } } Com_DPrintf("Got %d AL sources\n", i); if (i < MIN_CHANNELS) { Com_SetLastError("Insufficient number of AL sources"); goto fail1; } s_numchannels = i; Com_Printf("OpenAL initialized.\n"); return qtrue; fail1: QAL_Shutdown(); fail0: Com_EPrintf("Failed to initialize OpenAL: %s\n", Com_GetLastError()); return qfalse; }
qboolean AL_Init( void ) { int i; if( !QAL_Init() ) { Com_EPrintf( "OpenAL failed to initialize.\n" ); return qfalse; } // check for linear distance extension if( !qalIsExtensionPresent( "AL_EXT_LINEAR_DISTANCE" ) ) { Com_EPrintf( "Required AL_EXT_LINEAR_DISTANCE extension is missing.\n" ); goto fail; } // generate source names qalGetError(); for( i = 0; i < MAX_CHANNELS; i++ ) { qalGenSources( 1, &s_srcnums[i] ); if( qalGetError() != AL_NO_ERROR ) { break; } } if( i < MIN_CHANNELS ) { Com_EPrintf( "Required at least %d sources, but got %d.\n", MIN_CHANNELS, i ); goto fail; } s_numchannels = i; Com_Printf( "OpenAL initialized.\n" ); return qtrue; fail: QAL_Shutdown(); return qfalse; }