DarkShadow44

waveOutOpen test 4

Jan 28th, 2024
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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. static int done = 0;
  15.  
  16. void CALLBACK _export waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
  17. {
  18. if (uMsg == WOM_DONE)
  19. {
  20. done = 1;
  21. }
  22. }
  23.  
  24. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  25. {
  26. HWAVEOUT hout;
  27. PCMWAVEFORMAT format;
  28. WAVEHDR* block;
  29. int result;
  30. FARPROC callback;
  31.  
  32. char* buffer;
  33. OFSTRUCT ofstruct;
  34. HFILE file;
  35.  
  36. if ((file = OpenFile("test.wav", &ofstruct, OF_READ)) == HFILE_ERROR) {
  37. error("CreateFile failed");
  38. }
  39.  
  40. block = (WAVEHDR*)LocalAlloc(0, 8000 + sizeof(WAVEHDR));
  41.  
  42. buffer = (char*)block + sizeof(WAVEHDR);
  43. block->dwBufferLength = 8000;
  44. block->lpData = buffer;
  45.  
  46. if (_lread(file, buffer, 8000) == HFILE_ERROR)
  47. {
  48. error("ReadFile failed");
  49. }
  50.  
  51. format.wf.wFormatTag = WAVE_FORMAT_PCM;
  52. format.wf.nChannels = 1;
  53. format.wf.nSamplesPerSec = 11025;
  54. format.wf.nBlockAlign = 1;
  55. format.wf.nAvgBytesPerSec = 11025;
  56. format.wBitsPerSample = 8;
  57.  
  58. callback = MakeProcInstance((FARPROC)waveOutProc, hInstance);
  59. if (callback == NULL)
  60. {
  61. error("MakeProcInstance failed");
  62. }
  63.  
  64. if ((result = waveOutOpen(&hout, WAVE_MAPPER, (LPWAVEFORMAT)&format, (DWORD)callback, 0, CALLBACK_FUNCTION)) != MMSYSERR_NOERROR)
  65. {
  66. char errorMsg[256];
  67. waveOutGetErrorText(result, errorMsg, sizeof(errorMsg));
  68. MessageBox(0, errorMsg, "waveOutOpen Error", 0);
  69. error("waveOutOpen failed");
  70. }
  71.  
  72. waveOutPrepareHeader(hout, block, sizeof(WAVEHDR));
  73. waveOutWrite(hout, block, sizeof(WAVEHDR));
  74. while(!done)
  75. {
  76. }
  77. error("success!");
  78. return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment