Jump to content
  • Advertisement


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



This topic is 6171 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

Hi, I have a quick question. Do you have to use DuplicateBuffer(), if you want to be playing a buffer from two different locations. Can you just do what you would do in directdraw with a surface:

CreateSurface(Surface1); // Create the surface

LoadImageIntoSurface(Surface1, "Something.bmp); // Fill it with data

Surface2 = Surface1; // Have Surface2 point to Surface1

Surface1->AddRef(); // Add a reference to Surface1

Well, I am pretty sure you have to use DuplicateBuffer(), but it seems quite slow so I want to make sure. Also, this doesn't pertain to DirectSound, but, is there any way to get a random number between 2 numbers. For instance, I want to get a number between 12 and 50. I have written a function to do this, but it is quite pimitive. Here is the source:
int RandomIntBetween(int RangeLow, int RangeHigh) {

	int RandomNumber; // Random Number holder

	for(;;) {
                // Get a random number using 'RangeHigh'

		RandomNumber = rand() * (RangeHigh+1) / (RAND_MAX + 1);
                // If the random number is not between RaneLow 

                //and RangeHigh, try again.

		if(RandomNumber >= RangeLow ) break;

	return RandomNumber;

Although it works, it has the potential to be very slow. If I were to try to get a random number between 50,000 and 51,000 it could take awhile. Well if anyone could help me with either of these two questions, I would definitely appreciate it. Thanks for your time. James Edited by - JSCFaith on October 30, 2001 10:31:04 PM

Share this post

Link to post
Share on other sites
Um, you could of course just do:

Get a random number between 0 and maximum-minimum
add minimum

Share this post

Link to post
Share on other sites
Oh, and if my understanding is correct, which it is not always... Duplicating DirectSound buffers will not duplicate the actual sound data in memory, just let seperate DSBuffer objects utilize the same region.

Share this post

Link to post
Share on other sites
What you describe in your code example is basically what DuplicateSoundBuffer is doing. It is leaving the data alone and just getting another pointer. However, with DirectSoundBuffer there is a lot of internal data relating to the sound playback (eg. A marker to indicate where in thebuffer it is currently playing). Just addreffing an DirectSoundBuffer instance will cause the instance specific data to be duplicated too and so the two sounds will not be able to be played independantly.

I have not experienced performance problems with DuplicateSoundBuffer, though. By definition it should be a fast call.


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!