I need help loading a wave file for playing........

This is a discussion on I need help loading a wave file for playing........ within the Windows Programming forums, part of the Platform Specific Boards category; Well I have Isometric Game Programming with Directx 7.........this book has been "ok" so far, not great, just "ok", but ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    I need help loading a wave file for playing........

    Well I have Isometric Game Programming with Directx 7.........this book has been "ok" so far, not great, just "ok", but I must tell you that it did a terrible job on showing people how to load a freaking wave file for playing......I tried, I even basically copied the entire source code from the tutorial.......it compiled good but then it just crashed the small program.

    Code:
    
    	HANDLE hfile=CreateFile("boom.wave",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_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);

    Don't know what's wrong with it, I can't really check my mistakes on it, because as I said before I am not really up to date on knowing how to do that.......does anybody know what's wrong with this? Or knows a GOOD tutorial for this? I looked at a tutorial on gamedev.net and the guy says that doesn't even know if his tutorial compiles, so for someone like me who's having problems with it, maybe this isn't the best way to go. Or does anybody know how to do this an easier way? Please I need help people.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I should graduate June 12 from high school so now I am going to have more time to read more, because I couldn't read a lot because of school work.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    It troubles me that the file you attempt to load is named "boom.wave" and you fail to do any checking before you use the returned handle.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Originally posted by johnnie2
    It troubles me that the file you attempt to load is named "boom.wave" and you fail to do any checking before you use the returned handle.
    Ok besides that, any ideas why this doens't work?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I got it to work now people thank you, and yes there was also the problem of the file name "wave" it was indeed "wav" but there were other problems besides those, I got them taken care of though.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. multiple file loading. so fruturated! help!
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 05-09-2005, 05:13 PM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21