Sign in to follow this  
Golgari

Problem with reading wav files into a DSound buffer

Recommended Posts

Hello, at first I wrote a class for all the DirectSound inizialisation and buffer creation. Then I also wrote a function to load a RIFF file in wave format. I had no problems with reading the header and fmt sub-chunks. I use fread() to read the sound data into a BYTE* array and there are no errors from the compiler. The problem is that I can't allocate the memory for the Array variable. I use the new operator to allocate the memory: WaveFileData.soundbuffer = new BYTE[WaveFileData.data_size]; //sprintf(str,"Datasize %d",WaveFileData.data_size); //MessageBox(hwnd,str,"CAP",MB_OK); if(WaveFileData.soundbuffer==NULL) { MessageBox(hwnd,"mem alloc failed","CAP",MB_OK); return false; } else { fread(WaveFileData.soundbuffer, sizeof(BYTE), WaveFileData.data_size, soundfile); } I use a structure(WaveFileData) to hold the header information and the sound data (lpbysoundbuffer) before I copy the data into a DirectSound buffer. I got no compiler errors so far. When I verify the Array if(lpbsoundbuffer==NULL) it is always NULL and I can't proceed with loading the data to the Soundbuffer. I used the same method to read and load a 24 bit bitmap file and it works fine. I've checked the size of the sound data also ... it runs but not like it should. And is there any harm if I call the "delete" not in the same function as the "new" (but in the same class of course)? It is a DirectSound problem so I think this is the best place to ask, else feel free to put it in the right section. [Edited by - Golgari on September 29, 2006 4:02:49 AM]

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