Thread: Playing a Wave File

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

    Playing a Wave File

    this is what I have so far.........


    Code:
    
    class Sound
    {
    public:
    
    	Sound(char* FileName);
    	PBYTE GetMusicData(){ return SoundData;}
    
    
    
    
    private:
    	HANDLE MusicFile;
    	char Buffer [5];//we add one for the null terminator
    	char DataBuffer[4];
    	unsigned long FmtRead;
    	unsigned long RiffRead;
    	unsigned long WaveRead;
    	unsigned long LengthOfSound;
    	unsigned long LengthBuffer;
    	unsigned long LengthOfSoundWave;
    	unsigned long LengthBufferWave;
    
    	unsigned long GetPastHugeChunks;
    	unsigned long GetPastHugeChunksBuffer;
    
    	unsigned long LengthOfChunk;
    	unsigned long LengthOfChunkBuffer;
    	char* TEMP;
    	PBYTE SoundData;
    
    	PWAVEHDR     WaveHeader;
    	WAVEFORMATEX waveformat ;
    	HWAVEOUT     WaveOut;
    
    
    };
    
    
    
    Sound::Sound(char* FileName)
    {
    	//Load our Wave File
    	
    	Buffer[4]='\0';
    
    	MusicFile=CreateFile(FileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    	ReadFile(MusicFile,Buffer,4,&RiffRead,NULL);
    	ReadFile(MusicFile,&LengthOfSound,4,&LengthBuffer,NULL);
    	ReadFile(MusicFile,Buffer,4,&WaveRead,NULL);
    	ReadFile(MusicFile,Buffer,4,&FmtRead,NULL);
    	ReadFile(MusicFile,&LengthOfChunk,4,&LengthOfChunkBuffer,NULL);
    	TEMP=new char[LengthOfChunk];
    	ReadFile(MusicFile,TEMP,LengthOfChunk,&RiffRead,NULL);
    	
    	ReadFile(MusicFile,Buffer,4,&WaveRead,NULL);
    	ReadFile(MusicFile,&LengthOfSoundWave,4,&LengthBufferWave,NULL);
    
    	//allocate enough memory to copy of sound data
    
    	SoundData=new BYTE[LengthOfSoundWave];
    	ReadFile(MusicFile,SoundData,LengthOfSoundWave,&LengthBuffer,NULL);
    
    
    	WaveHeader=new WAVEHDR [sizeof (WAVEHDR)];
    
    
    	   waveformat.wFormatTag      = WAVE_FORMAT_PCM ;
                       waveformat.nChannels       = 1 ;
                       waveformat.nSamplesPerSec  = 11025;
                       waveformat.nAvgBytesPerSec = 11025;
                      waveformat.nBlockAlign     = 1 ;
                       waveformat.wBitsPerSample  = 8 ;
                       waveformat.cbSize          = 0 ;
    
    	   
    	   
    	   
    	   WaveHeader->lpData=SoundData;
    	   WaveHeader->dwBufferLength=LengthOfSoundWave;
    	   waveOutOpen (WaveOut, WAVE_MAPPER, &waveformat, NULL, 0, CALLBACK_WINDOW)
                                
    
    	
    	   waveOutWrite (WaveHeader, pWaveHdr2, sizeof (WAVEHDR)) ;
    
    
    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 have sucessfully loaded a file and extracted the the wave data from a file....but then when I try to use waveout stuff it doens't work.......I don't even know the orden in which is supposed to be called in. Could someone please the order in which this is called....
    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
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM