Пример #1
0
/*
=================
S_WAV_CodecOpenStream
=================
*/
snd_stream_t *S_WAV_CodecOpenStream(const char *filename)
{
	snd_stream_t *rv;

	// Open
	rv = S_CodecUtilOpen(filename, &wav_codec);
	if(!rv)
		return NULL;

	// Read the RIFF header
	if(!S_ReadRIFFHeader(rv->file, &rv->info))
	{
		S_CodecUtilClose(&rv);
		return NULL;
	}

	return rv;
}
Пример #2
0
/*
=================
S_WAV_CodecLoad
=================
*/
void *S_WAV_CodecLoad(const char *filename, snd_info_t *info)
{
	fileHandle_t file;
	void         *buffer;

	// Try to open the file
	FS_FOpenFileRead(filename, &file, qtrue);
	if (!file)
	{
		if (com_developer->integer)
		{
			Com_Printf(S_COLOR_RED "ERROR: Could not open \"%s\"\n", filename);
		}
		return NULL;
	}

	// Read the RIFF header
	if (!S_ReadRIFFHeader(file, info))
	{
		FS_FCloseFile(file);
		if (com_developer->integer)
		{
			Com_Printf(S_COLOR_RED "ERROR: Incorrect/unsupported format in \"%s\"\n", filename);
		}
		return NULL;
	}

	// Allocate some memory
	buffer = Z_Malloc(info->size);
	if (!buffer)
	{
		FS_FCloseFile(file);
		Com_Printf(S_COLOR_RED "ERROR: Out of memory reading \"%s\"\n", filename);
		return NULL;
	}

	// Read, byteswap
	FS_Read(buffer, info->size, file);
	S_ByteSwapRawSamples(info->samples, info->width, info->channels, (byte *)buffer);

	// Close and return
	FS_FCloseFile(file);
	return buffer;
}