Jump to content
  • Advertisement
Sign in to follow this  

XACT Noob Question

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

I want to put sound in my game so I started learning XACT Code Driven approach. I am trying to learn from the SDK sample and in that sample, information about wave file like duration is hard coded. In WAVEBANKENTRY, we need to set PlayRegion.dwLength variable. In sample, it is calculated using this formula, "dwSeconds * dwSampleRate * dwChannels * dwBits / 8". The variable dwSeconds is the duration of the wave and it is hard coded to 2 seconds. But in my game, I don't think it's a good idea to hard code those information so I began researching on the internet about wave file format and found this website: https://ccrma.stanfo...cts/WaveFormat/
Here's what the website has to say about byte 40 to 43 of wave file:


NumSamples * NumChannels * BitsPerSample/8

This is the number of bytes in the data.You can also think of this as the sizeof the read of the subchunk following this number.[/quote]

[font="Arial"]So, I am guessing that these bytes which are in little-endian order contain the values that I should pass in the [/font]WAVEBANKENTR::PlayRegion.dwLength variable. So to test it I wrote a small program, here's the code:

#include <iostream>

#include <fstream>
using namespace std;

int main() {
ifstream loadFile;
unsigned char fBytes[4];

loadFile.open("Example.wav", ios::binary);
if (loadFile.is_open()) {
loadFile.read((char*)fBytes, 4);
unsigned int waveLength;
waveLength = (fBytes[3] << 24) | (fBytes[2] << 16) | (fBytes[1] << 8) | fBytes[0];
cout << waveLength;
} else
cout << "Error opening wave file";

return 0;

Here's some result:

By using the hard coded data and formula from the sample the dwLength = 176400 (when duration = 2 sec)
By using my program the dwLength = 247286

By using the hard coded data and formula from the sample the dwLength = 1411200 (when duration = 8 sec)
By using my program the dwLength = 1525588

As you can see there is difference between the results from my program and the formula from sample but the difference is because the sample assumes that the Example.wav is 2 seconds and Example2.wav is 8 seconds. Actually Example.wav is greater than 2 seconds but less than 3 seconds while Example2.wav is just little bit greater than 8 seconds. So, for instance if we put 3 seconds in formula for Example.wav then the result is 264600.

So, I just wanted to ask, is this way of finding WAVEBANKENTR::PlayRegion.dwLength correct or not? Thank you...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!