[Amis-vcs] SF.net SVN: amis: [2206] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <dan...@us...> - 2007-10-18 15:08:16
|
Revision: 2206 http://amis.svn.sourceforge.net/amis/?rev=2206&view=rev Author: daniel_weck Date: 2007-10-18 08:08:14 -0700 (Thu, 18 Oct 2007) Log Message: ----------- - Daniel WECK * Removed unused codec (ThirdPartyAudio) * Moved mffmTimeCode inside AmisAudio Modified Paths: -------------- branches/amis3/AmisAudio/AmisAudio.cpp branches/amis3/AmisAudio/AmisAudio.h branches/amis3/AmisAudio/AmisAudio.vcproj Added Paths: ----------- branches/amis3/AmisAudio/mffmTimeCode/ branches/amis3/AmisAudio/mffmTimeCode/SmilTimeCode.H branches/amis3/AmisAudio/mffmTimeCode/counter.H branches/amis3/AmisAudio/mffmTimeCode/field.H branches/amis3/AmisAudio/mffmTimeCode/masterCounter.H branches/amis3/AmisAudio/mffmTimeCode/masterCounterArray.H branches/amis3/AmisAudio/mffmTimeCode/timeCode.H branches/amis3/AmisAudio/mffmTimeCode/win32fix.H Removed Paths: ------------- branches/amis3/3rdPartyAudio/ branches/amis3/mffmTimeCode/ Modified: branches/amis3/AmisAudio/AmisAudio.cpp =================================================================== --- branches/amis3/AmisAudio/AmisAudio.cpp 2007-10-18 15:02:10 UTC (rev 2205) +++ branches/amis3/AmisAudio/AmisAudio.cpp 2007-10-18 15:08:14 UTC (rev 2206) @@ -33,7 +33,7 @@ #include <process.h> -#include "win32Fix.H" +//#include "win32Fix.H" //#include "../AmisGuiMFC/Brain/Preferences.h" Modified: branches/amis3/AmisAudio/AmisAudio.h =================================================================== --- branches/amis3/AmisAudio/AmisAudio.h 2007-10-18 15:02:10 UTC (rev 2205) +++ branches/amis3/AmisAudio/AmisAudio.h 2007-10-18 15:08:14 UTC (rev 2206) @@ -46,7 +46,7 @@ //#include "StdAfx.h" #include <windows.h> -#include "smilTimeCode.H" +#include "./mffmTimeCode/smilTimeCode.H" //for message sending ... typedef void (*sendMessageCallbackFn)(void *); Modified: branches/amis3/AmisAudio/AmisAudio.vcproj =================================================================== --- branches/amis3/AmisAudio/AmisAudio.vcproj 2007-10-18 15:02:10 UTC (rev 2205) +++ branches/amis3/AmisAudio/AmisAudio.vcproj 2007-10-18 15:08:14 UTC (rev 2206) @@ -23,7 +23,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories=""../AmisGuiMFC2/include/";"../AmisCore/include/";"../3rdPartyAudio"; "../mffmTimeCode"" + AdditionalIncludeDirectories=""../AmisGuiMFC2/include/";"../AmisCore/include/"" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_WINDOWS;_USRDLL;AMISAUDIO_EXPORTS" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -274,6 +274,9 @@ RelativePath="AmisAudio.h"> </File> <File + RelativePath=".\mffmTimeCode\counter.H"> + </File> + <File RelativePath=".\TPBReader2\dmp\dmp.h"> </File> <File @@ -283,21 +286,36 @@ RelativePath=".\TPBReader2\dmp\DmpPpg.h"> </File> <File + RelativePath=".\mffmTimeCode\field.H"> + </File> + <File RelativePath=".\TPBReader2\dmp\iTPBTS.h"> </File> <File + RelativePath=".\mffmTimeCode\masterCounter.H"> + </File> + <File + RelativePath=".\mffmTimeCode\masterCounterArray.H"> + </File> + <File RelativePath=".\TPBReader2\RegOcx.h"> </File> <File RelativePath=".\TPBReader2\dmp\Resource.h"> </File> <File + RelativePath=".\mffmTimeCode\SmilTimeCode.H"> + </File> + <File RelativePath="StdAfx.h"> </File> <File RelativePath=".\TPBReader2\dmp\StdAfxFIX.h"> </File> <File + RelativePath=".\mffmTimeCode\timeCode.H"> + </File> + <File RelativePath=".\TPBReader2\dmp\TransformSample.h"> </File> <File @@ -309,6 +327,9 @@ <File RelativePath=".\TPBReader2\dmp\VuppSample.h"> </File> + <File + RelativePath=".\mffmTimeCode\win32fix.H"> + </File> </Filter> <Filter Name="Resource Files" Added: branches/amis3/AmisAudio/mffmTimeCode/SmilTimeCode.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/SmilTimeCode.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/SmilTimeCode.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,209 @@ +/* + mffm Time Code + Time Code for multimedia systems + + Copyright (C) 2000-2005 Matt R. Flax <fl...@ie...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You have received a copy of the GNU Lesser General Public License + along with this library. +*/ +#ifndef SMILTIMECODE_H_ +#define SMILTIMECODE_H_ + +#define SMILTIMECODE_VERSION 0.0 + +#include "timeCode.H" +#include <strstream> +//#include "win32fix.H" + +//Begins the implementation of SMIL timing : +// http://www.w3.org/TR/2005/REC-SMIL2-20050107/smil-timing.html#Timing-LanguageDefinition + +//The array type is char so that it can contain a smil mark up of a time reference +#define ARRAYTYPE char +//There are four fields in smil ... hours, minutes, seconds and milliseconds +#define FIELDCOUNT 4 +//The master counter will not work with X under win32 so for portability, use no GUI - field +#define MASTERCOUNTERTYPE MasterCounter<field, FIELDCOUNT> +//The maximum field counts +#define MAX_HOURS 300 +#define MAX_MINUTES 60 +#define MAX_SECONDS 60 +#define MAX_MILLISECONDS 1000 + +#define DEFAULTBUFLEN 512 + +/** This class loads a TimeCode structure with the correct + beginning and end. A SMIL type of string is used as input for + both times + +*/ +class SmilTimeCode : public TimeCode<MASTERCOUNTERTYPE, ARRAYTYPE> { + + //This function performs the raw string to milliseconds conversion + //Input is a SMIL compliant string + //Output is a millisecond count. + int convertStrToTimeCode(char *strSMIL){ + //Step for conversion : + // Work out the time metric : this correcponds to the maximum specified time field + // Work out whether the last field is a fractional part and remember that info. + // Hold fields in an array 'counts' + // Load a master counter with appropriate millisecond count + // Return the master counter millisecond count + + //Find the metric and thus the end of the stream + //Form an array to hold the metric digit values + int startMetric=0; + + char * tempI; + if ((tempI=strstr(strSMIL,"ms"))!=NULL){ + //we are receiving milliseconds + tempI[0]='\0'; //Mark a new end to the string + startMetric=0; //Indicate the start metric + } else if ((tempI=strstr(strSMIL,"s"))!=NULL){ + //we are receiving seconds + tempI[0]='\0'; //Mark a new end to the string + startMetric=1; //Indicate the start metric + } else if ((tempI=strstr(strSMIL,"min"))!=NULL){ + //we are receiving minutes + tempI[0]='\0'; //Mark a new end to the string + startMetric=2; //Indicate the start metric + } else if ((tempI=strstr(strSMIL,"h"))!=NULL){ + //we are receiving hours + tempI[0]='\0'; //Mark a new end to the string + startMetric=3; //Indicate the start metric + } else { + //No specification of metric. + // Check number of ':' in the string + int cnt=0; + for (int i=0;i<strlen(strSMIL);i++){ + if (strSMIL[i]==':') + cnt++; + } + if (cnt==3)//We are using hours minutes seconds milliseconds + startMetric=3; + else if (cnt==2)//We are using hours minutes seconds + startMetric=3; + else if (cnt==1)//We are using minutes seconds + startMetric=2; + else //We are using seconds + startMetric=1; + } + + cout<<"startMetric="<<startMetric<<endl; + + //Make sure '.' is translated to ':' + float convertLastField=0; //Use this to force fractional conversion of the smallest field + if ((tempI=strstr(strSMIL,"."))!=NULL){ + convertLastField=atof(tempI); + tempI[0]=':'; + cout<<convertLastField<<endl; + } + //if (convertLastField) + // cout<<"Last field needs conversion"<<endl; + + //Form an array to hold values counts[4]={milliseconds, sec, min, hours} + int counts[4]={-1,-1,-1,-1}; + + //Fill up to the start metric with zeros + for (int i=FIELDCOUNT-1;i>startMetric;i--) + counts[i]=0; + + /* for (i=0;i<FIELDCOUNT;i++) + cout<<counts[i]<<'\t'; + cout<<endl; + */ + + int howMany, howManyNot, origStartMetric; //Indicates how many tokens (and non tokens) + parseTok:{ + howMany=howManyNot=0; + origStartMetric=startMetric; + + //Work out how many tokens to parse + istrstream buf(strSMIL); + char tempS[DEFAULTBUFLEN]; + while (buf.getline(tempS,DEFAULTBUFLEN,':')){//Fill the array from the end + if (strlen(tempS)){ //Guard against no first token e.g. .25 (meaning 0.25 seconds) + howMany++; + if (startMetric>=0) + counts[startMetric]=atoi(tempS); + //cout<<tempS<<'\t'<<counts[startMetric]<<endl;; + } else { + howManyNot++; + if (startMetric>=0) + counts[startMetric]=0; + } + startMetric--; + } + cout<<howMany<<" Fields"<<endl; + } + + if (origStartMetric+1<howMany){ + cout<<"metric (h,min,s or ms) doesn't match the number of fields, autocorrecting"<<endl; + startMetric=howMany-1; + goto parseTok; + } + + for (i=0;i<FIELDCOUNT;i++) + cout<<counts[i]<<'\t'; + cout<<endl; + + //Now load up the masterCounter + MASTERCOUNTERTYPE tempTime (128,MAX_HOURS,MAX_MINUTES,MAX_SECONDS,MAX_MILLISECONDS); + tempTime=0; + int factor=1,fractionalFactor=1;//Factor to multiply by + //tempTime.dump(); + for (i=0;i<FIELDCOUNT;i++){ + switch (i) { + case 0: factor=1; fractionalFactor*=MAX_MILLISECONDS; + break; + case 1: factor*=MAX_MILLISECONDS; fractionalFactor*=MAX_SECONDS; + break; + case 2: factor*=MAX_SECONDS; fractionalFactor*=MAX_MINUTES; + break; + case 3: factor*=MAX_MINUTES; break; + default: cout<<"SmilTimeCode::convertStrToTimeCode field count exceeded : Error 2"<<endl; break; + } + if (counts[i]>=0){ //Check that a token exists + if (convertLastField>0){ //We must use a fractional concept + //cout<<"fractional i="<<i<<" counts[i]="<<counts[i]<<" fractionalFactor = "<<fractionalFactor<<endl; + //char tempS[DEFAULTBUFLEN]; + //sprintf(tempS,"0.%d\0",counts[i]); + //tempTime+=atof(tempS)*fractionalFactor; + //cout<<"fractional i="<<i<<" convertLastField="<<convertLastField<<" fractionalFactor = "<<fractionalFactor<<endl; + tempTime+=convertLastField*(fractionalFactor+1); //Check this +1 : introduced to remove 1ms error e.g. 0.120 goes to 0.119 without this +1 + convertLastField=0; //Ensure it doesn't happen again. + } else //Regular update + tempTime+=counts[i]*factor; + } + } + + // tempTime.dump(); + + return tempTime.getCount(); + } + +public: + //The time code is restricted to MAX_INT hours, 60 minutes, 60 seconds and 1000 milliseconds + SmilTimeCode(char *SMILBegin, char *SMILCurrent, char *SMILEnd) : TimeCode<MASTERCOUNTERTYPE, ARRAYTYPE>(DEFAULTBUFLEN,MAX_HOURS,MAX_MINUTES,MAX_SECONDS,MAX_MILLISECONDS){ + //This constructor will fill in the time code for beginning, current time and end time + + //Set the end of time + //setFinish(convertStrToTimeCode(SMILEnd)); + this->end=convertStrToTimeCode(SMILEnd); + //Set the beginning of time + //setBeginning(convertStrToTimeCode(SMILBegin)); + this->start=convertStrToTimeCode(SMILBegin); + } +}; +#endif //SMILTIMECODE_H_ Added: branches/amis3/AmisAudio/mffmTimeCode/counter.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/counter.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/counter.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,172 @@ +/* + mffm Time Code + Time Code for multimedia systems + + Copyright (C) 2000, 2001 Matt R. Flax <fl...@ie...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You have received a copy of the GNU Lesser General Public License + along with this library. +*/ +#ifndef COUNTER_H_ +#define COUNTER_H_ + +//#include <iomanip.h> +#include <iostream> + +#ifndef MAXINT +#include "./win32fix.h" +#endif + +//#define C_DEBUG + +//#define CTYPE int +class counter { +protected: + inline void cond(void){ +#ifdef C_DEBUG + std::cout<<"counter::cond enter"<<std::endl; +#endif + if (minCount<(int)0.0) + std::cerr<<"Warning: min Count < 0 and may cause problems"<<std::endl; + if (maxCount<=minCount) + std::cerr<<"Warning: max Count <= min Count and may cause problems"<<std::endl; + if (maxCount==(int)0.0) + std::cerr<<"Warning: max Count = 0 and may cause problems"<<std::endl; + int temp=(int)0.0; + if (--temp>0){ + std::cerr<<"counter: You are using an unsigned type ... error ... exiting"<<std::endl; + exit(-1); + } +#ifdef C_DEBUG + std::cout<<"counter::cond exit"<<std::endl; +#endif + } + + inline void clean(void){ +#ifdef C_DEBUG + std::cout<<"counter::clean count = "<<count<<std::endl; +#endif + int tempCount=count-minCount, tempMaxCount=maxCount-minCount; + // std::cout<<tempCount<<'\t'<<tempMaxCount<<std::endl; + // if (count<0.0){ + // carry=count/maxCount-(int)1.0; + //count+=maxCount; + if (tempCount<0.0){ + carry=tempCount/tempMaxCount-(int)1.0; + tempCount+=tempMaxCount; + // std::cout<<carry<<'\t'<<count<<std::endl; + } + if (tempCount>=tempMaxCount){ + carry=tempCount/tempMaxCount; + tempCount%=tempMaxCount; + } + count=tempCount+minCount; + //std::cout<<"clean exit"<<std::endl; +#ifdef C_DEBUG + std::cout<<"counter::clean exit "<<count<<std::endl; +#endif + } + + int count, maxCount, minCount; + int carry; +public: + counter (){ +#ifdef C_DEBUG + std::cout<<"counter::counter()"<<std::endl; +#endif + maxCount=MAXINT; minCount=0; count=(int)0;carry=0; cond(); + + } + counter (int minc, int maxc){ +#ifdef C_DEBUG + std::cout<<"counter::counter(minc, maxc)"<<std::endl; +#endif + maxCount=maxc; minCount=minc; count=(int)0;carry=0; cond(); + } + counter (int minc, int c, int maxc){ +#ifdef C_DEBUG + std::cout<<"counter::counter(minc="<<minc<<", c="<<c<<", maxc="<<maxc<<")"<<std::endl; +#endif + // if (c<0.0) std::cout <<"counter: init vals must be >=0 ... this may cause a problem"<<std::endl; + count=c; maxCount=maxc; minCount=minc; carry=0; cond(); clean(); + } + + /// returns the current count + int getCount(void){return count;} + /// returns the maximum count + int getMaxCount(void){return maxCount;} + /// Sets the maximum count + int setMaxCount(counter mc){return setMaxCount(mc.count);} + int setMaxCount(int mc){ + if (count>mc) count=mc-1; + return maxCount=mc; + } + /// returns the minimum count + int getMinCount(void){return minCount;} + /// Sets the minimum count + int setMinCount(counter mc){return setMinCount(mc.count);} + int setMinCount(int mc){ +#ifdef C_DEBUG + std::cout<<"counter::setMinCount(mc="<<mc<<")"<<std::endl; +#endif + if (count<mc) count=mc; + return minCount=mc; + } + /// returns the carry + int getCarry(void){return carry;} + /// resets the carry to zero + void resetCarry(void){carry=0;} + + // Logic operators + char operator!=(counter& c) {return count != c.count;} + char operator!=(int& c) {return count != c;} + char operator==(counter& c) {return count == c.count;} + char operator==(int& c) {return count == c;} + char operator> (counter& c) {return count > c.count;} + char operator> (int& c) {return count > c;} + char operator>=(counter& c) {return count >= c.count;} + char operator>=(int& c) {return count >= c;} + char operator< (counter& c) {return count < c.count;} + char operator< (int& c) {return count < c;} + char operator<=(counter& c) {return count <= c.count;} + char operator<=(int& c) {return count <= c;} + + // Evaluational operators + counter& operator =(counter c){ + //std::cout<<"count::yoyo"<<std::endl; + count = c.count; clean(); return *this;} + counter& operator =(int c){ + //std::cout<<"count::yo "<<count<<std::endl; + count = c;clean(); return *this;} + counter& operator+=(counter c){count += c.count; clean(); return *this;} + counter& operator+=(int c){count += c; clean(); return *this;} + counter& operator-=(counter c){count -= c.count; clean(); return *this;} + counter& operator-=(int c){count -= c; clean(); return *this;} + counter& operator*=(counter c){count *= c.count; clean(); return *this;} + counter& operator*=(int c){count *= c; clean(); return *this;} + counter& operator/=(counter c){count /= c.count; clean(); return *this;} + counter& operator/=(int c){count /= c; clean(); return *this;} + + int operator+(counter& c){return count+c.count;} + int operator+(int c){return count+c;} + int operator-(counter& c){return count-c.count;} + int operator-(int c){return count-c;} + double operator*(counter& c){return (double)count*(double)c.count;} + double operator*(int c){return (double)count*(double)c;} + double operator/(counter& c){return (double)count/(double)c.count;} + double operator/(int c){return (double)count/(double)c;} + + friend std::ostream& operator <<(std::ostream& o, counter c) {o << c.count<<"\tcarry="<<c.carry<<"\tMinCount="<<c.minCount<<"\tMaxCount="<<c.maxCount; return o;} +}; +#endif //COUNTER_H_ + Added: branches/amis3/AmisAudio/mffmTimeCode/field.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/field.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/field.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,108 @@ +/* + mffm Time Code + Time Code for multimedia systems + + Copyright (C) 2000, 2001 Matt R. Flax <fl...@ie...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You have received a copy of the GNU Lesser General Public License + along with this library. +*/ +#ifndef FIELD_H_ +#define FIELD_H_ + +#include <math.h> + +#include "counter.H" + +//template <class FTYPE> +//#define FTYPE int +class field : public counter { + unsigned int digitCount; + + /// Sets the digit count and display array + void countDigits(void){ + // Work out the required digit count ... + double mVal=maxCount; + digitCount=0; + while (mVal>pow(10.0,(int) ++digitCount)-1.0); + // Set up the digit array ... + digits=NULL; + if (!(digits=new unsigned char[digitCount])){ + std::cerr <<"field: digit malloc error"<<std::endl; + exit(-1); + } + } + + /// Sets the digits array to the digit value of the counter + void syncDigits(void){ + //std::cout<<"syncdigits :: "<<std::endl; + if (count==maxCount) count=0; + int cnt = count; + register double temp; + for (int i=digitCount-1;i>=0;i--){ + temp=pow(10.0, i); + digits[i]=(char)((double)cnt/temp); + //std::cout<<(int)digits[i]<<std::endl; + cnt-=digits[i]*(int)temp; + } + } + +public: + unsigned char *digits; + + field(int minimumVal, int startVal, int maximumVal) : counter(minimumVal, startVal, maximumVal){ +//#if DEBUG > 1 +// std::cout<<"field::field(minimumVal, startVal, maximumVal)"<<std::endl; +//#endif + digits=NULL; + // Set up the digit array and count + countDigits(); + // Sync the digits with the counter value + syncDigits(); + } + + ~field(void){ +//#if DEBUG > 1 +// std::cout<<"field::~field"<<std::endl; +//#endif + // std::cout<<"~field: in"<<std::endl; + if (digits) delete [] digits; + // std::cout<<"~field: out"<<std::endl; + } + + // The following alter the counter and must be overloaded + field& operator =(const counter& f){counter::operator =(f); syncDigits(); return *this;} + field& operator =(const int f){ + // std::cout<<"equate"<<std::endl; +counter::operator =(f); +//std::cout<<"about to sync"<<std::endl; + syncDigits(); return *this;} + field& operator+=(const counter& f){counter::operator+=(f); syncDigits(); return *this;} + field& operator+=(const int& f){counter::operator+=(f); syncDigits(); return *this;} + field& operator-=(const counter& f){counter::operator-=(f); syncDigits(); return *this;} + field& operator-=(const int& f){counter::operator-=(f); syncDigits(); return *this;} + field& operator*=(const counter& f){counter::operator*=(f); syncDigits(); return *this;} + field& operator*=(const int& f){counter::operator*=(f); syncDigits(); return *this;} + field& operator/=(const counter& f){counter::operator/=(f); syncDigits(); return *this;} + field& operator/=(const int& f){counter::operator/=(f); syncDigits(); return *this;} + + friend std::ostream& operator <<(std::ostream& o, field& f) { + std::cout<<(counter)f<<":\t"; + for (int i=f.digitCount-1; i>=0; i--) + o << (long)f.digits[i]; + return o; + } + + int digitCnt(void){return digitCount;} +}; +#endif //FIELD_H_ Added: branches/amis3/AmisAudio/mffmTimeCode/masterCounter.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/masterCounter.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/masterCounter.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,194 @@ +/* + mffm Time Code + Time Code for multimedia systems + + Copyright (C) 2000, 2001 Matt R. Flax <fl...@ie...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You have received a copy of the GNU Lesser General Public License + along with this library. +*/ +#ifndef MASTERCOUNTER_H_ +#define MASTERCOUNTER_H_ + +#include <stdarg.h> +#include "field.H" + +//#define DEBUG_MC + +template <class FIELDTYPE, int FIELDCOUNT> +class MasterCounter : public counter { +protected: + FIELDTYPE **fields; +public: + int fieldCount(void){return FIELDCOUNT;} + + MasterCounter(int startVal, ...) : counter(0, startVal, 1){ +#ifdef DEBUG_MC + std::cout<<"MasterCounter::MasterCounter(startVal, ...)"<<std::endl; +#endif + int maxC=1; + + if (FIELDCOUNT){ + if (!(fields=new FIELDTYPE*[FIELDCOUNT])){ + std::cerr<<"MasterCounter: Out of memory error"<<std::endl; + exit(-1); + } + for (int i=0;i<FIELDCOUNT;i++) + fields[i]=NULL; + + va_list ap; + va_start(ap, startVal); + for (i=0;i<FIELDCOUNT;i++){ + int temp=va_arg(ap, int); + if (i==0) + maxC*=temp; + maxC*=temp; + if (!(fields[i]=new FIELDTYPE(0, 0,temp))){ + std::cerr<<"MasterCounter: Out of memory error 1"<<std::endl; + exit(-1); + } + } + va_end(ap); + setMaxCount(maxC); + updateFields(); + } +#ifdef DEBUG_MC + std::cout<<"MasterCounter::MasterCounter(startVal, ...) EXIT"<<std::endl; +#endif + } + + MasterCounter(void) : counter(0, 0, 1){ +#ifdef DEBUG_MC + std::cout<<"MasterCounter::MasterCounter()"<<std::endl; +#endif + if (FIELDCOUNT){ + fields=new FIELDTYPE*[FIELDCOUNT]; + if (!fields){ + std::cerr<<"MasterCounter: Out of memory error"<<std::endl; + exit(-1); + } + for (int i=0;i<FIELDCOUNT;i++) + fields[i]=NULL; + } + } + + void init(int c, ...){ +#ifdef DEBUG_MC + std::cout<<"MasterCount: init "<<c<<" ..."<<std::endl; +#endif + va_list ap; + va_start(ap, c); + init(c, ap); + va_end(ap); + } + + void init(int c, va_list& ap){ +#ifdef DEBUG_MC + std::cout<<"MasterCount: init "<<c<<std::endl; +#endif + count=c; + int maxC=1; + for (int i=0;i<FIELDCOUNT;i++){ + int temp=va_arg(ap, int); + maxC*=temp; + //std::cout<<i<<" after "<<temp<<'\t'<<maxC<<std::endl; + fields[i]=new FIELDTYPE(0,0,temp); + if (!fields[i]){ + std::cerr<<"MasterCounter: Out of memory error 1"<<std::endl; + exit(-1); + } + // std::cout<<FIELDCOUNT<< " looping"<<std::endl; + } + setMaxCount(maxC); + updateFields(); + } + + ~MasterCounter(void){ +#ifdef DEBUG_MC + std::cout<<"MasterCounter::~MasterCounter"<<std::endl; +#endif + if (fields) { + for (int i=0;i<FIELDCOUNT;i++){ + if (fields[i]) delete fields[i]; + fields[i]=NULL; + } + delete [] fields; + fields=NULL; + } + // std::cout<<"~MasterCounter: out"<<std::endl; + } + + /// Sets the minimum count + int setMinCount(counter mc){return setMinCount(mc.getCount());} + int setMinCount(int mc){ +#ifdef DEBUG_MC + std::cout<<"MasterCounter::setMinCount(mc="<<mc<<")"<<std::endl; +#endif + int temp=counter::setMinCount(mc); + updateFields(); + return temp; + } + + /// Sets the minimum count + int setMaxCount(counter mc){return setMaxCount(mc.getCount());} + int setMaxCount(int mc){ +#ifdef DEBUG_MC + std::cout<<"MasterCounter::setMaxCount(mc="<<mc<<")"<<std::endl; +#endif + int temp=counter::setMaxCount(mc); + updateFields(); + return temp; + } + + // syncs the field with the new counter value + void updateFields(void){ + //std::cout<<"masterCounter: updateFields"<<std::endl; + int temp=count, tempCarry; + for (int i=0;i<FIELDCOUNT;i++){ + //std::cout<<i<<std::endl; + int which =FIELDCOUNT-i-1; + tempCarry=temp%fields[which]->getMaxCount(); + temp=temp/fields[which]->getMaxCount(); + *fields[which]=(int)tempCarry; + } + //std::cout<<"masterCounter: updateFields EXIT"<<std::endl; + } + + // Logic operators + /* char operator==(counter& m) {return count == m.getCount();} + char operator!=(counter& m) {return count != m.getCount();} + char operator> (counter& m) {return count > m.getCount();} + char operator>=(counter& m) {return count >= m.getCount();} + char operator< (counter& m) {return count < m.getCount();} + char operator<=(counter& m) {return count <= m.getCount();} + */ + + // Evaluational operators + MasterCounter& operator =(counter c){counter::operator=(c); updateFields();return *this;} + MasterCounter& operator =(int c){counter::operator=(c);updateFields();return *this;} + MasterCounter& operator+=(counter c){counter::operator+=(c); updateFields();return *this;} + MasterCounter& operator+=(int c){counter::operator+=(c);updateFields();return *this;} + MasterCounter& operator-=(counter c){counter::operator-=(c); updateFields();return *this;} + MasterCounter& operator-=(int c){counter::operator-=(c); updateFields();return *this;} + MasterCounter& operator*=(counter c){counter::operator*=(c); updateFields();return *this;} + MasterCounter& operator*=(int c){counter::operator*=(c); updateFields();return *this;} + MasterCounter& operator/=(counter c){counter::operator/=(c); updateFields();return *this;} + MasterCounter& operator/=(int c){counter::operator/=(c); updateFields();return *this;} + + friend std::ostream& operator <<(std::ostream& o, MasterCounter<FIELDTYPE, FIELDCOUNT>& c) { + o << c.count<<"\tMinCount="<<c.minCount<<"\tcarry="<<c.carry<<"\tMaxCount="<<c.maxCount<<'\t'; + return o; + } +}; +#endif //MASTERCOUNTER_H_ + Added: branches/amis3/AmisAudio/mffmTimeCode/masterCounterArray.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/masterCounterArray.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/masterCounterArray.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,163 @@ +/* + mffm Time Code + Time Code for multimedia systems + + Copyright (C) 2000, 2001 Matt R. Flax <fl...@ie...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You have received a copy of the GNU Lesser General Public License + along with this library. +*/ +#ifndef MASTERCOUNTERARRAY_H_ +#define MASTERCOUNTERARRAY_H_ + +#include <stdarg.h> +//#include <sys/resource.h> +#include "field.H" + +//#define MCA_DEBUG + +template <class MASTERCOUNTERTYPE, class ARRAYTYPE> +class MasterCounterArray : public MASTERCOUNTERTYPE { + + /// The size in bytes of a single sample (multichannel size). i.e. 16 bit stereo => 4 bytes + int frameSize; + // double countToFrames, framesToCount; + +protected: + ARRAYTYPE *array; +public: + // double getFramesToCount(){return framesToCount;} + //double getCountToFrames(){return countToFrames;} + + int getFrameSize(){return frameSize;} + int setFrameSize(int fsz){ +#ifdef MCA_DEBUG + std::cout<<"MasterCounterArray::setFrameSize"<<std::endl; +#endif + //// Find the conversion from frames to count + // framesToCount=(double)frameCount/(double)rate; + //countToFrames=(double)rate/(double)frameCount; + + if (frameSize!=fsz){ + frameSize=fsz; + updateArray(); + } + return frameSize; + } + + /** Constructor, specifying a startValue for the array index and a + list of time code fields. + */ + MasterCounterArray(int startVal, ...) : MASTERCOUNTERTYPE(){ +#ifdef MCA_DEBUG + + std::cout<<"MasterCounterArray::MasterCounterArray(startVal="<<startVal<<", ...)"<<std::endl; +#endif + array=NULL; + frameSize=1; + va_list ap; + va_start(ap, startVal); + init(startVal, ap); + va_end(ap); + } + + /** Empty constructor, must use init to complete valid construction + */ + MasterCounterArray(void) : MASTERCOUNTERTYPE(){ +#ifdef MCA_DEBUG + std::cout<<"MasterCounterArray::MasterCounterArray()"<<std::endl; +#endif + array=NULL; + frameSize=1; + } + + /** Initialiser for the empty constructor + */ + void init(int c, ...){ +#ifdef MCA_DEBUG + std::cout<<"MasterCounterArray::init(startVal="<<c<<", ...)"<<std::endl; +#endif + va_list ap; + va_start(ap, c); + init(c, ap); + va_end(ap); + } + + /** second stage init, called by 'other' init function + */ + void init(int c, va_list& ap){ +#ifdef MCA_DEBUG + std::cout<<"MasterCounterArray::init(startVal="<<c<<", va_list)"<<std::endl; +#endif + //cout<<"c "<<c<<endl; + MASTERCOUNTERTYPE::init(c,ap); + //std::cout<<*this<<std::endl; + updateArray(); + } + + /** Deconstructor */ + ~MasterCounterArray(void){ +#ifdef MCA_DEBUG + std::cout<<"MasterCounterArray::~MasterCounterArray"<<std::endl; +#endif + if (array) delete [] array; + array=NULL; + // std::cout<<"MasterCounterArray::~MasterCounterArray exit"<<std::endl; + } + + void updateArray(){ +#ifdef MCA_DEBUG + std::cout<<"MasterCounterArray::updateArray - new size "<<getCount()*frameSize<<std::endl; +#endif + //std::cout<<"count "<<getCount()<<std::endl; + //std::cout<<"frameSize "<<frameSize<<std::endl; + if (array) delete [] array; + array=NULL; + // std::cout<<getCount()<<std::endl; + //Should limit the possible allocatable space here ... + /* struct rlimit limit; + getrlimit(RLIMIT_MEMLOCK , &limit); + std::cout<<"rlim_cur "<<limit.rlim_cur<<std::endl; + std::cout<<"rlim_max "<<limit.rlim_max<<std::endl; + */ + //cout<<"making array of size "<<this->getCount()*frameSize<<endl; + if (!(array=new ARRAYTYPE[this->getCount()*frameSize])){ + std::cout<<"MasterCounterArray: Out of memory"<<std::endl; + exit(-1); + } + //std::cout<<"MasterCounterArray::updateArray : array="<<array<<std::endl; + } + + void zeroArray(void){ + //Check whether this needs frameSize multiplier. + bzero(array, this->getCount()*sizeof(ARRAYTYPE)); + } + + // Evaluational operators + MasterCounterArray& operator =(counter c){counter::operator=(c); updateArray();return *this;} + MasterCounterArray& operator =(int c){counter::operator=(c);updateArray();return *this;} + MasterCounterArray& operator+=(counter c){counter::operator+=(c); updateArray();return *this;} + MasterCounterArray& operator+=(int c){counter::operator+=(c); updateArray();return *this;} + MasterCounterArray& operator-=(counter c){counter::operator-=(c); updateArray();return *this;} + MasterCounterArray& operator-=(int c){counter::operator-=(c); updateArray();return *this;} + MasterCounterArray& operator*=(counter c){counter::operator*=(c); updateArray();return *this;} + MasterCounterArray& operator*=(int c){counter::operator*=(c); updateArray();return *this;} + MasterCounterArray& operator/=(counter c){counter::operator/=(c); updateArray();return *this;} + MasterCounterArray& operator/=(int c){counter::operator/=(c); updateArray();return *this;} + + // ARRAYTYPE& operator[](int i){return array[i];} + ARRAYTYPE* getDataPtr(void){return array;} + ARRAYTYPE& operator[](int i){return array[i];} + // ARRAYTYPE& operator[]=(int i, ARRAYTYPE val){return array[i]=val;} +}; +#endif //MASTERCOUNTERARRAY_H_ Added: branches/amis3/AmisAudio/mffmTimeCode/timeCode.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/timeCode.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/timeCode.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,220 @@ +/* + mffm Time Code + Time Code for multimedia systems + + Copyright (C) 2000, 2001 Matt R. Flax <fl...@ie...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You have received a copy of the GNU Lesser General Public License + along with this library. +*/ +#ifndef TIMECODE_H_ +#define TIMECODE_H_ + +#include <stdarg.h> +#include "masterCounter.H" +#include "masterCounterArray.H" + +/** Time Code, inherits the current code + */ +template <class MASTERCOUNTERTYPE, class ARRAYTYPE> +class TimeCode : public MASTERCOUNTERTYPE { + int beginning, finish; +protected: + MASTERCOUNTERTYPE start, end; +public: + // The window count + MasterCounterArray<MASTERCOUNTERTYPE, ARRAYTYPE> *window; + //void zeroArray(void) {window->zeroArray();} + //ARRAYTYPE* getDataPtr(void){return window->getDataPtr();} + // ARRAYTYPE& operator[](int i){return window[i];} + + TimeCode(int startVal, ...) : MASTERCOUNTERTYPE (){ +//#if DEBUG > 1 +// std::cout<<"TimeCode::TimeCode(startVal, ...)"<<std::endl; +//#endif + window=NULL; + va_list ap, ap1, ap2, ap3; + va_start(ap, startVal); + va_start(ap1, startVal); + va_start(ap2, startVal); + va_start(ap3, startVal); + init(startVal, ap, ap1, ap2, ap3); + va_end(ap); + va_end(ap1); + va_end(ap2); + va_end(ap3); + } + + TimeCode(void) : MASTERCOUNTERTYPE (){ +//#if DEBUG > 1 +// std::cout<<"TimeCode::TimeCode()"<<std::endl; +//#endif + window=NULL; + } + + void init(int startVal, ...) { + va_list ap, ap1, ap2, ap3; + va_start(ap, startVal); + va_start(ap1, startVal); + va_start(ap2, startVal); + va_start(ap3, startVal); + init(startVal, ap, ap1, ap2, ap3); + va_end(ap); + va_end(ap1); + va_end(ap2); + va_end(ap3); + } + + void init(int c, va_list& ap, va_list& apStart, va_list& apEnd, va_list& apWindow){ +//#if DEBUG > 1 +// std::cout<<"TimeCode::init"<<std::endl; +//#endif + beginning=0; + start.init(beginning, apStart); + + MASTERCOUNTERTYPE::init(c, ap); + finish=this->getMaxCount(); + + // Ensure end points to the last window + end.init(finish-1, apEnd); + + if (window) delete window; + if (!(window=new MasterCounterArray<MASTERCOUNTERTYPE, ARRAYTYPE>)) std::cerr <<"TimeCode::init : window malloc error"<<std::endl; + window->init(this->fields[this->fieldCount()-1]->getMaxCount(), apWindow); + } + + ~TimeCode(void){ +//#if DEBUG > 1 +// std::cout<<"TimeCode::~TimeCode"<<std::endl; +//#endif + if (window) delete window; + } + + int getBeginning(void){return beginning;} + void setBeginning(counter c){setBeginning(c.getCount());} + void setBeginning(int c){ + if (c>=finish) + c=finish-1; + beginning=c; + setStart(beginning); + } + + void nothing(){} + + int getStart(){return start.getCount();}; + void setStart(counter c){setStart(c.getCount());} + void setStart(int c){ +//#if DEBUG > 1 +// std::cout<<"TimeCode::setStart "<<c<<std::endl; +//#endif + //Check that the beginning is not underrun + // the end minimum is not before the start + // the end minimum matches the start point + if (c<beginning) c=beginning; + if (c>end.getCount()) c=end.getCount(); + // if (c<end->getMinCount()) end->setMinCount(c); + end.setMinCount(c); + nothing(); + start.MASTERCOUNTERTYPE::operator=(c);// set the start point + //start=c;// set the start point + // std::cout<<start<<std::endl; + setMinCount(start); // reset the minimum of the current time + } + + int getEnd(){return end.getCount();}; + void setEnd(counter c){setEnd(c.getCount());} + void setEnd(int c){ +//#if DEBUG > 1 +// std::cout<<"TimeCode::setEnd "<<c<<std::endl; +//#endif + + //Check that the finish is not overrun + // the start maximum is not after the end + // the start maximum matches the end point + if (c>finish) c=finish; + if (c<start.getCount()) c=start.getCount(); + + start.setMaxCount(c); + // set the end point + end.MASTERCOUNTERTYPE::operator=(c); + setMaxCount(end); // reset the maximum of the current time + } + + int getFinish(void){return finish;} + void setFinish(counter c){setEnd(c.getCount());} + void setFinish(int c){ + finish=c; + end.setMaxCount(c); + window->setMaxCount(c); + } + + /** this function will apply a type II filter using the masterArray as the + output. + Filter coefficients are specified by the arrays a and b, with their + coefficient counts represented by aCnt and bCnt. + The input is pointed to by 'input'. The current location must be pointed + to and there must be at least 'aCnt' elements in the array preceeding + the pointer. + This function will only process one output at a time. + Coefficient notes : + a[0]=1.0; + input : + input The current value of the input signal + aCnt the number of denomiator coefficients + a the denominator (pole polynomial) coefficients + bCnt the number of numerator coefficients + b the numerator (zero polynomial) coefficients + memory the filter memory of dimension max(aCnt,bCnt) + */ + inline void filter(ARRAYTYPE input, const int aCnt, const double *a, const int bCnt, const double *b, double *memory){ + int j, loc=this->getCount(); + + //cout<<a<<'\t'<<b<<'\t'<<memory<<'\n'; + //cout<<aCnt<<'\t'<<bCnt<<'\n'; + + // Firstly calculate the output + (*window)[loc]=input*b[0]+memory[0]; + //cout<<(*window)[loc]<<'\t'<<input<<'\t'<<b[0]<<'\t'<<memory[0]<<'\n'; + // Manipulate the filter memory + for (j=1;j<aCnt & j<bCnt; j++){ + memory[j-1]=memory[j]+input*b[j]-(*window)[loc]*a[j]; + //cout<<memory[j-1]<<'\t'<<memory[j]<<'\t'<<input<<'\t'<<b[j]<<'\t'<<(*window)[loc]<<'\t'<<a[j]<<'\n'; + } + + //if (bCnt>aCnt) + for (j;j<bCnt;j++){ + memory[j-1]=memory[j]+input*b[j]; + //cout<<"take 2 b: "<<memory[j-1]<<'\t'<<memory[j]<<'\t'<<input<<'\t'<<b[j]<<'\n'; + } + //else + for (j;j<aCnt;j++){ + memory[j-1]=memory[j]-(*window)[loc]*a[j]; + //cout<<"take 2 a "<<memory[j-1]<<'\t'<<memory[j]<<'\t'<<(*window)[loc]<<'\t'<<a[j]<<'\n'; + } + //cout<<'\n'; + } + + TimeCode& operator =(TimeCode& c){counter::operator=(c);return *this;} + TimeCode& operator =(counter c){counter::operator=(c);return *this;} + TimeCode& operator =(int c){counter::operator=(c);return *this;} + + friend std::ostream& operator <<(std::ostream& o, TimeCode& tc) { + o<<"TimeCode: Beginning: "<<tc.beginning<<" Finish: "<<tc.finish<<'\n'; + o<<"Start: "<<tc.start<<'\n'; + o<<"Current: "<<(MASTERCOUNTERTYPE&)tc<<'\n'; + o<<"End: "<<tc.end<<'\n'; + o<<"Window Count: "<<*tc.window<<'\n'; + return o; + } +}; +#endif //TIMECODE_H_ Added: branches/amis3/AmisAudio/mffmTimeCode/win32fix.H =================================================================== --- branches/amis3/AmisAudio/mffmTimeCode/win32fix.H (rev 0) +++ branches/amis3/AmisAudio/mffmTimeCode/win32fix.H 2007-10-18 15:08:14 UTC (rev 2206) @@ -0,0 +1,74 @@ +/* Copyright 2001 Matt Flax <fl...@ie...> + This file is part of MFFM Time Scale Modification for Audio. + + MFFM Time Scale Modification for Audio 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. + + MFFM Time Scale Modification for Audio 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 have received a copy of the GNU General Public License + along with MFFM Time Scale Modification for Audio + */ +#ifndef WIN32FIX_H_ +#define WIN32FIX_H_ + +// DLLs in Windows should use the standard calling convention +#ifndef ADR_CALL + #if defined(WIN32) || defined(_WIN32) + #define ADR_CALL __stdcall + #else + #define ADR_CALL + #endif +#endif + +// Export functions from the DLL +#ifndef ADR_DECL +# if defined(WIN32) || defined(_WIN32) +# ifdef LIBFFT_EXPORTS +# define ADR_DECL __declspec(dllexport) +# else +# define ADR_DECL __declspec(dllimport) +# endif +# else +# define ADR_DECL +# endif +#endif + +#define ADR_FUNCTION(ret) extern "C" ADR_DECL ret ADR_CALL + +#ifndef round +#define round(a) roundD(a) +#endif + +#ifndef bzero +#define bzero(a,c) memset(a,0,c) +#endif + +#ifndef remainder +#define remainder(a,b) fmod(a,b) +#endif + +#ifndef MAXDOUBLE +//#include <limits> +//#define MAXDOUBLE (numeric_limits<double>::max()) +//#define MAXDOUBLE DBL_MAX +#define MAXDOUBLE 1e308 +#endif + +#ifndef MAXINT +//#include <limits> +//#define MAXINT (numeric_limits<int>::max()) +#define MAXINT INT_MAX +#endif + +#ifndef cerr +#include <iostream> +using namespace std; +//#define cerr std:cout +#endif +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |