Sign in to follow this  
munawar

Difference between Resources.ResXResourceWriter, ResourceWriter and Sound Data

Recommended Posts

Hi All, First of all, apologies for using MDX.DirectSound--I know it's an old API, but SlimDX doesn't support DirectSound right now but I know they will in the future. I came across some curious behavior. I want to pack all my sounds in a binary resource file. .NET offered me both the Resources.ResXResourceWriter and Resources.ResourceWriter classes. When I wrote the files to a ResXResourceWriter buffer, my sounds were fifty mb total, but the resource file came out to be 80 mb. However, I was able to load the sound into a SecondaryBuffer by using the ResXResourceSet class, getting a byte array of the resource data and then creating a MemoryStream to pass to the constructor of the SecondaryBuffer. All this worked fine, but I wanted a smaller size file, and can't see why 50 mb of wave files would generate an 80 mb resource file. I then looked at the ResourceWriter class, and got the my desired results--a 50 mb resource file for 50 mb of wave data. However, I can't seem to load these resources with MemoryStream directly into SecondaryBuffers. What I have to do instead is specify the wave format using DirectSound.WaveFormat, create a SecondaryBuffer using BufferDescription and DirectSound.Device. After that, I have to write the byte array containing the binary data from the specific sound resource I want to play, into the SecondaryBuffer using Buffer.Write(int, Array, LockFlag). Finally my question! Smile. What's the difference between writing sounds to a resource file using ResXResourceWriter and simply ResourceWriter so that one forces me to specify the Pcm attributes and the other can simply load using a MemoryStream? I thought resources were exact replicas of the files they were created from. The reason I'm asking is because right now I have to specify arbitrary values for the wave format, such as 16 bits per sample for all sounds, 44100 hz samples per second for all sounds, etc. I've lost the ability to play all sounds fine regardless of their sampling rate--I've had to change the hz of some sounds because they were not recorded at 44100 hz, unless someone knows of any methods that would gather this data for me using the byte array returned by the source reader. Thanks so much for your help in advance. Munawar

Share this post


Link to post
Share on other sites
Hi,
This is just a message to let you all know that I managed to find a solution. Using ResourceWriter worked fine to compile a resource file, but instead of using ResourceReader.GetResourceData(), I tried using ResourceSet.GetObject(resourceName as String) and converting the Object it returned into a byte array. I then used that to construct the MemoryStream, which I passed to the SecondaryBuffer, and it worked, so I'm writing this message for the record in case anyone else has this issue. Still baffled as to why ResourceSet worked, but not plain old ResourceReader though.
Munawar

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this