HANDLE hfile=CreateFile("boom.wave" ,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,F
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;
//read length
DWORD dwNumRead;
//length variable
DWORD dwLength;
DWORD dwDataLength;
//data buffer
UCHAR* ucTemp;
UCHAR* ucData;
LPWAVEFORMATEX lpWfx;
/*
BOOL ReadFile(
HANDLE hFile, // handle of file to read
LPVOID lpBuffer, // address of buffer that receives data
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // address of number of bytes read
LPOVERLAPPED lpOverlapped // address of structure for data
);
*/
ReadFile(hfile,Buffer,4,&dwNumRead,NULL);//"RIFF"
ReadFile(hfile,&dwLength,sizeof(dwLength),&dwNumRead,NULL);//length of file
ReadFile(hfile,Buffer,4,&dwNumRead,NULL);//"WAVE"
bool done=false;
while(!done)
{
ReadFile(hfile,Buffer,4,&dwNumRead,NULL);//chunk header
ReadFile(hfile,&dwLength,sizeof(dwLength),&dwNumRead,NULL);//length of chunk
ucTemp=new UCHAR[dwLength];
ReadFile(hfile,ucTemp,dwLength,&dwNumRead,NULL);
//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);
I am an idiot!!!!!!! Trying to load a wave file...........
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
Check the return values from all of your function calls and you''ll find your problem.
Stay Casual,
Ken
Drunken Hyena
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]
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
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
Just looking over the code, I could imagine this line causing a crash:
lpWfx has not been allocated yet and points to random memory, which you''re overwriting -> access violation.
-Markus-
//copy from buffermemcpy(lpWfx,ucTemp,dwLength);
lpWfx has not been allocated yet and points to random memory, which you''re overwriting -> access violation.
-Markus-
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement