Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0 KiB

  1. //
  2. // syslink.cpp
  3. //
  4. /*
  5. Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  6. */
  7. #include "common.h"
  8. #include "private.h"
  9. #define STR_MODULENAME "DDKSynth.sys:SysLink: "
  10. /*****************************************************************************
  11. *****************************************************************************
  12. * CDmSynthStream-- ISynthSinkDMus implementation
  13. *****************************************************************************
  14. ****************************************************************************/
  15. #pragma code_seg()
  16. /*****************************************************************************
  17. * CDmSynthStream::Render()
  18. *****************************************************************************
  19. * Render is called from the port driver, to fill the given buffer. This is
  20. * in turn forwarded to the synth (which -- roughly -- goes to the different
  21. * voices, which goes to the DigitalAudios, which goes to the mix functions).
  22. *
  23. * Typically, a synthesizer manages converting messages into
  24. * rendered wave data in two processes. First, it time stamps the MIDI
  25. * messages it receives from the application via calls to
  26. * PlayBuffer and places them in its own internal queue.
  27. *
  28. * Then, in response to Render, it generates audio by pulling MIDI
  29. * messages from the queue and synthesizing the appropriate tones within
  30. * the time span of the requested render buffer.
  31. *
  32. * As the synthesizer renders the MIDI messages into the buffer, it
  33. * calls RefTimeToSample to translate the MIDI time stamps into sample
  34. * positions. This guarantees extremely accurate timing.
  35. */
  36. void CDmSynthStream::Render(
  37. IN PBYTE pBuffer,
  38. IN DWORD dwLength,
  39. IN LONGLONG llPosition)
  40. {
  41. PAGED_CODE();
  42. _DbgPrintF(DEBUGLVL_BLAB, ("CDmSynthStream::Render"));
  43. ASSERT(pBuffer);
  44. m_pSynth->Mix((short*)pBuffer, dwLength, llPosition);
  45. m_llLastPosition = llPosition + dwLength;
  46. }
  47. /*****************************************************************************
  48. * CDmSynthStream::SyncToMaster()
  49. *****************************************************************************
  50. * Sync this stream to the master clock, using the given slave time, and
  51. * whether we are starting now.
  52. */
  53. STDMETHODIMP
  54. CDmSynthStream::SyncToMaster(IN REFERENCE_TIME rtSlaveTime,
  55. IN BOOL fStart)
  56. {
  57. PAGED_CODE();
  58. _DbgPrintF(DEBUGLVL_BLAB, ("CDmSynthStream::SyncToMaster"));
  59. REFERENCE_TIME rtMasterTime;
  60. m_pMasterClock->GetTime(&rtMasterTime);
  61. if (!fStart)
  62. {
  63. m_SampleClock.SyncToMaster(rtSlaveTime, rtMasterTime);
  64. }
  65. else
  66. {
  67. m_llStartPosition = ((rtSlaveTime / 1000) * m_PortParams.SampleRate) / 10000;
  68. m_SampleClock.Start(m_pMasterClock, m_PortParams.SampleRate, m_llStartPosition);
  69. }
  70. return S_OK;
  71. }
  72. /*****************************************************************************
  73. * CDmSynthStream::SampleToRefTime()
  74. *****************************************************************************
  75. * Translate between sample time and reference clock time.
  76. */
  77. STDMETHODIMP
  78. CDmSynthStream::SampleToRefTime(IN LONGLONG llSampleTime,
  79. OUT REFERENCE_TIME * prtTime)
  80. {
  81. _DbgPrintF(DEBUGLVL_BLAB, ("CDmSynthStream::SampleToRefTime"));
  82. ASSERT(prtTime);
  83. m_SampleClock.SampleToRefTime(llSampleTime + m_llStartPosition, prtTime);
  84. return S_OK;
  85. }
  86. /*****************************************************************************
  87. * CDmSynthStream::RefTimeToSample()
  88. *****************************************************************************
  89. * Translate between sample time and reference clock time.
  90. */
  91. STDMETHODIMP
  92. CDmSynthStream::RefTimeToSample(IN REFERENCE_TIME rtTime,
  93. OUT LONGLONG * pllSampleTime)
  94. {
  95. _DbgPrintF(DEBUGLVL_BLAB, ("CDmSynthStream::RefTimeToSample"));
  96. ASSERT(pllSampleTime);
  97. *pllSampleTime = m_SampleClock.RefTimeToSample(rtTime) - m_llStartPosition;
  98. return S_OK;
  99. }