1 // **************************************************************************** 2 // 3 // CMtcSync.h 4 // 5 // Include file for interfacing with the CMtcSync class. 6 // 7 // This class manages syncing to MIDI time code. 8 // 9 // Set editor tabs to 3 for your viewing pleasure. 10 // 11 // ---------------------------------------------------------------------------- 12 // 13 // ---------------------------------------------------------------------------- 14 // 15 // Copyright Echo Digital Audio Corporation (c) 1998 - 2004 16 // All rights reserved 17 // www.echoaudio.com 18 // 19 // This file is part of Echo Digital Audio's generic driver library. 20 // 21 // Echo Digital Audio's generic driver library is free software; 22 // you can redistribute it and/or modify it under the terms of 23 // the GNU General Public License as published by the Free Software Foundation. 24 // 25 // This program is distributed in the hope that it will be useful, 26 // but WITHOUT ANY WARRANTY; without even the implied warranty of 27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 // GNU General Public License for more details. 29 // 30 // You should have received a copy of the GNU General Public License 31 // along with this program; if not, write to the Free Software 32 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, 33 // MA 02111-1307, USA. 34 // 35 // **************************************************************************** 36 37 // Prevent problems with multiple includes 38 #ifndef _MTCQUEUEOBJECT_ 39 #define _MTCQUEUEOBJECT_ 40 41 typedef struct tMTC_DATA 42 { 43 DWORD dwData; // DWORD here wastes memory, but is easier to debug... 44 DWORD dwTimestamp; // Timestamp in terms of the DSP sample count 45 } MTC_DATA; 46 47 48 // 49 // CMtcSync 50 // 51 class CMtcSync 52 { 53 public: 54 // 55 // Construction/destruction 56 // 57 CMtcSync( CEchoGals *pEG ); 58 ~CMtcSync(); 59 60 // 61 // Methods used to store MTC data & timestamps 62 // 63 void StoreTimestampHigh(DWORD dwData); 64 void StoreTimestampLow(DWORD dwData); 65 void StoreMtcData(DWORD dwData); 66 67 // 68 // Call this to process the MTC data and adjust the sample rate 69 // 70 void Sync(); 71 72 // 73 // Reset the state of things 74 // 75 void Reset(); 76 77 // 78 // Overload new & delete so memory for this object is allocated from non-paged memory. 79 // 80 PVOID operator new( size_t Size ); 81 VOID operator delete( PVOID pVoid ); 82 83 protected: 84 85 enum // Quarter-frame message types 86 { 87 MTC_QF_FRAME_LSN = 0, 88 MTC_QF_FRAME_MSN, 89 MTC_QF_SECOND_LSN, 90 MTC_QF_SECOND_MSN, 91 MTC_QF_MINUTE_LSN, 92 MTC_QF_MINUTE_MSN, 93 MTC_QF_HOUR_LSN, 94 MTC_QF_HOUR_MSN, 95 96 MTC_TOLERANCE = 64, 97 MTC_DAMPING = 98 * 0x1000 / 100, // 95% in 12 bit fixed point 98 99 MAX_DFRAME_SYNC_COUNT = 4096, 100 101 DAMPING_RATIO_LIMIT_LOW = 4096 - 16, 102 DAMPING_RATIO_LIMIT_HIGH = 4096 + 16 103 }; 104 105 // 106 // Midi buffer management 107 // 108 MTC_DATA m_Buffer[ ECHO_MTC_QUEUE_SZ ]; 109 DWORD m_dwFill; 110 DWORD m_dwDrain; 111 112 // 113 // State information 114 // 115 DWORD m_dwBaseSampleRate; 116 117 DWORD m_dwLastDframeTimestamp; // Timestamp of last double frame 118 // in units of samples 119 120 DWORD m_iSamplesPerDframe; 121 DWORD m_dwFramesPerSec; 122 123 DWORD m_dwLastDframe; // Last doubleframe number 124 DWORD m_dwCurrentDframe; // Doubleframe number currently being assembled 125 // from MTC data bytes 126 127 DWORD m_iNumDframesSynced; // How many frames have elapsed since the 128 // last sample rate adjustment 129 130 INT32 m_iNumSamplesSynced; // Sum of all actual timestamp deltas since 131 // last sample rate adjustment 132 DWORD m_dwNextQfType; 133 134 DWORD m_dwTemp; 135 136 // 137 // Other stuff 138 // 139 CEchoGals *m_pEG; 140 141 friend class CMidiInQ; 142 143 }; // class CMtcSync 144 145 typedef CMtcSync * PCMtcSync; 146 147 #endif 148 149 // *** CMtcSync.H *** 150