#### Archived

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

# I am an idiot!!!!!!! Trying to load a wave file...........

## Recommended Posts

incognito    122


ILE_ATTRIBUTE_NORMAL,NULL);
//set up buffer description

DSBUFFERDESC dsbd;
memset(&dsbd,0,sizeof(DSBUFFERDESC));

//size

dsbd.dwSize=sizeof(DSBUFFERDESC);

//flags

dsbd.dwFlags=DSBCAPS_LOCSOFTWARE;

char Buffer[5];
Buffer[4]=0;

//length variable

DWORD dwLength;

DWORD dwDataLength;

//data buffer

UCHAR* ucTemp;
UCHAR* ucData;

LPWAVEFORMATEX lpWfx;
/*

HANDLE hFile,	// handle of file to read
LPVOID lpBuffer,	// address of buffer that receives data
DWORD nNumberOfBytesToRead,	// number of bytes to read
LPOVERLAPPED lpOverlapped 	// address of structure for data
);
*/

bool done=false;

while(!done)
{

ucTemp=new UCHAR[dwLength];

//dependin on the chunk header, do something

if(strcmp("fmt ",Buffer)==0)// if the chunk contains the world "fmt "

{

//clear out format

memset(lpWfx,0,sizeof(WAVEFORMATEX));

//memcpy (&destination, &source, lenghtofbytes)

//copy from buffer

memcpy(lpWfx,ucTemp,dwLength);
}

if(strcmp("data",Buffer)==0)
{
//data chunk

//allocate data buffer

//copy length

dwDataLength=dwLength;

//copy buffer

memcpy(ucData,ucTemp,dwDataLength);

//we are done, and need no more chunks

done=true;
}

delete ucTemp;
}
//close the file

CloseHandle(hfile);
dsbd.dwBufferBytes=dwLength;

bullets->CreateSoundBuffer(&dsbd,&lpdsb, NULL);
DWORD buflen,buflen2;
void* bufptr;
lpdsb->Lock(0,0,&bufptr,&buflen,NULL,&buflen2,DSBLOCK_ENTIREBUFFER);
//copy from wave loader to sound buffer

memcpy(bufptr,ucData,dwLength);
lpdsb->Unlock(bufptr,buflen,NULL,buflen2);


Well so this crashed my computer..........any ideas? [edited by - jim adams on June 9, 2002 11:15:19 PM]

##### Share on other sites
DrunkenHyena    805
With no error checking, it could be in a number of places. Are you sure your file is called ''boom.wave'' rather than ''boom.wav''?

Check the return values from all of your function calls and you''ll find your problem.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
incognito    122
quote:
Original post by DrunkenHyena
With no error checking, it could be in a number of places. Are you sure your file is called 'boom.wave' rather than 'boom.wav'?

Check the return values from all of your function calls and you'll find your problem.

Stay Casual,

Ken
Drunken Hyena

lol well what do you know it's not "wave" but rather "wav" well now it doesn't crash my system but it closes the program back down again, because it doesn't work but I am making progress......about the error checking well I am an idiot. Uh let's see I just got the book doesn't really show me how to do that a lot so I am not very familiar with this. I just got Programming Windows hopefully this would help, don't know how to use a debugger either, can't find tutorial for that. so as you can see I am a very sad idiot.

[edited by - incognito on June 8, 2002 8:58:46 PM]

##### Share on other sites
Jason Zelos    211
Debugger:

Breakpoint: line at which program execution stops and returns control to the IDE/Debugger.

Watch: Keep an eye on the value of a varible (local or global)

Step Over: Run to next line in same function, skipping but running functions.

Step Through (or into): Run next line going into other functions if neccesary.

Step Out: Run to end of function.

If your using VC just check your using debug release (its default for a new project) and go to debug->start.

,Jay

##### Share on other sites
incognito    122
I got it to work now people thnk you in advance, now I need to look over the code

##### Share on other sites
Cygon    1219
Just looking over the code, I could imagine this line causing a crash:
//copy from buffermemcpy(lpWfx,ucTemp,dwLength);

lpWfx has not been allocated yet and points to random memory, which you''re overwriting -> access violation.

-Markus-

##### Share on other sites
Jason Zelos    211
LPWAVEFORMATEX lpWfx;if(strcmp("fmt ",Buffer)==0)// if the chunk contains the world "fmt " {//clear out formatmemset(lpWfx,0,sizeof(WAVEFORMATEX));//memcpy (&destination, &source, lenghtofbytes)//copy from buffermemcpy(lpWfx,ucTemp,dwLength);}

Are you sure that the WAVEFORMATEX is the same as the ''fmt '' chunk and in the correct size and order ?

#define FormatID ''fmt '' /* chunkID for Format Chunk. NOTE: There is a space at the end of this ID. */

typedef struct {
ID chunkID;
long chunkSize;

short wFormatTag;
unsigned short wChannels;
unsigned long dwSamplesPerSec;
unsigned long dwAvgBytesPerSec;
unsigned short wBlockAlign;
unsigned short wBitsPerSample;

/* Note: there may be additional fields here, depending upon wFormatTag. */
} FormatChunk;

Copied from: http://www.borg.com/~jglatt/tech/wave.htm

Type WAVEFORMATEX
lAvgBytesPerSec As Long
lExtra As Long
lSamplesPerSec As Long
nBitsPerSample As Integer
nBlockAlign As Integer
nChannels As Integer
nFormatTag As Integer
nSize As Integer
End Type

From MSDN.

,Jay