/*************************************************************************** * Copyright (C) 2004 by Johan Maes * * on4qz@telenet.be * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SYNCPROC_H #define SYNCPROC_H #define SYNCENTRIES 5 /*!< number of sync entries in the syncarray */ #define SHORTSYNC 1 #define SHORTNOSYNC 2 #define INVALIDFREQ 4 #define ISVISCODE 8 #define DELTAFREQ 150. #define DELTAFREQREPTONE 80. #define TRACKDEPTH 900 #include class vuMeter; enum detectState {dSTART,dEND}; /*! \struct syncRecord \brief record describing synchronisation info */ struct syncRecord { unsigned int sync; /*!< number of samples during (position in ringbuffer) */ unsigned int noSync; /*!< number of samples during no-sync */ float freq; /*!< frequency during sync */ float nosFreq; /*!< frequency during nosync */ unsigned int pos; /*!< position of the trailing edge of the sync in the ringbuffer */ unsigned int status; /*!< stores qualification of sync and nosync periods */ }; struct trackRecord { unsigned int sync; /*!< number of samples during (position in ringbuffer) */ unsigned int noSync; /*!< number of samples during no-sync */ float freq; /*!< frequency during sync */ float nosFreq; /*!< frequency during nosync */ int pos; /*!< position of the trailing edge of the sync in the ringbuffer */ unsigned int sc; /*! samplecounter */ int lineCounter; /*!< stores the linecounter */ }; /** @author Johan Maes */ class syncProc : public QObject { Q_OBJECT public: syncProc(); ~syncProc(); void init(); bool recordSync(float f,bool s,int tPos, bool &endSync); unsigned int evaluateSync(int sens,unsigned int &pos,bool &afterVIS); unsigned evaluateVIS(unsigned int &pos); void clearSyncArray(); bool inSync(); bool isInSync() {return (syncCounter!=0);} void trackSync(float &f,bool s,int tPos,int lineCount); float avgFreq; bool evaluateTrackSync(float &clock,int &offset); bool isOutOfSync(); void restartTrackSync(); void setOffsetCompensation(int oc); bool checkRepeaterTone(float f,bool Init); signals: void setOffset(int val,int pos); private: syncRecord syncArray[SYNCENTRIES+1]; void shiftUpSyncArray(int start); void shiftDownSyncArray(int start); bool oldS; unsigned int syncIndex; unsigned int syncCounter; trackRecord trackArray[TRACKDEPTH]; unsigned int trackIndex; unsigned int outOfSync; int offsetCompensation; double lineLen; void calcRegression(int numb,double &a,double &b,double &r); bool correctValues(int numb,double &a,double &b,double &r); void initTrackSync(); int lastCorrected; bool detectTone(float f,float freq,bool Init); detectState dState; int count; }; extern syncProc syncProcessor; #endif