CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    232

    waveOut Problems

    I'm trying to create a simple loobback between the microphone, then send it to the soundcard. I was successfully able to get data from the soundcard, but once I do waveOutWrite, I get error code 33, and I don't know what that means. I searched all over the winmm.h file, and I don't see anywhere error 33. What am I doing wrong?

    Here's code:

    Code:
    #include <windows.h> 
    #include <mmsystem.h>
    #include <stdio.h>
    
    #pragma comment (lib, "winmm.lib")
    
    HWAVEIN WaveInHandle;
    HWAVEOUT WaveOutHandle;
    
    WAVEHDR WaveHeader; 
    
    WAVEFORMATEX WaveFormat;
    
    int err;
    
    void CALLBACK waveOutProc(HWAVEOUT WaveOutHandle, UINT uMsg, DWORD dwInstance, DWORD
    						  dwParam1, DWORD dwParam2)
    {
    	if(uMsg == WOM_DONE)
    	{
    		printf("Successfully written sound!!\n");
    	}
    
    	if(uMsg == WOM_OPEN)
    	{
    		printf("WaveOut Opened....\n");
    	}
    
    	if(uMsg == WOM_CLOSE)
    	{
    		printf("WaveOut closed!!\n");
    	}
    }
    
    void CALLBACK waveInProc(HWAVEIN WaveInHandle, UINT uMsg, DWORD dwInstance, DWORD
    dwParam1, DWORD dwParam2) 
    { 
    	if (uMsg == WIM_DATA) 
    	{ 
    		printf("Got some data\n");
    		if ((waveInAddBuffer(WaveInHandle, &WaveHeader, sizeof(WaveHeader)))) 
    		{
    			printf("Error while adding the buffer again...\n");
    		}
    		
    		// error 33....
    		err = waveOutWrite(WaveOutHandle,&WaveHeader,sizeof(WaveHeader));
    		
    			if(err != MMSYSERR_NOERROR)
    			{
    				printf("Error playing back data!\n");
    			}
    		
    	}
    	
    	if (uMsg == WIM_OPEN)
    	{
    		printf("Device opened...\n");
    	}
    
    	if (uMsg == WIM_CLOSE) 
    	{
    		printf("Device closed...\n");
    	}
    }
    
    
    int main()
    {
    
    int intBufferSize = 44100;
    
    WaveFormat.nSamplesPerSec = 22050; 
    WaveFormat.nChannels = 1;
    WaveFormat.wBitsPerSample = 16; 
    WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
    WaveFormat.nBlockAlign = WaveFormat.nChannels * (WaveFormat.wBitsPerSample/8);
    WaveFormat.nAvgBytesPerSec = WaveFormat.nSamplesPerSec * WaveFormat.nBlockAlign;
    WaveFormat.cbSize = 0;
    
    WaveHeader.dwBufferLength = intBufferSize; 
    WaveHeader.lpData = (char *)VirtualAlloc(0, intBufferSize, MEM_COMMIT, PAGE_READWRITE);
    WaveHeader.dwFlags = 0; 
    WaveHeader.dwLoops = 0; 
    WaveHeader.lpNext = 0;
    
    if ((err = waveInOpen(&WaveInHandle, WAVE_MAPPER,
    &WaveFormat, (DWORD)&waveInProc, 0, CALLBACK_FUNCTION))) 
    {
    	printf("Error opening the device!\n"); 
    }
    
    		if ((waveInPrepareHeader(WaveInHandle, &WaveHeader, sizeof(WaveHeader))))
    		{ 
    			printf("Error while preparing header!\n");
    		} 
    
    if((err = waveOutOpen(&WaveOutHandle,WAVE_MAPPER,&WaveFormat,(DWORD)&waveOutProc,0,CALLBACK_FUNCTION)) != MMSYSERR_NOERROR)
    {
    	printf("Error opening WaveOut!");
    }
    
    if((err = waveOutPrepareHeader(WaveOutHandle,&WaveHeader,sizeof(WaveHeader))))
    {
    	printf("Error while preparing waveOut Header");
    }
    
    if ((waveInAddBuffer(WaveInHandle, &WaveHeader, sizeof(WaveHeader))))
    { 
    	printf("Error while adding buffer to queue!\n");
    }
    
    waveInStart(WaveInHandle);
    
    getchar();
    
    waveInClose(WaveInHandle);
    printf("Device closed...\n\n\n");
    
    return 0;
    
    }
    Need help with anything related to audio programming? I can help!

  2. #2
    Join Date
    Feb 2004
    Posts
    232
    *bump*
    Need help with anything related to audio programming? I can help!

  3. #3
    Join Date
    Mar 2004
    Posts
    43
    33 means another program has locked a part of the file(may be something else),you process cant access it
    the visual studio has a small tool to search the error messages by it's code ,y may find it in the vc program's entry,
    btw,in my computer ,it's name is errlook.exe

  4. #4
    Join Date
    Feb 2004
    Posts
    232
    I do lock memory for lpWave data, but thats the only way I was ever successful to read microphone data. Otherwise it won't work...What should I do?
    Need help with anything related to audio programming? I can help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured