/* ============== S_LoadSound The filename may be different than sfx->name in the case of a forced fallback of a player specific sound ============== */ bool S_LoadSound( sfx_t *sfx ) { byte *data; short *samples; wavinfo_t info; int size; // player specific sounds are never directly loaded if ( sfx->soundName[0] == '*') return false; // load it in size = FS_ReadFile( sfx->soundName, (void **)&data ); if ( !data ) return false; info = GetWavinfo( sfx->soundName, data, size ); if ( info.channels != 1 ) { Com_Printf ("%s is a stereo wav file\n", sfx->soundName); FS_FreeFile (data); return false; } if ( info.width == 1 ) Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName); if ( info.rate != 22050 ) Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName); samples = reinterpret_cast<short*>(Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2)); sfx->lastTimeUsed = Com_Milliseconds()+1; // each of these compression schemes works just fine // but the 16bit quality is much nicer and with a local // install assured we can rely upon the sound memory // manager to do the right thing for us and page // sound in as needed if( sfx->soundCompressed == true) { sfx->soundCompressionMethod = 1; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) ); S_AdpcmEncodeSound(sfx, samples); } else { sfx->soundCompressionMethod = 0; sfx->soundLength = info.samples; sfx->soundData = NULL; ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, false ); } Hunk_FreeTempMemory(samples); FS_FreeFile( data ); return true; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[256]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; byte stackbuf[1*1024]; // avoid dirtying the cache heap // see if still in memory sc = (sfxcache_t *) Cache_Check (&s->cache); if (sc) return sc; // Con_Printf ("%s: %x\n", __thisfunc__, (int)stackbuf); // load it in q_strlcpy(namebuffer, "sound/", sizeof(namebuffer)); q_strlcat(namebuffer, s->name, sizeof(namebuffer)); // Con_Printf ("loading %s\n",namebuffer); data = FS_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf)); if (!data) { Con_Printf ("Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo (s->name, data, fs_filesize); if (info.channels != 1) { Con_Printf ("%s is a stereo sample\n",s->name); return NULL; } stepscale = (float)info.rate / shm->speed; len = info.samples / stepscale; len = len * info.width * info.channels; sc = (sfxcache_t *) Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); if (!sc) return NULL; sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); return sc; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound(sfx_t *s) { char namebuffer[256]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc = NULL; byte stackbuf[1 * 1024]; // avoid dirtying the cache heap // see if still in memory if (s->cache) sc = (sfxcache_t *) s->cache->getData(); if (sc) return sc; //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf); // load it in strcpy(namebuffer, "sound/"); strcat(namebuffer, s->name); // Con_Printf ("loading %s\n",namebuffer); data = COM_LoadStackFile(namebuffer, stackbuf, sizeof (stackbuf)); if (!data) { Con_Printf("Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo(s->name, data, com_filesize); if (info.channels != 1) { Con_Printf("%s is a stereo sample\n", s->name); return NULL; } stepscale = (float) info.rate / shm->speed; len = info.samples / stepscale; len = len * info.width * info.channels; s->cache = MemoryObj::Alloc(MemoryObj::CACHE, s->name, len + sizeof (sfxcache_t)); sc = (sfxcache_t *) s->cache->getData(); if (!sc) return NULL; sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx(s, sc->speed, sc->width, data + info.dataofs); return sc; }
sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[512]; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; // see if still in memory sc = (sfxcache_t*)Cache_Check(&s->cache); if(sc) return sc; // load it in strncpy(namebuffer, g_state.cSoundPath, sizeof(namebuffer)); strcat(namebuffer, s->name); uint8_t *data = (uint8_t*)COM_LoadHeapFile(namebuffer); if (!data) { Con_Warning("Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo (s->name, data, com_filesize); stepscale = (float)info.rate / shm->speed; len = info.samples / stepscale; len = len * info.width * info.channels; sc = (sfxcache_t*)Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); if (!sc) { free(data); return NULL; } sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); free(data); return sc; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[256]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; fs_offset_t filesize; // see if still in memory sc = Cache_Check (&s->cache); if (sc) return sc; // load it in strcpy (namebuffer, "sound/"); strcat (namebuffer, s->name); data = FS_LoadFile (namebuffer, false, &filesize); if (!data) return NULL; info = GetWavinfo (s->name, data, filesize); if (info.channels != 1) { Com_Printf ("%s is a stereo sample\n",s->name); return NULL; } stepscale = (float)info.rate / dma.speed; len = info.samples / stepscale; len = len * info.width * info.channels; sc = (sfxcache_t *) Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name); if (!sc) return NULL; sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); return sc; }
sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[512]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; byte stackbuf[1*1024]; // avoid dirtying the cache heap // see if still in memory sc = (sfxcache_t*)Cache_Check(&s->cache); if(sc) return sc; // load it in Q_strcpy(namebuffer,Global.cSoundPath); Q_strcat(namebuffer,s->name); data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf)); if (!data) { Con_Warning("Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo (s->name, data, com_filesize); stepscale = (float)info.rate / shm->speed; len = info.samples / stepscale; len = len * info.width * info.channels; sc = (sfxcache_t*)Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); if (!sc) return NULL; sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); return sc; }
/* ============== LoadSoundtrack ============== */ void LoadSoundtrack( void ){ char name[1024]; FILE *f; int len; int i, val, j; soundtrack = NULL; sprintf( name, "%svideo/%s/%s.wav", gamedir, base, base ); printf( "%s\n", name ); f = fopen( name, "rb" ); if ( !f ) { printf( "no soundtrack for %s\n", base ); return; } len = Q_filelength( f ); soundtrack = malloc( len ); fread( soundtrack, 1, len, f ); fclose( f ); wavinfo = GetWavinfo( name, soundtrack, len ); // count samples for compression memset( samplecounts, 0, sizeof( samplecounts ) ); j = wavinfo.samples / 2; for ( i = 0 ; i < j ; i++ ) { val = ( (unsigned short *)( soundtrack + wavinfo.dataofs ) )[i]; samplecounts[val]++; } val = 0; for ( i = 0 ; i < 0x10000 ; i++ ) if ( samplecounts[i] ) { val++; } printf( "%i unique sample values\n", val ); }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[MAX_QPATH]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; int size; char *name; if (s->name[0] == '*') return NULL; // see if still in memory sc = s->cache; if (sc) return sc; //Com_Printf ("S_LoadSound: %x\n", (int)stackbuf); // load it in if (s->truename) name = s->truename; else name = s->name; if (name[0] == '#') strcpy(namebuffer, &name[1]); else Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name); // Com_Printf ("loading %s\n",namebuffer); size = FS_LoadFile (namebuffer, (void **)&data); if (!data) { Com_DPrintf ("Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo (s->name, data, size); if (info.channels != 1) { Com_Printf ("%s is a stereo sample\n",s->name); FS_FreeFile (data); return NULL; } // jeyries : test, do not force 8 bit //s_loadas8bit->value = 0; stepscale = (float)info.rate / dma.speed; len = info.samples / stepscale; // moved here to save sound memory if (s_loadas8bit->value) len = len * 1 * info.channels; else len = len * info.width * info.channels; #if DEBUG_AUDIO Com_Printf ("loading %s : samples=%d width=%d rate=%d channels=%d memsize=%d\n", namebuffer, info.samples, info.width, info.rate, info.channels, len ); #endif sc = s->cache = Z_Malloc (len + sizeof(sfxcache_t)); if (!sc) { FS_FreeFile (data); return NULL; } sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; //sc->width = info.width; sc->stereo = info.channels; // moved here to save sound memory if (s_loadas8bit->value) sc->width = 1; else sc->width = info.width; //ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); ResampleSfx (s, info.rate ,info.width, data + info.dataofs); FS_FreeFile (data); return sc; }
/* ============== S_LoadSound The filename may be different than sfx->name in the case of a forced fallback of a player specific sound ============== */ qboolean S_LoadSound( sfx_t *sfx ) { byte *data; short *samples; wavinfo_t info; int size; // player specific sounds are never directly loaded if ( sfx->soundName[0] == '*' ) { return qfalse; } // load it in size = FS_ReadFile( sfx->soundName, (void **)&data ); if ( !data ) { return qfalse; } info = GetWavinfo( sfx->soundName, data, size ); if ( info.channels != 1 ) { Com_Printf( "%s is a stereo wav file\n", sfx->soundName ); FS_FreeFile( data ); return qfalse; } if ( info.width == 1 ) { Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName ); } if ( info.rate != 22050 ) { Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName ); } samples = Hunk_AllocateTempMemory( info.samples * sizeof( short ) * 2 ); // DHM - Nerve sfx->lastTimeUsed = Sys_Milliseconds() + 1; // each of these compression schemes works just fine // but the 16bit quality is much nicer and with a local // install assured we can rely upon the sound memory // manager to do the right thing for us and page // sound in as needed if ( s_nocompressed->value ) { sfx->soundCompressionMethod = 0; sfx->soundLength = info.samples; sfx->soundData = NULL; ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse ); } else if ( sfx->soundCompressed == qtrue ) { sfx->soundCompressionMethod = 1; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) ); S_AdpcmEncodeSound( sfx, samples ); #ifdef COMPRESSION } else if ( info.samples > ( SND_CHUNK_SIZE * 16 ) && info.width > 1 ) { sfx->soundCompressionMethod = 3; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) ); encodeMuLaw( sfx, samples ); } else if ( info.samples > ( SND_CHUNK_SIZE * 6400 ) && info.width > 1 ) { sfx->soundCompressionMethod = 2; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) ); encodeWavelet( sfx, samples ); #endif } else { sfx->soundCompressionMethod = 0; sfx->soundLength = info.samples; sfx->soundData = NULL; ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse ); } Hunk_FreeTempMemory( samples ); FS_FreeFile( data ); return qtrue; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[MAX_QPATH]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; int size; char *name; if (s->name[0] == '*') return NULL; // see if still in memory sc = s->cache; if (sc) return sc; //S_Printf(PRINT_ALL, "S_LoadSound: %x\n", (int)stackbuf); // load it in if (s->truename) name = s->truename; else name = s->name; if (name[0] == '#') strcpy(namebuffer, &name[1]); else Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name); // S_Printf(PRINT_ALL, "loading %s\n",namebuffer); size = FS_LoadFile (namebuffer, (void **)&data); if (!data) { S_Printf(PRINT_DEVELOPER, "Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo (s->name, data, size); if (info.channels != 1) { S_Printf(PRINT_ALL, "%s is a stereo sample\n",s->name); FS_FreeFile (data); return NULL; } stepscale = (float)info.rate / dma.speed; len = info.samples / stepscale; len = len * info.width * info.channels; sc = s->cache = Z_Malloc (len + sizeof(sfxcache_t)); if (!sc) { FS_FreeFile (data); return NULL; } sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); FS_FreeFile (data); return sc; }
/* ============== S_LoadWavFile ============== */ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) { fs_offset_t filesize; unsigned char *data; wavinfo_t info; int i, len; const unsigned char *inb; unsigned char *outb; // Already loaded? if (sfx->fetcher != NULL) return true; // Load the file data = FS_LoadFile(filename, snd_mempool, false, &filesize); if (!data) return false; // Don't try to load it if it's not a WAV file if (memcmp (data, "RIFF", 4) || memcmp (data + 8, "WAVE", 4)) { Mem_Free(data); return false; } if (developer_loading.integer >= 2) Con_Printf ("Loading WAV file \"%s\"\n", filename); info = GetWavinfo (sfx->name, data, (int)filesize); if (info.channels < 1 || info.channels > 2) // Stereo sounds are allowed (intended for music) { Con_Printf("%s has an unsupported number of channels (%i)\n",sfx->name, info.channels); Mem_Free(data); return false; } //if (info.channels == 2) // Log_Printf("stereosounds.log", "%s\n", sfx->name); sfx->format.speed = info.rate; sfx->format.width = info.width; sfx->format.channels = info.channels; sfx->fetcher = &wav_fetcher; sfx->fetcher_data = Mem_Alloc(snd_mempool, info.samples * sfx->format.width * sfx->format.channels); sfx->total_length = info.samples; sfx->memsize += filesize; len = info.samples * sfx->format.channels * sfx->format.width; inb = data + info.dataofs; outb = (unsigned char *)sfx->fetcher_data; if (info.width == 2) { if (mem_bigendian) { // we have to byteswap the data at load (better than doing it while mixing) for (i = 0;i < len;i += 2) { outb[i] = inb[i+1]; outb[i+1] = inb[i]; } } else { // we can just copy it straight memcpy(outb, inb, len); } } else { // convert unsigned byte sound data to signed bytes for quicker mixing for (i = 0;i < len;i++) outb[i] = inb[i] - 0x80; } if (info.loopstart < 0) sfx->loopstart = sfx->total_length; else sfx->loopstart = info.loopstart; sfx->loopstart = min(sfx->loopstart, sfx->total_length); sfx->flags &= ~SFXFLAG_STREAMED; return true; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound(sfx_t *s) { char namebuffer[256]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; byte stackbuf[1*1024]; // avoid dirtying the cache heap loadedfile_t *fileinfo; // 2001-09-12 Returning information about loaded file by Maddes // see if still in memory sc = Cache_Check(&s->cache); if (sc) { return sc; } //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf); // load it in Q_strcpy(namebuffer, "sound/"); Q_strcat(namebuffer, s->name); if (developer.value == 1) { Con_DPrintf("Loading %s\n",namebuffer); // Edited } // Con_Printf ("loading %s\n",namebuffer); // 2001-09-12 Returning information about loaded file by Maddes start /* data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf)); if (!data) */ fileinfo = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf)); if (!fileinfo) // 2001-09-12 Returning information about loaded file by Maddes end { Con_Printf("Couldn't load %s\n", namebuffer); return NULL; } data = fileinfo->data; // 2001-09-12 Returning information about loaded file by Maddes info = GetWavinfo(s->name, data, com_filesize); if (info.channels != 1) { Con_Printf("%s is a stereo sample\n",s->name); return NULL; } stepscale = (float)info.rate / shm->speed; len = info.samples / stepscale; len = len * info.width * info.channels; sc = Cache_Alloc(&s->cache, len + sizeof(sfxcache_t), s->name); if (!sc) { return NULL; } sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx(s, sc->speed, sc->width, data + info.dataofs); return sc; }
/* ============== S_LoadWavFile ============== */ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) { fs_offset_t filesize; unsigned char *data; wavinfo_t info; snd_format_t wav_format; snd_buffer_t* sb; // Already loaded? if (sfx->fetcher != NULL) return true; // Load the file data = FS_LoadFile(filename, snd_mempool, false, &filesize); if (!data) return false; // Don't try to load it if it's not a WAV file if (memcmp (data, "RIFF", 4) || memcmp (data + 8, "WAVE", 4)) { Mem_Free(data); return false; } if (developer_loading.integer >= 2) Con_Printf ("Loading WAV file \"%s\"\n", filename); info = GetWavinfo (sfx->name, data, (int)filesize); if (info.channels < 1 || info.channels > 2) // Stereo sounds are allowed (intended for music) { Con_Printf("%s has an unsupported number of channels (%i)\n",sfx->name, info.channels); Mem_Free(data); return false; } //if (info.channels == 2) // Log_Printf("stereosounds.log", "%s\n", sfx->name); // We must convert the WAV data from little endian // to the machine endianess before resampling it if (info.width == 2 && mem_bigendian) { unsigned int len, i; short* ptr; len = info.samples * info.channels; ptr = (short*)(data + info.dataofs); for (i = 0; i < len; i++) ptr[i] = LittleShort (ptr[i]); } wav_format.speed = info.rate; wav_format.width = info.width; wav_format.channels = info.channels; sb = Snd_CreateSndBuffer (data + info.dataofs, info.samples, &wav_format, snd_renderbuffer->format.speed); if (sb == NULL) { Mem_Free(data); return false; } sfx->fetcher = &wav_fetcher; sfx->fetcher_data = sb; sfx->total_length = sb->nbframes; sfx->memsize += sb->maxframes * sb->format.channels * sb->format.width + sizeof (*sb) - sizeof (sb->samples); if (info.loopstart < 0) sfx->loopstart = sfx->total_length; else sfx->loopstart = (unsigned int) ((double)info.loopstart * (double)sb->format.speed / (double)info.rate); sfx->loopstart = min(sfx->loopstart, sfx->total_length); sfx->flags &= ~SFXFLAG_STREAMED; Mem_Free (data); return true; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[MAX_QPATH]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; int size; const char *name; if (s->name[0] == '*') return NULL; // see if still in memory sc = s->cache; if (sc) return sc; // load it in name = (s->truename)? s->truename : s->name; if (name[0] == '#') Q_strncpyz(namebuffer, &name[1], sizeof(namebuffer)); else Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name); // Com_Printf ("loading %s\n",namebuffer); size = FS_LoadFile (namebuffer, (void **)&data); if (!data) { Com_DPrintf(DEVELOPER_MSG_IO, "Couldn't load %s\n", namebuffer); return NULL; } info = GetWavinfo (s->name, data, size); /* if (info.channels != 1) { Com_Printf ("%s is a stereo sample\n",s->name); FS_FreeFile (data); return NULL; }*/ if (info.channels < 1 || info.channels > 2) //CDawg changed { Com_Printf ("%s has an invalid number of channels\n", s->name); FS_FreeFile (data); return NULL; } if (info.width != 1 && info.width != 2) { Com_Printf("%s is not 8 or 16 bit\n", s->name); FS_FreeFile (data); return NULL; } stepscale = (float)info.rate / dma.speed; len = info.samples / stepscale; len = len * info.width * info.channels; if (info.samples == 0 || len == 0) { Com_Printf("%s has zero samples\n", s->name); FS_FreeFile (data); return NULL; } sc = s->cache = Z_Malloc (len + sizeof(sfxcache_t)); if (!sc) { FS_FreeFile (data); return NULL; } sc->length = info.samples; sc->loopstart = info.loopstart; // sc->speed = info.rate; sc->speed = info.rate * info.channels; //CDawg changed sc->width = info.width; sc->stereo = info.channels; // Knightmare: force loopstart if it's a music file if (!strncmp(namebuffer, "music/", 6) && (sc->loopstart == -1)) sc->loopstart = 0; // end Knightmare ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); FS_FreeFile (data); return sc; }
/* ============== S_LoadSound ============== */ sfxcache_t *S_LoadSound (sfx_t *s) { char namebuffer[MAX_QPATH]; byte *data; wavinfo_t info; int len; float stepscale; sfxcache_t *sc; int size; char *name; int close_file = 0; extern int s_in_precache; if(r_rache_is_empty) { return NULL; } if (s->name[0] == '*') return NULL; sc = (sfxcache_t *)Cache_Check (&ds_snd_cache,&(s->extradata)); if (sc) return sc; if(s_in_precache == 0) { s_in_precache = 0; } //Com_Printf ("S_LoadSound: %x\n", (int)stackbuf); // load it in if (s->truename) name = s->truename; else name = s->name; if (name[0] == '#') strcpy(namebuffer, &name[1]); else Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name); //printf ("%s\n",namebuffer); FILE *h = (FILE *)s->handle; size = s->len; if(h == 0) { close_file = 1; //size = FS_LoadFile (namebuffer, (void **)&data); size = FS_FOpenFile (namebuffer, &h); } else { ds_fseek (h, s->pos, SEEK_SET); } if (!h) { Com_DPrintf ("Couldn't load %s\n", namebuffer); return NULL; } r_cache_set_fail(0); data = (byte *)Z_Malloc(size); if (!data) { r_cache_set_fail(1); if(close_file) { ds_fclose (h); } Com_DPrintf ("Couldn't load %s\n", namebuffer); return NULL; } FS_Read (data, size, h); if(close_file) { ds_fclose (h); s->handle = g_pack_file; s->pos = g_pack_file_pos; s->len = g_pack_file_len; } info = GetWavinfo (s->name, data, size); if (info.channels != 1) { r_cache_set_fail(1); Com_DPrintf ("%s is a stereo sample\n",s->name); //FS_FreeFile (data); Z_Free(data); return NULL; } stepscale = (float)info.rate / dma.speed; len = info.samples / stepscale; /*if (info.width != 1) { r_cache_set_fail(1); printf ("%s is a 16 bit sample\n",s->name); //FS_FreeFile (data); Z_Free(data); return NULL; }*/ //we are forcing 8 bit sound //len = len * info.width * info.channels; Cache_Alloc(&ds_snd_cache,(cache_user_t *)&(s->extradata),len + sizeof(sfxcache_t) + 4,s->name); /*cached_t *ds = DS_CacheAlloc(&ds_snd_cache,len + sizeof(sfxcache_t) + 4); if(!ds) { r_cache_set_fail(1); //FS_FreeFile (data); Z_Free(data); return NULL; } ds->owner = (cached_t **)&s->cache; ds->visframe = r_framecount; sc = s->cache = (sfxcache_t *)(ds+1); */ //sc = s->cache = (sfxcache_t *)Hunk_Alloc (len + sizeof(sfxcache_t) + 4);//pad by 4 just to be certain - too lazy to check sc = (sfxcache_t *)s->extradata; if (!sc) { r_cache_set_fail(1); //FS_FreeFile (data); Z_Free(data); return NULL; } r_cache_set_fail(1); sc->length = info.samples; sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; sc->stereo = info.channels; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); //FS_FreeFile (data); Z_Free(data); return sc; }