Exemple #1
0
/*
=================
S_ReadRIFFHeader
=================
*/
static qboolean S_ReadRIFFHeader(fileHandle_t file, snd_info_t *info)
{
	char dump[16];
	//int wav_format;
	int bits;
	int fmtlen = 0;

	// skip the riff wav header
	FS_Read(dump, 12, file);

	// Scan for the format chunk
	if((fmtlen = S_FindRIFFChunk(file, "fmt ")) < 0)
	{
		Com_Printf( S_COLOR_RED "ERROR: Couldn't find \"fmt\" chunk\n");
		return qfalse;
	}

	// Save the parameters
	//wav_format = FGetLittleShort(file);
	FGetLittleShort(file);  // wav format
	info->channels = FGetLittleShort(file);
	info->rate = FGetLittleLong(file);
	FGetLittleLong(file);
	FGetLittleShort(file);
	bits = FGetLittleShort(file);

	if( bits < 8 )
	{
	  Com_Printf( S_COLOR_RED "ERROR: Less than 8 bit sound is not supported\n");
	  return qfalse;
	}

	info->width = bits / 8;
	info->dataofs = 0;

	// Skip the rest of the format chunk if required
	if(fmtlen > 16)
	{
		fmtlen -= 16;
		FS_Seek( file, fmtlen, FS_SEEK_CUR );
	}

	// Scan for the data chunk
	if( (info->size = S_FindRIFFChunk(file, "data")) < 0)
	{
		Com_Printf( S_COLOR_RED "ERROR: Couldn't find \"data\" chunk\n");
		return qfalse;
	}
	info->samples = (info->size / info->width) / info->channels;

	return qtrue;
}
static qboolean read_wav_header( int filenum, snd_info_t *info )
{
	char dump[16];
	int fmtlen = 0;

	// skip the riff wav header
	trap_FS_Read( dump, 12, filenum );

	// Scan for the format chunk
	if( !( fmtlen = findWavChunk( filenum, "fmt " ) ) )
	{
		Com_Printf( "Error reading wav header: No fmt chunk\n" );
		return qfalse;
	}

	// Save the parameters
	FGetLittleShort( filenum );
	info->channels = FGetLittleShort( filenum );
	info->rate = FGetLittleLong( filenum );
	FGetLittleLong( filenum );
	FGetLittleShort( filenum );
	info->width = FGetLittleShort( filenum ) / 8;

	// Skip the rest of the format chunk if required
	if( fmtlen > 16 )
	{
		fmtlen -= 16;
		skipChunk( filenum, fmtlen );
	}

	// Scan for the data chunk
	if( !( info->size = findWavChunk( filenum, "data" ) ) )
	{
		Com_Printf( "Error reading wav header: No data chunk\n" );
		return qfalse;
	}
	info->samples = ( info->size / info->width ) / info->channels;

	return qtrue;
}
Exemple #3
0
/*
======================
S_StartBackgroundTrack
======================
*/
void S_StartBackgroundTrack( const char *intro, const char *loop ){
	int		len;
	char	dump[16];
	char	name[MAX_QPATH];

	if ( !intro ) {
		intro = "";
	}
	if ( !loop || !loop[0] ) {
		loop = intro;
	}
	Com_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );

	Q_strncpyz( name, intro, sizeof( name ) - 4 );
	COM_DefaultExtension( name, sizeof( name ), ".wav" );

	if ( !intro[0] ) {
		return;
	}

	Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );

	// close the background track, but DON'T reset s_rawend
	// if restarting the same back ground track
	if ( s_backgroundFile ) {
		Sys_EndStreamedFile( s_backgroundFile );
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
	}

	//
	// open up a wav file and get all the info
	//
	FS_FOpenFileRead( name, &s_backgroundFile, qtrue );
	if ( !s_backgroundFile ) {
		Com_Printf( S_COLOR_YELLOW "WARNING: couldn't open music file %s\n", name );
		return;
	}

	// skip the riff wav header

	FS_Read(dump, 12, s_backgroundFile);

	if ( !S_FindWavChunk( s_backgroundFile, "fmt " ) ) {
		Com_Printf( "No fmt chunk in %s\n", name );
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
		return;
	}

	// save name for soundinfo
	s_backgroundInfo.format = FGetLittleShort( s_backgroundFile );
	s_backgroundInfo.channels = FGetLittleShort( s_backgroundFile );
	s_backgroundInfo.rate = FGetLittleLong( s_backgroundFile );
	FGetLittleLong(  s_backgroundFile );
	FGetLittleShort(  s_backgroundFile );
	s_backgroundInfo.width = FGetLittleShort( s_backgroundFile ) / 8;

	if ( s_backgroundInfo.format != WAV_FORMAT_PCM ) {
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
		Com_Printf("Not a microsoft PCM format wav: %s\n", name);
		return;
	}

	if ( s_backgroundInfo.channels != 2 || s_backgroundInfo.rate != 22050 ) {
		Com_Printf(S_COLOR_YELLOW "WARNING: music file %s is not 22k stereo\n", name );
	}

	if ( ( len = S_FindWavChunk( s_backgroundFile, "data" ) ) == 0 ) {
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
		Com_Printf("No data chunk in %s\n", name);
		return;
	}

	s_backgroundInfo.samples = len / (s_backgroundInfo.width * s_backgroundInfo.channels);

	s_backgroundSamples = s_backgroundInfo.samples;

	//
	// start the background streaming
	//
	Sys_BeginStreamedFile( s_backgroundFile, 0x10000 );
}
Exemple #4
0
/*
=================
WAV_ReadRIFFHeader
=================
*/
static qboolean WAV_ReadRIFFHeader(const char *name, FILE *file, snd_info_t *info)
{
	char dump[16];
	int wav_format;
	int fmtlen = 0;

	if (fread(dump, 1, 12, file) < 12 ||
	    strncmp(dump, "RIFF", 4) != 0 ||
	    strncmp(&dump[8], "WAVE", 4) != 0)
	{
		Con_Printf("%s is missing RIFF/WAVE chunks\n", name);
		return false;
	}

	/* Scan for the format chunk */
	if ((fmtlen = WAV_FindRIFFChunk(file, "fmt ")) < 0)
	{
		Con_Printf("%s is missing fmt chunk\n", name);
		return false;
	}

	/* Save the parameters */
	wav_format = FGetLittleShort(file);
	if (wav_format != WAV_FORMAT_PCM)
	{
		Con_Printf("%s is not Microsoft PCM format\n", name);
		return false;
	}

	info->channels = FGetLittleShort(file);
	info->rate = FGetLittleLong(file);
	FGetLittleLong(file);
	FGetLittleShort(file);
	info->bits = FGetLittleShort(file);

	if (info->bits != 8 && info->bits != 16)
	{
		Con_Printf("%s is not 8 or 16 bit\n", name);
		return false;
	}

	info->width = info->bits / 8;
	info->dataofs = 0;

	/* Skip the rest of the format chunk if required */
	if (fmtlen > 16)
	{
		fmtlen -= 16;
		fseek(file, fmtlen, SEEK_CUR);
	}

	/* Scan for the data chunk */
	if ((info->size = WAV_FindRIFFChunk(file, "data")) < 0)
	{
		Con_Printf("%s is missing data chunk\n", name);
		return false;
	}

	if (info->channels != 1 && info->channels != 2)
	{
		Con_Printf("Unsupported number of channels %d in %s\n",
						info->channels, name);
		return false;
	}
	info->samples = (info->size / info->width) / info->channels;
	if (info->samples == 0)
	{
		Con_Printf("%s has zero samples\n", name);
		return false;
	}

	return true;
}