Question about playing .wav files using mmio functions
-
I am trying to code a program to play wave files using the low level functions provided by VC++ such as the "MMIO" functions. I encountered problems in "waveOutOpen","waveOutWrite","waveOutPrepareHeader" functions. A handle was passed as the first parameter to each of the function calls.The error i got was "waveOutOpen cannot convert parameter one from void ** to struct HWaveout_ **".the same error was shown for each of the other function calls(i.e for waveOutPrepareHeader etc),subsequently i typecasted the handle as (HWAVEOUT*).While this caused the errors to stop the program did not run as the header was not being prepared. The code is as shown below. HANDLE hWaveOut; MMRESULT ReturnCode = waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL); if(ReturnCode) { AfxMessageBox("Could Not Open Wave Device",MB_OK | MB_ICONSTOP,NULL); return(FALSE); } ReturnCode=waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader)); if(ReturnCode) { AfxMessageBox("Could Not Prepare Header",MB_OK | MB_ICONSTOP,NULL); waveOutClose((HWAVEOUT)hWaveOut); return(FALSE); } ReturnCode = waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader)); if(ReturnCode) { AfxMessageBox("Error Writing to Wave Device",MB_OK | MB_ICONSTOP,NULL); waveOutClose((HWAVEOUT)hWaveOut); return(FALSE); } Could anyone let me know how to proceed? novicedude
-
I am trying to code a program to play wave files using the low level functions provided by VC++ such as the "MMIO" functions. I encountered problems in "waveOutOpen","waveOutWrite","waveOutPrepareHeader" functions. A handle was passed as the first parameter to each of the function calls.The error i got was "waveOutOpen cannot convert parameter one from void ** to struct HWaveout_ **".the same error was shown for each of the other function calls(i.e for waveOutPrepareHeader etc),subsequently i typecasted the handle as (HWAVEOUT*).While this caused the errors to stop the program did not run as the header was not being prepared. The code is as shown below. HANDLE hWaveOut; MMRESULT ReturnCode = waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL); if(ReturnCode) { AfxMessageBox("Could Not Open Wave Device",MB_OK | MB_ICONSTOP,NULL); return(FALSE); } ReturnCode=waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader)); if(ReturnCode) { AfxMessageBox("Could Not Prepare Header",MB_OK | MB_ICONSTOP,NULL); waveOutClose((HWAVEOUT)hWaveOut); return(FALSE); } ReturnCode = waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader)); if(ReturnCode) { AfxMessageBox("Error Writing to Wave Device",MB_OK | MB_ICONSTOP,NULL); waveOutClose((HWAVEOUT)hWaveOut); return(FALSE); } Could anyone let me know how to proceed? novicedude
Your first function, waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL); seems to be correctly, but more correctly is to use function like that: HWAVEOUT hWaveOut; waveOutOpen(&hWaveOut,WAVE_MAPPER,(LPWAVEFORMATEX)&PCMWaveFmtRecord,NULL,NULL,NULL); (where PCMWaveFmtRecord identifies the format of the waveform-audio data to be sent to the device). The second and third function: waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader)); waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader)); is not correctly because the first parrametter pased is need to be a HWAVEOUT handle and not a reference. Correctly is: waveOutPrepareHeader(hWaveOut,&WaveHeader,sizeof(WAVEHDR)); waveOutWrite(hWaveOut,&WaveHeader,sizeof(WAVEHDR));