Skip to main content
gamedev.net
🔒 Locked

Just a Basic Sound Buffer

Started by cilcoder Nov 22, 2003 at 1:28 AM 0 replies 900+ views
Original Post
cilcoder
cilcoder
Ok. I'm using C#. I'm trying to create a basic secondary buffer. I don't want to open a wav file or anything. I'm doing this because I want to be able to mix all my sounds myself. This is what I use
BufferDescription desc = new  BufferDescription();
priv_Buffer = new SecondaryBuffer(desc,priv_Device);
 
and I get a lovely:
quote:
An unhandled exception of type 'System.ArgumentException' occurred in microsoft.directx.directsound.dll Additional information: Value does not fall within the expected range.
It's just a guess but I'm thinkign it's because I don't set any of the BufferDescriptions properties or it's wave format. But I don't know what I should set them to(the Managed docs are terrible). Basically I want a good quality single channel buffer. Thanks for your help. UPDATE: I changed it to this:
			// Create a wave format object

			WaveFormat format = new WaveFormat();
			format.BitsPerSample = 16;
			format.BlockAlign = 4;
			format.Channels = 2;
			format.FormatTag = WaveFormatTag.Pcm;
			format.SamplesPerSecond = 22050;
			format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;

			// Create a buffer description

			BufferDescription desc = new  BufferDescription(format);
			desc.BufferBytes = 3 * format.AverageBytesPerSecond;
			
			// Actually create the buffer

			priv_Buffer = new SecondaryBuffer(desc,priv_Device);

            // Play the buffer

			priv_Buffer.Play(0,BufferPlayFlags.Default);
 
and I believe it works as I want it to. I get the error if I change it to only 1 channel. Any suggestions? [edited by - cilcoder on November 22, 2003 2:36:35 AM] [edited by - cilcoder on November 22, 2003 2:38:52 AM]
cilcoder
cilcoder
I just solved my problem. I know it''s weird solving my own problem within 10 minutes of posting it(I did work on it for a long time before posting). In case anyone is wondering, I solved it by changing the Block Alignment to 2. This made sense after I read MSDN about the C++ WAVEFORMAT Structure. It''s supposed to be set to the size of a sample. 16 bit sample size * 2 Channels = 4 bytes. With one channel it needed to be 2 bytes.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.