DarkShadow44

waveOutOpen test 3

Jan 28th, 2024
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. /* i686-w64-mingw32-gcc main.c -lwinmm */
  2. /* WATCOM=/opt/watcom PATH=$WATCOM/binl:$PATH INCLUDE=$WATCOM/h:$WATCOM/h/win LIB=$WATCOM/lib286:$WATCOM/lib286/dos wcl -bcl=windows main.c -q mmsystem.lib */
  3.  
  4. #include <windows.h>
  5. #include <mmsystem.h>
  6. #include <stdlib.h>
  7.  
  8. void error(const char* str)
  9. {
  10. MessageBox(0, str, "", 0);
  11. exit(1);
  12. }
  13.  
  14. void CALLBACK _export waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
  15. {
  16. if (uMsg == WOM_DONE)
  17. {
  18. error("success");
  19. }
  20. }
  21.  
  22. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  23. {
  24. HWAVEOUT hout;
  25. PCMWAVEFORMAT format;
  26. WAVEHDR* block;
  27. int result;
  28. FARPROC callback;
  29.  
  30. char* buffer;
  31. OFSTRUCT ofstruct;
  32. HFILE file;
  33.  
  34. if ((file = OpenFile("test.wav", &ofstruct, OF_READ)) == HFILE_ERROR) {
  35. error("CreateFile failed");
  36. }
  37.  
  38. block = (WAVEHDR*)LocalAlloc(0, 8000 + sizeof(WAVEHDR));
  39.  
  40. buffer = (char*)block + sizeof(WAVEHDR);
  41. block->dwBufferLength = 8000;
  42. block->lpData = buffer;
  43.  
  44. if (_lread(file, buffer, 8000) == HFILE_ERROR)
  45. {
  46. error("ReadFile failed");
  47. }
  48.  
  49. format.wf.wFormatTag = WAVE_FORMAT_PCM;
  50. format.wf.nChannels = 1;
  51. format.wf.nSamplesPerSec = 11025;
  52. format.wf.nBlockAlign = 1;
  53. format.wf.nAvgBytesPerSec = 11025;
  54. format.wBitsPerSample = 8;
  55.  
  56. callback = MakeProcInstance((FARPROC)waveOutProc, hInstance);
  57. if (callback == NULL)
  58. {
  59. error("MakeProcInstance failed");
  60. }
  61.  
  62. if ((result = waveOutOpen(&hout, WAVE_MAPPER, (LPWAVEFORMAT)&format, (DWORD)callback, 0, CALLBACK_FUNCTION)) != MMSYSERR_NOERROR)
  63. {
  64. char errorMsg[256];
  65. waveOutGetErrorText(result, errorMsg, sizeof(errorMsg));
  66. MessageBox(0, errorMsg, "waveOutOpen Error", 0);
  67. error("waveOutOpen failed");
  68. }
  69.  
  70. waveOutPrepareHeader(hout, block, sizeof(WAVEHDR));
  71. waveOutWrite(hout, block, sizeof(WAVEHDR));
  72. while(1)
  73. {
  74. }
  75.  
  76. return 0;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment