Jump to content
  • Advertisement


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

Ronin Magus

Copying Mix_Chunk? (SDL_mixer help needed!)

This topic is 5733 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 *

		// this frees this soundeffect''s soundData if it''s not NULL


		// 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
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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!