• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
blueshogun96

.wav Parser Making Popping Sounds

3 posts in this topic

I have this .wav parsing code that I've been using for quite some time, but there are some .wav files that will have a popping sound after it finishes playing.  I assume that it has something to do with my code since this doesn't happen when other .wav playing programs play the sound.  It shouldn't really matter, but I'm using OpenAL.

 

My code to load .wav files is in a single function.

 

ALuint wavstatic_open( char* filename )
{
	FILE* file = NULL;
	char* buffer = NULL;
	ALuint channels;
	ALuint frequency;
	ALuint format;
	ALuint bits;
	ALuint albuffer;
	long filesize = 0;
	int ret;

	/* Does the wav file exist? */
	file = fopen( filename, "rb" );
	if( !file )
		return 0;

	/* Get the file size */
	fseek( file, 0, SEEK_END );
	filesize = ftell(file);
	fseek( file, 0, SEEK_SET );

	/* Create buffers and sources */
	alGenBuffers( 1, &albuffer );
	if( alGetError() != AL_NO_ERROR )
	{
		fclose(file);
		free(buffer);
		alDeleteBuffers( 1, &albuffer );
		return 0;
	}

	/* Allocate this buffer to read bytes from as we go. */
	/* Should check for the strings "RIFF" and "WAVE" in the header, but I don't feel like
	   it at the moment, so... */
	buffer = malloc( filesize );
	fread( buffer, 1, 12, file );

	/* Check the wav file chunk header for the format information. If it's not there, forget it */
	fread( buffer, 1, 8, file );
	if( buffer[0] != 'f' || buffer[1] != 'm' || buffer[2] != 't' || buffer[3] != ' ' )
	{
		fclose(file);
		free(buffer);
		alDeleteBuffers( 1, &albuffer );
		return 0;
	}

	/* Read the wav format type. 1 == PCM.  If it's not, then we either
	   exit, or have to decode the format ourselves */
	fread( buffer, 1, 2, file );
	if( buffer[1] != 0 || buffer[0] != 1 )
	{
		fclose(file);
		free(buffer);
		alDeleteBuffers( 1, &albuffer );
		return 0;
	}

	/* Get the channel count */
	fread( buffer, 1, 2, file );
	channels = buffer[1]<<8;
	channels |= buffer[0];

	/* Get the sample frequency */
	fread( buffer, 1, 4, file );
	frequency  = buffer[3]<<24;
    frequency |= buffer[2]<<16;
    frequency |= buffer[1]<<8;
    frequency |= buffer[0];

	/* Ignore block size and bytes per second */
	fread( buffer, 1, 6, file );

	/* Get the bit depth */
	fread( buffer, 1, 2, file );
	bits = buffer[1]<<8;
	bits |= buffer[0];

	if( bits == 8 )
	{
		if( channels == 1 )
			format = AL_FORMAT_MONO8;
		else if( channels == 2 )
			format = AL_FORMAT_STEREO8;
	}
	else if( bits == 16 )
	{
		if( channels == 1 )
			format = AL_FORMAT_MONO16;
		else if( channels == 2 )
			format = AL_FORMAT_STEREO16;
	}

	/* Read the data chunk which will hold the decoded sample data */
	fread( buffer, 1, 8, file );
	if( buffer[0] != 'd' || buffer[1] != 'a' || buffer[2] != 't' || buffer[3] != 'a' )
	{
		fclose(file);
		free(buffer);
		alDeleteBuffers( 1, &albuffer );
		return 0;
	}

	/* Now read in the data section of this wav file */
	ret = fread( buffer, 1, filesize, file );
	alBufferData( albuffer, format, buffer, ret, frequency );
	if( alGetError() != AL_NO_ERROR )
	{
		fclose(file);
		free(buffer);
		alDeleteBuffers( 1, &albuffer );
		return 0;
	}

	/* That's all */
	fclose(file);
	free(buffer);

	return albuffer;
}

 

 

Not sure what it is.  The pop sound at the end only happens with a few .wav files.  The rest sound and work okay.  Any ideas?  Thanks.

 

Shogun.

0

Share this post


Link to post
Share on other sites

Pop sounds usually happen when there's a bigger step in the sound curve. Look at the end of the .wav in an audio editor. Ideally the sound curve is zero at the end to avoid popping.

Some audio players default to fading out when playing (WinAMP)

0

Share this post


Link to post
Share on other sites
some audio programs put some data after the "data" lump (note: lump==chunk).
(a common example here are lumps that indicate the audio program used and/or contain data similar to that found in an ID3 tag).

the reader code appears as if it will just read all the way to the end of the file, so if anything follows the main data lump, it may result in noise and/or pops, due to this data being treated as audio.

better could be taking the lump-size into account (for the "data" lump), then use this to know how many audio samples are present (rather than how much data was read).


secondary notes:
not all WAV files will have exactly the same length for the "fmt " lump (mostly N/A for PCM WAV files);
theoretically, other lumps may appear between "fmt " and "data" lumps (not actually ran into this AFAICT);
thoeretically, audio files may contain a 'LIST'/'wavl' lump instead of a single big 'data' lump (not seen AFAICT);
RIFF does this odd thing of padding lumps up to even (multiple of 2) sizes (N/A in this case);
...

the most likely scenario is here being data following 'data', because most of the other scenarios would likely result in the decoder rejecting the file (by not seeing 'data' where it is expected).


ADD, maybe try something like (trivial edit):
/* decode the length for "data" (32 bit little-endian DWORD) */
len = buffer[4] | (buffer[5]<<8) | (buffer[6]<<16) | (buffer[7]<<24);

/* Now read in the data section of this wav file */
ret = fread( buffer, 1, len, file ); Edited by cr88192
2

Share this post


Link to post
Share on other sites

This makes sense.  It would be best not to expect every chunk to come in a certain order.  Also, I'm pretty sure that it's another chunk after the actual data chunk.

 

So far, I've only had one instance where the data chunk wasn't where I expected it to be.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0