示例#1
0
static int getOggInt(char *buff, int beg, int bytes){
//if (DEBUG==1) putlog("getOggInt");
	int ret=0;
	int i;
	for (i=0;i<bytes;i++){
		if (buff[i+beg]>=0) ret+=buff[i+beg]*iPow(256,i);else ret+=(256+buff[i+beg])*iPow(256,i);
		//printf("[%i]=%i\n",i,buff[i+beg]);
	}
	return ret;
}
示例#2
0
struct tagInfo readID3V2(char *file){
//if (DEBUG==1) putlog("reading id3v2");
	FILE *f;
	int i, c, len;
	char header[10];
	char *tag;
	struct tagInfo ret;

	f = fopen(file,"rb");
	//hexchat_printf(ph,"file :%s",file);
	if (f==NULL)
	{
       hexchat_print(ph,"file not found whilt trying to read ID3V2");
       //if (DEBUG==1)putlog("file not found while trying to read ID3V2");
       return ret;
    }

	ret.artist=NULL;
	for (i=0;i<10;i++){
        c=fgetc(f);
        if (c==EOF){
            fclose(f);
           //putlog("found eof while reading id3v2");
           return ret;
        }
        header[i]=(char)c;
    }
	if (strstr(header,"ID3")==header){
		//hexchat_printf(ph,"found id3v2\n");
		len=0;
		for (i=6;i<10;i++) len+=(int)header[i]*iPow(256,9-i);
		
		//char *tag=(char*)malloc(sizeof(char)*len);
		tag=(char*) calloc(len,sizeof(char)); //malloc(sizeof(char)*len);
		for (i=0;i<len;i++){c=fgetc(f);tag[i]=(char)c;}
//hexchat_printf(ph,"tag length: %i\n",len);
//hexchat_printf(ph,"tag: %s\n",tag);
		fclose(f);
		ret.comment=tagExtract(tag,len,"COMM");
//hexchat_printf(ph,"Comment: %s\n",ret.comment);
		ret.genre=tagExtract(tag,len,"TCON");
		//if (strcmp(ret.genre,"(127)")==0) ret.genre="unknown";
//hexchat_printf(ph, "ret.genre = %s",ret.genre);
		if ((ret.genre!=NULL)&&(ret.genre[0]=='(')) ret.genre=extractID3Genre(ret.genre);
//hexchat_printf(ph,"genre: %s\n",ret.genre);
		ret.title=tagExtract(tag,len,"TIT2");
//hexchat_printf(ph,"Title: %s\n",ret.title);
		ret.album=tagExtract(tag,len,"TALB");
//hexchat_printf(ph,"Album: %s\n",ret.album);
		ret.artist=tagExtract(tag,len,"TPE1");
//hexchat_printf(ph,"Artist: %s\n",ret.artist);
	}
	else{fclose(f);printf("no id3v2 tag found\n"); return ret;}
	//printf("id2v2 done\n");
	//if (DEBUG==1) putlog("id3v2 readed");
	return ret;
}
示例#3
0
std::vector<Int> ABS(std::vector<Int> U, Int t, nInt log) {
    std::vector<Int> S(U);
    std::sort(U.begin(), U.end());
    t = iMin(t, Sigma(U) - t);
    if (!t) return U;
    if (std::binary_search(U.begin(), U.end(), t)) return std::vector<Int>({t});
    for (nInt k = 0; k < U.size(); k++) {
        if (U.at(k) > t) {
            U.erase(U.begin() + k, U.end());
        }
    }
    if (U.size() == 1) return U;
    Int L = iMin(iPow(U.size(), 4), iPow(2, U.size() - 1));
    Int i, j, s, d, n, e = 0;
    Int k = 0;
    Int l = iPow(2, U.size() - 1);
    while (k < L) {
        i = k;
        j = l;
        e = (i + j) / 2;
        while (i < j) {
            cycles++;
            n = (i + j) / 2;
            S = Phi(U, n + e);
            s = Sigma(S);
            d = s - t;
            if (log) {
                std::cout << "(<" << Sigma(S) << ", " << Sigma(U) - Sigma(S) << ">, [ ";
                for (auto u : S) std::cout << u << " ";
                std::cout << "])" << std::endl;
            }
            if (d == 0) return S;
            if (d < 0) i = n + 1;
            if (d > 0) j = n;
            e++;
        }
        k++;
        l++;
    }

    return std::vector<Int>();
}
示例#4
0
double bisect_nRoot(double N, double T, unsigned int n)
{
	assert(N >= 0);
	assert(T >= 0);
	//Ensures that none of the trivial cases are requested
	assert(n >= 2);

	//Runs the more optimal bisect_sqrt if n == 2
	if(n == 2)
		return bisect_sqrt(N, T);

	double a, b, x, f;
	
	//Sets the initial values of a and b
	a = 0;
	//This statement is equivalent to
	//  if(N<1) b=1; else b=N;
	b = N < 1 ? 1 : N;

	x = 0.5*(a + b);
	f = iPow(x, n) - N;
	
	//fabs(f) > T is our approximation of 
	//  f != 0, by using the given tolerance
	while(fabs(f) > T && b - a > T)
	{
		//Update of the bounds a and b
		if (f < 0)
			a = x;
		else
			b = x;
		
		//Update of x and f
		x = 0.5*(a + b);
		f = iPow(x, n) - N;
	}
	
	return x;
}
示例#5
0
std::vector<Int> ABS(std::vector<Int> U, Int t, nInt log) {
    Int z = iPow(t, U.size() / 2);
    std::vector<Int> S(U);
    std::sort(U.begin(), U.end());
    Int L = iMin(iPow(U.size(), 4), iPow(2, U.size() - 1));
    Int i, j, s, d, n, e = 0;
    Int k = 0;
    Int l = iPow(2, U.size() - 1);
    while (k < L) {
        i = k;
        j = l;
        e = (i + j) / 2;
        while (i < j) {
            cycles++;
            n = (i + j) / 2;
            S = Phi(U, n + e);
            s = iPow(Sigma(S), S.size());
            d = s - z;
            if (log) {
                std::vector<Int> C;
                std::set_difference(U.begin(), U.end(), S.begin(), S.end(), std::back_inserter(C));
                std::cout << "(<" << Sigma(S) << ", " << Sigma(U) - Sigma(S) << ">, [ ";
                for (auto u : S) std::cout << u << " ";
                std::cout << "]  [";
                for (auto u : C) std::cout << u << " ";
                std::cout << "])" << std::endl;
            }
            if (d == 0) return S;
            if (d < 0) i = n + 1;
            if (d > 0) j = n;
            e++;
        }
        k++;
        l++;
    }

    return std::vector<Int>();
}
示例#6
0
文件: mp3Info.c 项目: fuzzmz/hexchat
int str2int(char *text){
    //if (DEBUG==1) putlog("converting string to int");
    int i;
    int ret=0;
    for (i=1;i<=strlen(text);i++){
        if ((text[strlen(text)-i]>57)||(text[strlen(text)-i]<48)){
           hexchat_printf(ph,"invalid char in string: %i",text[strlen(text)-i]);
           return 255;
        }
        ret+=((int)text[strlen(text)-i]-48)*iPow(10,i-1);
    }
    //hexchat_printf(ph, "str2int(%s)=%i",text,ret);
    //if (DEBUG==1) putlog("int converted");
    return ret;
}
示例#7
0
文件: mp3Info.c 项目: fuzzmz/hexchat
static char *tagExtract(char *tag, int tagLen, char* info){
//if (DEBUG==1) putlog("extracting tag");
	int pos, len, i;
	pos=inStr(tag,tagLen,info);
//hexchat_printf(ph,"pos=%i",pos);
	if (pos==-1) return "";//NULL;
	//printf("position of %s = %i\n",info,pos);
	len=0;
	//for (i=pos;i<pos+10;i++)printf("tag[%i]=%i \n",i,tag[i]);
	for (i=0;i<4;i++) {
		len+=tag[pos+strlen(info)+i]*iPow(255,3-i);
	}
	//printf("Tag-Length: %i\n",len);
	if (strcmp("COMM",info)!=0) return substring(tag,pos+7+strlen(info),len-1);//11
	return substring(tag,pos+7+strlen(info),len-1);//11
	//char *ct=substring(tag,pos+7+strlen(info),len-1);//11
	//return substring(ct,strlen(ct)+1,len-1-strlen(ct)); //<-- do not understand, what i did here :(
	
}
void checkbasis( BasisFamily &b1 , BasisFamily &b2 )
{
  int maxDim=3;
  double tol = 1.0e-13;
  int maxDiffOrder = 0;
  int numErrors = 0;
  QuadratureFamily quad = new GaussianQuadrature(4);
  
  for (int spatialDim=1; spatialDim<=maxDim; spatialDim++) {
    std::cerr << "\t" << "spatial dimension =" << spatialDim << std::endl;
    for (int cellDim=0; cellDim<=spatialDim; cellDim++) { 
      std::cerr << "\t\t" << "cell dimension =" << cellDim << std::endl;
      CellType cellType;
      if (cellDim==0) cellType=PointCell;
      if (cellDim==1) cellType=LineCell;
      if (cellDim==2) cellType=TriangleCell;
      if (cellDim==3) cellType=TetCell;
      
      Array<Point> qPts;
      Array<double> qWts;
      quad.getPoints(cellType, qPts, qWts);
      
      for (int d=0; d<=maxDiffOrder; d++) {
	if (cellDim==0 && d>0) continue;
	cerr << "\t\t\t" << "differentiation order = " << d << std::endl;
	for (int dir=0; dir<iPow(cellDim, d); dir++) {
	  std::cerr << "\t\t\t\t" << "direction = " << dir << std::endl;
	  MultiIndex mi;
	  mi[dir]=d;
	  Array<Array<double> > values1;
	  Array<Array<double> > values2;
	  std::cerr << "\t\t\t\t" << "computing basis1...";
	  b1.ptr()->refEval(spatialDim, cellType, qPts, mi, values1);
	  std::cerr << "done" << std::endl << "\t\t\t\t" << "computing basis2...";
	  b2.ptr()->refEval(spatialDim, cellType, qPts, mi, values2);
	  std::cerr << "done" << std::endl;
	  int nNodes1 = b1.ptr()->nNodes(spatialDim, cellType);
	  int nNodes2 = b2.ptr()->nNodes(spatialDim, cellType);
	  std::cerr << "\t\t\t\t" << "num nodes: basis1=" << nNodes1
	       << " basis2=" << nNodes2 << std::endl;
	  if (nNodes1 != nNodes2) {	
	    std::cerr << "******** ERROR: node counts should be equal" << std::endl;
	    numErrors++;
	    continue;
	  }
	  if (values1.size() != values2.size()) {
	    std::cerr << "******** ERROR: value array outer sizes should be equal" << std::endl;
	    numErrors++;
	    continue;
	  }
	  if (values1.size() != qPts.size()) {
	    std::cerr << "******** ERROR: value array outer size should be equal to number of quad points" << std::endl;
	    numErrors++;
	    continue;
	  }
	  for (int q=0; q<qPts.length(); q++) {
	    if (values1[q].length() != nNodes1) {
	      std::cerr << "******** ERROR: value array inner size should be equal to number of nodes" << std::endl;
	      numErrors++;
	      continue;
	    }
	    std::cerr << "\t\t\t\t\t" << "quad point q=" << q << " pt=" << qPts[q]
		 << std::endl;
	    for (int n=0; n<nNodes1; n++) {
	      std::cerr << "\t\t\t\t\t\t" << "node n=" << n << " phi1="
		   << values1[q][n]
		   << " phi2=" << values2[q][n]
		   << " |phi1-phi2|=" << fabs(values1[q][n]-values2[q][n])
		   << std::endl;
	      if (fabs(values1[q][n]-values2[q][n]) > tol) {
		cout << "ERROR" << std::endl; numErrors++;
	      }
	    }
	  }
	}
      }
    }
  }    
  std::cerr << std::endl << std::endl << "Summary: detected " << numErrors << " errors " << std::endl;
}