Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ronin Magus

Copying Mix_Chunk? (SDL_mixer help needed!)

This topic is 5654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I''m trying to write a function to copy a Mix_Chunk into a new one. Basically I''ve got a SoundEffect object and I want to write a copy constructor/operator= function. Any idea what''s wrong with my code?
  
void SoundEffect::__CopySound(const SoundEffect & s)
{
	// soundData is a Mix_Chunk *

	if(s.soundData)
	{
		// this frees this soundeffect''s soundData if it''s not NULL

		UnloadSound();

		// create a new chunk

		Mix_Chunk * newMixChunk = new Mix_Chunk;

		// copy s''s chunk data into new chunk

		newMixChunk->allocated = s.soundData->allocated;
		newMixChunk->alen = s.soundData->alen;
		newMixChunk->volume = s.soundData->volume;

		// create a sample buffer for the new sound

		newMixChunk->abuf = new Uint8[newMixChunk->alen];

		// copy sound data

		memcpy(newMixChunk->abuf, s.soundData->abuf, newMixChunk->alen);

		soundData = newMixChunk;	
	}
}
  
Please help me if you can, I''m stuck!

Share this post


Link to post
Share on other sites
Advertisement
I was mistaken. The problem with my code was not in this function but in a constructor not initializing a pointer to NULL.

So, if you need it, there''s some code to copy a Mix_Chunk into another!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!