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



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