28 #include "../idlib/precompiled.h"
33 #define USE_SOUND_CACHE_ALLOCATOR
35 #ifdef USE_SOUND_CACHE_ALLOCATOR
48 soundCacheAllocator.
Init();
98 if ( def && def->
name == fname ) {
100 if ( def->
purged && !loadOnDemandOnly ) {
111 if ( shandle != -1 ) {
122 if ( !loadOnDemandOnly ) {
185 int useCount, purgeCount;
186 common->
Printf(
"----- idSoundCache::EndLevelLoad -----\n" );
214 common->
Printf(
"----------------------------------------\n" );
223 int i,
j,
num = 0, total = 0;
240 sortIndex =
new int[
num];
242 for ( i = 0; i <
num; i++ ) {
246 for ( i = 0; i < num - 1; i++ ) {
247 for ( j = i + 1; j <
num; j++ ) {
248 if (
listCache[sortIndex[i]]->objectMemSize <
listCache[sortIndex[j]]->objectMemSize ) {
249 int temp = sortIndex[
i];
250 sortIndex[
i] = sortIndex[
j];
257 for ( i = 0; i <
num; i++ ) {
349 short *ncd = (
short *)nonCacheData;
362 common->
Error(
"idSoundCache: error generating OpenAL hardware buffer" );
368 common->
Error(
"idSoundCache: error loading data into OpenAL hardware buffer" );
390 short *converted = (
short *)soundCacheAllocator.
Alloc( shortSamples *
sizeof(
short ) );
393 for (
int i = 0;
i < shortSamples;
i++ ) {
397 for (
int i = 0;
i < shortSamples;
i += 2 ) {
419 if ( timestamp == FILE_NOT_FOUND_TIMESTAMP ) {
441 if (
timestamp == FILE_NOT_FOUND_TIMESTAMP ) {
451 if ( fh.
Open(
name, &info ) == -1 ) {
495 common->
Error(
"idSoundCache: error generating OpenAL hardware buffer" );
500 common->
Error(
"idSoundCache: error loading data into OpenAL hardware buffer" );
515 for ( j = 0; j <
Min( objectSize - i, blockSize ); j++ ) {
517 max = ((
short *)nonCacheData)[ i +
j ] > max ? ((
short *)nonCacheData)[ i +
j ] :
max;
539 common->
Error(
"idSoundCache: error generating OpenAL hardware buffer" );
550 if ( destData[
i*4] < -32768.0
f )
551 ((
short *)destData)[
i] = -32768;
552 else if ( destData[
i*4] > 32767.0
f )
553 ((
short *)destData)[
i] = 32767;
559 if ( destData[
i*2] < -32768.0
f )
560 ((
short *)destData)[
i] = -32768;
561 else if ( destData[
i*2] > 32767.0
f )
562 ((
short *)destData)[
i] = 32767;
568 if ( destData[
i] < -32768.0
f )
569 ((
short *)destData)[
i] = -32768;
570 else if ( destData[
i] > 32767.0
f )
571 ((
short *)destData)[
i] = 32767;
580 common->
Error(
"idSoundCache: error loading data into OpenAL hardware buffer" );
595 for ( j = 0; j <
Min( objectSize - i, blockSize ); j++ ) {
596 min = ((
short *)destData)[ i +
j ] < min ? ((
short *)destData)[ i +
j ] :
min;
597 max = ((
short *)destData)[ i +
j ] > max ? ((
short *)destData)[ i +
j ] :
max;
607 soundCacheAllocator.
Free( (
byte *)destData );
635 common->
Error(
"idSoundCache: error unloading data from OpenAL hardware buffer" );
660 ID_TIME_T newTimestamp;
665 if ( newTimestamp == FILE_NOT_FOUND_TIMESTAMP ) {
690 offset &= 0xfffffffe;
703 *size =
objectSize *
sizeof( short ) - offset;
static idCVar s_force22kHz
static idSampleDecoder * Alloc(void)
idStr & SetFileExtension(const char *extension)
bool FetchFromCache(int offset, const byte **output, int *position, int *size, const bool allowIO)
type * Alloc(const int num)
const int MIXBUFFER_SAMPLES
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
idCVar com_purgeAll("com_purgeAll","0", CVAR_BOOL|CVAR_ARCHIVE|CVAR_SYSTEM,"purge everything between level loads")
void AssureSize(int newSize)
idFileSystem * fileSystem
void SetGranularity(int newgranularity)
void ReloadSounds(bool force)
#define AL_NO_ERROR
Errors: No Error.
idSoundSample * FindSound(const idStr &fname, bool loadOnDemandOnly)
static idCVar s_decompressionLimit
int Open(const char *strFileName, waveformatex_t *pwfx=NULL)
void SetLockMemory(bool lock)
#define AL_FORMAT_STEREO16
idStr & BackSlashesToSlashes(void)
idList< idSoundSample * > listCache
int LengthIn44kHzSamples() const
void PrintMemInfo(MemInfo_t *mi)
static idStr FormatNumber(int number)
static int FtoiFast(float f)
int GetInteger(void) const
virtual idFile * OpenFileWrite(const char *relativePath, const char *basePath="fs_savepath")=0
static void Free(idSampleDecoder *decoder)
void DeleteContents(bool clear)
int Read(byte *pBuffer, int dwSizeToRead, int *pdwSizeRead)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
#define alIsExtensionPresent
virtual void MediaPrint(const char *fmt,...) id_attribute((format(printf
idDeclManager * declManager
void FreeEmptyBaseBlocks(void)
int Append(const type &obj)
ID_TIME_T GetNewTimeStamp(void) const
const idSoundSample * GetObject(const int index) const
const char * c_str(void) const
virtual void Decode(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest)=0
void CheckForDownSample()
virtual void CloseFile(idFile *f)=0
waveformatex_t objectInfo
virtual void Error(const char *fmt,...) id_attribute((format(printf
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
ID_INLINE T Min(T x, T y)
virtual int Printf(const char *fmt,...) id_attribute((format(printf