BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CMtcSync.h
blobb0ab478b86c772e7a2969508ce1e74f45a2a17ee
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.
11 // ----------------------------------------------------------------------------
13 // This file is part of Echo Digital Audio's generic driver library.
14 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
15 // All rights reserved
16 // www.echoaudio.com
18 // This library is free software; you can redistribute it and/or
19 // modify it under the terms of the GNU Lesser General Public
20 // License as published by the Free Software Foundation; either
21 // version 2.1 of the License, or (at your option) any later version.
23 // This library is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 // Lesser General Public License for more details.
28 // You should have received a copy of the GNU Lesser General Public
29 // License along with this library; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 // ****************************************************************************
34 // Prevent problems with multiple includes
35 #ifndef _MTCQUEUEOBJECT_
36 #define _MTCQUEUEOBJECT_
38 typedef struct tMTC_DATA
40 DWORD dwData; // DWORD here wastes memory, but is easier to debug...
41 DWORD dwTimestamp; // Timestamp in terms of the DSP sample count
42 } MTC_DATA;
46 // CMtcSync
48 class CMtcSync
50 public:
52 // Construction/destruction
54 CMtcSync( CEchoGals *pEG );
55 ~CMtcSync();
58 // Methods used to store MTC data & timestamps
59 //
60 void StoreTimestampHigh(DWORD dwData);
61 void StoreTimestampLow(DWORD dwData);
62 void StoreMtcData(DWORD dwData);
65 // Call this to process the MTC data and adjust the sample rate
67 void Sync();
70 // Reset the state of things
72 void Reset();
75 // Overload new & delete so memory for this object is allocated from non-paged memory.
77 PVOID operator new( size_t Size );
78 VOID operator delete( PVOID pVoid );
80 protected:
82 enum // Quarter-frame message types
84 MTC_QF_FRAME_LSN = 0,
85 MTC_QF_FRAME_MSN,
86 MTC_QF_SECOND_LSN,
87 MTC_QF_SECOND_MSN,
88 MTC_QF_MINUTE_LSN,
89 MTC_QF_MINUTE_MSN,
90 MTC_QF_HOUR_LSN,
91 MTC_QF_HOUR_MSN,
93 MTC_TOLERANCE = 64,
94 MTC_DAMPING = 98 * 0x1000 / 100, // 95% in 12 bit fixed point
96 MAX_DFRAME_SYNC_COUNT = 4096,
98 DAMPING_RATIO_LIMIT_LOW = 4096 - 16,
99 DAMPING_RATIO_LIMIT_HIGH = 4096 + 16
103 // Midi buffer management
105 MTC_DATA m_Buffer[ ECHO_MTC_QUEUE_SZ ];
106 DWORD m_dwFill;
107 DWORD m_dwDrain;
110 // State information
112 DWORD m_dwBaseSampleRate;
114 DWORD m_dwLastDframeTimestamp; // Timestamp of last double frame
115 // in units of samples
117 DWORD m_iSamplesPerDframe;
118 DWORD m_dwFramesPerSec;
120 DWORD m_dwLastDframe; // Last doubleframe number
121 DWORD m_dwCurrentDframe; // Doubleframe number currently being assembled
122 // from MTC data bytes
124 DWORD m_iNumDframesSynced; // How many frames have elapsed since the
125 // last sample rate adjustment
127 INT32 m_iNumSamplesSynced; // Sum of all actual timestamp deltas since
128 // last sample rate adjustment
129 DWORD m_dwNextQfType;
131 DWORD m_dwTemp;
134 // Other stuff
136 CEchoGals *m_pEG;
138 friend class CMidiInQ;
140 }; // class CMtcSync
142 typedef CMtcSync * PCMtcSync;
144 #endif
146 // *** CMtcSync.H ***