src/sgp/SoundMan.cc
/* Loads a sound file from disk into the cache, allocating memory and a slot
 * for storage.
 *
 * Returns: The sample index if successful, NO_SAMPLE if the file wasn't found
 *          in the cache. */
Loads a sound file from disk into the cache, allocating memory and a slot
for storage.

The sample index if successful, NO_SAMPLE if the file wasn't found
in the cache.
Loads a sound file from disk into the cache allocating memory and a slot for storage . The sample index if successful NO_SAMPLE if the file wasn ' t found in the cache .
static SAMPLETAG* SoundLoadDisk(const char* pFilename)
{
	Assert(pFilename != NULL);
	if(pFilename[0] == '\0') {
		SLOGA("SoundLoadDisk Error: pFilename is an empty string.");
		return NULL;
	}
	AutoSGPFile hFile;
	try
	{
		hFile = GCM->openGameResForReading(pFilename);
	}
	catch (const std::runtime_error& err)
	{
		SLOGA("SoundLoadDisk Error: %s", err.what());
		return NULL;
	}
	SDL_RWops* rwOps = FileGetRWOps(hFile);
	SDL_AudioSpec wavSpec;
	Uint32 wavLength;
	Uint8 *wavBuffer;
	if (SDL_LoadWAV_RW(rwOps, 0,  &wavSpec, &wavBuffer, &wavLength) == NULL) {
		SLOGE("SoundLoadDisk Error: Error loading file \"%s\"- %s", pFilename, SDL_GetError());
		return NULL;
	}
	SAMPLETAG* s = SoundLoadBuffer(wavSpec.format, wavSpec.channels, wavSpec.freq, wavBuffer, wavLength);
	SDL_FreeWAV(wavBuffer);
	SDL_FreeRW(rwOps);
	if (s == NULL)
	{
		SLOGE("SoundLoadDisk: Error converting sound file \"%s\"", pFilename);
		return NULL;
	}
	strcpy(s->pName, pFilename);
	return s;
}
static SAMPLETAG * SoundLoadDisk ( const char * pFilename ) { Assert ( pFilename != NULL ) ; if ( pFilename [ 0 ] == ' \0 ' ) { SLOGA ( " " ) ; return NULL ; } AutoSGPFile hFile ; try { hFile = GCM -> openGameResForReading ( pFilename ) ; } catch ( const std :: runtime_error & err ) { SLOGA ( " " , err . what ( ) ) ; return NULL ; } SDL_RWops * rwOps = FileGetRWOps ( hFile ) ; SDL_AudioSpec wavSpec ; Uint32 wavLength ; Uint8 * wavBuffer ; if ( SDL_LoadWAV_RW ( rwOps , 0 , & wavSpec , & wavBuffer , & wavLength ) == NULL ) { SLOGE ( " \" \" " , pFilename , SDL_GetError ( ) ) ; return NULL ; } SAMPLETAG * s = SoundLoadBuffer ( wavSpec . format , wavSpec . channels , wavSpec . freq , wavBuffer , wavLength ) ; SDL_FreeWAV ( wavBuffer ) ; SDL_FreeRW ( rwOps ) ; if ( s == NULL ) { SLOGE ( " \" \" " , pFilename ) ; return NULL ; } strcpy ( s -> pName , pFilename ) ; return s ; }
Loads a sound file from disk into the cache, allocating memory and a slot
 for storage.
Loads a sound file from disk into the cache allocating memory and a slot for storage .