1
0

MCIPlay.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef NULLSOFT_MCIPLAYH
  2. #define NULLSOFT_MCIPLAYH
  3. #include "CDPlay.h"
  4. #include "main.h"
  5. class MciPlay : public C_CDPlay {
  6. public:
  7. MciPlay()
  8. {
  9. posinms=0;
  10. }
  11. int play(wchar_t drive, int track)
  12. {
  13. g_drive = drive;
  14. {
  15. MCI_SET_PARMS sMCISet;
  16. g_playtrack = track;
  17. if (!CDOpen(&playdev, drive, L"mci"))
  18. {
  19. playdev=0;
  20. g_drive = 0;
  21. return 1;
  22. }
  23. sMCISet.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
  24. MCISendCommand (playdev, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR) (LPVOID) &sMCISet);
  25. g_playlength=CDGetTrackLength(playdev,g_playtrack);
  26. sMCISet.dwTimeFormat = MCI_FORMAT_TMSF;
  27. MCISendCommand (playdev, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR) (LPVOID) &sMCISet);
  28. if (CDPlay(playdev,g_playtrack,FALSE,0,0,g_playlength))
  29. {
  30. CDClose(&playdev);
  31. playdev=0;
  32. g_drive = 0;
  33. return 1;
  34. }
  35. line.is_seekable=1;
  36. }
  37. line.SetInfo(1411,44,2,1);
  38. line.SAVSAInit(0,44100);
  39. line.VSASetInfo(2,44100);
  40. setvolume(a_v, a_p);
  41. {
  42. short dta[576*2] = {0};
  43. line.VSAAddPCMData(dta,2,16,0);
  44. line.SAAddPCMData(dta,2,16,0);
  45. }
  46. if (audioInit(/*config_sample*/))
  47. {
  48. }
  49. return 0;
  50. }
  51. void stop()
  52. {
  53. //CDStop(playdev);
  54. if (!done) CDPause(playdev);
  55. CDClose(&playdev);
  56. audioQuit();
  57. }
  58. void pause()
  59. {
  60. posinms=audioGetPos();
  61. CDPause(playdev);
  62. audioPause(1);
  63. }
  64. void unpause()
  65. {
  66. int pos=audioGetPos();
  67. CDPlay(playdev, g_playtrack, TRUE,pos/60000,(pos/1000)%60,g_playlength);
  68. audioPause(0);
  69. }
  70. int getlength()
  71. {
  72. return g_playlength;
  73. }
  74. int getoutputtime()
  75. {
  76. int p;
  77. if (paused)
  78. {
  79. return posinms;
  80. }
  81. p=audioGetPos();
  82. if (GetCurrentThreadId()==MainThreadId)
  83. {
  84. if ((p > g_playlength || (p-g_lastpos > 2000 && !isMediaPresent(playdev))) && !done)
  85. {
  86. done=1;
  87. PostMessage(line.hMainWindow,WM_WA_MPEG_EOF,0,0);
  88. }
  89. if (g_lastpos > p+2000)
  90. g_lastpos=p;
  91. }
  92. return p;
  93. }
  94. void setoutputtime(int time_in_ms)
  95. {
  96. CDPlay(playdev,g_playtrack,FALSE,time_in_ms/60000,(time_in_ms/1000)%60,g_playlength);
  97. if (paused)
  98. {
  99. audioPause(0);
  100. }
  101. audioSetPos(time_in_ms);
  102. g_lastpos=time_in_ms;
  103. if (paused)
  104. {
  105. audioPause(1);
  106. CDPause(playdev);
  107. }
  108. done=0;
  109. }
  110. void setvolume(int _a_v, int _a_p) {
  111. HMIXER hmix;
  112. int vol1, vol2;
  113. if (_a_v < 0) _a_v = 0;
  114. if (_a_v > 255) _a_v = 255;
  115. if (_a_p < -127) _a_p = -127;
  116. if (_a_p > 127) _a_p = 127;
  117. vol1 = vol2 = (_a_v*2048) / 255;
  118. if (_a_p > 0)
  119. {
  120. vol1 *= (127-_a_p);
  121. vol1 /= 127;
  122. }
  123. else if (_a_p < 0)
  124. {
  125. vol2 *= (_a_p+127);
  126. vol2 /= 127;
  127. }
  128. if (mixerOpen(&hmix,0,0,0,0) == MMSYSERR_NOERROR)
  129. {
  130. MIXERLINE ml={sizeof(ml),0};
  131. ml.dwComponentType=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;
  132. if (mixerGetLineInfo((HMIXEROBJ)hmix,&ml,MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
  133. {
  134. MIXERLINECONTROLS mlc = {sizeof(mlc),ml.dwLineID,};
  135. MIXERCONTROL mc={sizeof(mc),};
  136. mlc.cControls=1;
  137. mlc.cbmxctrl=sizeof(mc);
  138. mlc.pamxctrl=&mc;
  139. mlc.dwControlType=MIXERCONTROL_CONTROLTYPE_VOLUME;
  140. if (mixerGetLineControls((HMIXEROBJ)hmix,&mlc,MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
  141. {
  142. MIXERCONTROLDETAILS mcd = {sizeof(mcd),mc.dwControlID,ml.cChannels,};
  143. MIXERCONTROLDETAILS_UNSIGNED v[2];
  144. mcd.cbDetails=sizeof(MIXERCONTROLDETAILS_UNSIGNED);
  145. mcd.paDetails=v;
  146. v[0].dwValue=mc.Bounds.dwMinimum + (vol1*(mc.Bounds.dwMaximum-mc.Bounds.dwMinimum))/2048;
  147. v[1].dwValue=mc.Bounds.dwMinimum + (vol2*(mc.Bounds.dwMaximum-mc.Bounds.dwMinimum))/2048;
  148. if (mixerSetControlDetails((HMIXEROBJ)hmix,&mcd,0) == MMSYSERR_NOERROR)
  149. {
  150. // yay we're done!
  151. }
  152. // else MessageBox(NULL,"mixerSetLineControlDetails()","Error",MB_OK);
  153. }
  154. //else MessageBox(NULL,"mixerGetLineControls()","Error",MB_OK);
  155. }
  156. // else MessageBox(NULL,"mixerGetLineInfo()","Error",MB_OK);
  157. mixerClose(hmix);
  158. }
  159. //else MessageBox(NULL,"MixerOpen()","Error",MB_OK);
  160. }
  161. private:
  162. int posinms;
  163. MCIDEVICEID playdev;
  164. };
  165. #endif