예제 #1
0
void Queue::print(void(*toString) (ssi_size_t size, ssi_char_t *str, void *x), FILE *fp) {

	if (empty()) {

		ssi_fprint(fp, "[]\n");

	} else {

		Lock lock (_mutex);

		ssi_fprint(fp, "[");

		int i;

		i = _first;
		ssi_char_t string[SSI_MAX_CHAR];
		while (i != _last) {
			toString (SSI_MAX_CHAR, string, _q[i]);
			ssi_fprint(fp, "%s ", string);
			i = (i+1) % _n;
		}
		toString (SSI_MAX_CHAR, string, _q[i]);
		ssi_fprint(fp, "%s ]\n", string);
	}
}
예제 #2
0
void ElanTier::print (FILE *file) {
	
	ssi_fprint (file, "TIER: %s\n", _name.str ());
	ElanTier::iterator it;
	for (it = begin (); it != end (); it++) {
		ssi_fprint (file, "\t%u-%u:%s\n", it->from, it->to, it->value.str ());
	}
}
예제 #3
0
void Thread::PrintInfo (FILE *file) {

	Lock lock (_monitor_mutex);
	ssi_char_t string[SSI_MAX_CHAR];

	ssi_fprint (file, "#   running\telapsed\t\tname\n");
	ssi_size_t count = 0;
	for (ssi_size_t i = 0; i < _monitor_counter; i++) {
		if (_monitor[i]) {
			Thread *thread = _monitor[i];
			ssi_time_sprint (thread->getElapsedTime (), string);
			ssi_fprint (file, "%03u %s\t%s\t%s\n", count++, thread->isActive () ? "true" : "false", string, thread->getName ());
		}
	}
}
예제 #4
0
void SampleList::print (FILE *file) {

	if (_samples.empty ()) {
		return;
	}

	for (_samples_it = _samples.begin (); _samples_it != _samples.end (); _samples_it++) {
		ssi_fprint (file, "%s %s %.3lf [ ", _users.at ((*_samples_it)->user_id), _classes.at ((*_samples_it)->class_id), (*_samples_it)->time);
		for (ssi_size_t i = 0; i < (*_samples_it)->num; i++) {
			ssi_fprint (file, "%ux%u ", (*_samples_it)->streams[i]->num, (*_samples_it)->streams[i]->dim);
		}
		ssi_fprint (file, "]\n");
	}	

	reset ();
}
예제 #5
0
void Evaluation::print_result_vec (FILE *file) {

	if (!_result_vec) {
		ssi_wrn ("nothing to print");
		return;
	}
	ssi_size_t *ptr = _result_vec;
	for (ssi_size_t i = 0; i < _n_total; i++) {
		ssi_fprint (file, "%u %u\n", *ptr, *(ptr+1));
		ptr += 2;
	}
}
예제 #6
0
void SampleList::printInfo (FILE *file) {

	ssi_fprint (file, "samples\t\t%ux%u\n", getSize (), getStreamSize ());	
	ssi_fprint (file, "per class\t");
	for (ssi_size_t nclass = 0; nclass < getClassSize (); nclass++) {
		ssi_fprint (file, "%u ", getSize (nclass));
	}
	ssi_fprint (file, "\nnames\t\t");
	for (ssi_size_t nclass = 0; nclass < getClassSize (); nclass++) {
		ssi_fprint (file, "%s ", getClassName (nclass));
	}
	ssi_fprint (file, "\nstreams\t\t");
	for (ssi_size_t nstream = 0; nstream < getStreamSize (); nstream++) {
		ssi_fprint (file, "%ux%u %s", getSize (), _streams[nstream].dim, SSI_TYPE_NAMES[_streams[nstream].type]);
	}
	ssi_fprint (file, "\n");
	
}
예제 #7
0
void ISMergeSample::printDebug (FILE *file) {

	ssi_fprint (file, "#lists = %u\n#samples = %u ( ", _n_lists, _n_samples);
	for (ssi_size_t i = 0; i < _n_lists; i++) {
		ssi_fprint (file, "%u ", _n_samples_per_list[i]);
	}
	ssi_fprint (file, ")\nusers = ");
	for (ssi_size_t i = 0; i < _n_users; i++) {
		ssi_fprint (file, "%s ", _user_names[i]);
	}	
	for (ssi_size_t i = 0; i < _n_lists; i++) {
		ssi_fprint (file, "\nlist%02u = ", i);
		for (ssi_size_t j = 0; j < _lists[i]->getUserSize (); j++) {
			ssi_fprint (file, "%s ", _user_names[_user_map[i][j]]);
		}
	}
	ssi_fprint (file, "\n");
}
예제 #8
0
		bool FileAnnotationWriter::update(ssi_event_t &e) {
			if (_time == 0) {
				_time = e.time / 1000.0;
			}
			_duration += e.dur / 1000.0;
			if (e.type == SSI_ETYPE_STRING)
			{
				if (e.ptr != NULL)
				{
					sprintf(_meta, ";%s", e.ptr);
				}


			}

			else sprintf(_meta, "");

			if (e.state == SSI_ESTATE_COMPLETED) {
				{
					Lock lock(_label_mutex);

					if (_label) {
						if (_options.eventNameaAsTier)
						{
							ssi_sprint(_string, "%lf;%lf;%s;#%s", _time, _time + _duration, _label, Factory::GetString(e.event_id));
						}

						else if (_options.senderNameAsTier)
						{
							ssi_sprint(_string, "%lf;%lf;%s;#%s", _time, _time + _duration, _label, Factory::GetString(e.sender_id));
						}

						else
						{
							ssi_sprint(_string, "%lf;%lf;%s", _time, _time + _duration, _label);
						}

						if (_tier)
						{
							ssi_sprint(_string, "%lf;%lf;%s;#%s", _time, _time + _duration, _label, _tier);
						}
					}

					else {
						if (_options.eventNameAsLabel && _options.eventNameaAsTier)
						{
							ssi_sprint(_string, "%lf;%lf;%s;#%s%s", _time, _time + _duration, Factory::GetString(e.event_id), Factory::GetString(e.event_id), _meta);
						}

						else if (_options.eventNameAsLabel && _options.senderNameAsTier)
						{
							ssi_sprint(_string, "%lf;%lf;%s;#%s%s", _time, _time + _duration, Factory::GetString(e.event_id), Factory::GetString(e.sender_id), _meta);
						}

						else if (_options.eventNameAsLabel)
						{
							ssi_sprint(_string, "%lf;%lf;%s", _time, _time + _duration, Factory::GetString(e.event_id));
						}
						else
						{
							ssi_sprint(_string, "%lf;%lf", _time, _time + _duration);
						}
					}
				}
				_time = 0;
				_duration = 0;

				ssi_fprint(_file, "%s\n", _string);
				fflush(_file);
			}
			return true;
		}
예제 #9
0
파일: ISNorm.cpp 프로젝트: hcmlab/mobileSSI
bool ISNorm::SaveParams(const ssi_char_t *path, Params &params, File::TYPE type) {

	ssi_char_t string[SSI_MAX_CHAR];

	FilePath fp(path);
	ssi_char_t *path_xml;
	ssi_char_t *path_data;
	if (ssi_strcmp(fp.getExtension(), "norm", false)) {
		path_xml = ssi_strcpy(path);
	} else {
		path_xml = ssi_strcat(path, ".norm");
	}
	path_data = ssi_strcat(path_xml, "~");

	TiXmlElement norm("norm");
	
	TiXmlElement norm_method("method");
	norm_method.InsertEndChild(TiXmlText(METHOD_NAMES[params.method]));
	norm.InsertEndChild(norm_method);

	if (params.method == METHOD::SCALE) {
		TiXmlElement norm_limits("limits");
		ssi_sprint(string, "%f %f", params.limits[0], params.limits[1]);
		norm_limits.InsertEndChild(TiXmlText(string));
		norm.InsertEndChild(norm_limits);
	}

	TiXmlElement norm_dim("dim");
	ssi_sprint(string, "%u", params.n_features);
	norm_dim.InsertEndChild(TiXmlText(string));
	norm.InsertEndChild(norm_dim);

	TiXmlElement norm_type("type");	
	norm_type.InsertEndChild(TiXmlText(File::TYPE_NAMES[type]));
	norm.InsertEndChild(norm_type);
	
	TiXmlDocument doc;
	TiXmlDeclaration head("1.0", "", "");
	doc.InsertEndChild(head);
	doc.InsertEndChild(norm);	
	doc.SaveFile(path_xml);

	if (params.method != METHOD::NONE) {
		FILE *fp = fopen(path_data, type == File::BINARY ? "wb" : "w");
		if (fp) {
			switch (params.method) {			
			case METHOD::SCALE:
				if (type == File::BINARY) {
					fwrite(params.mins, params.n_features, sizeof(ssi_real_t), fp);
					fwrite(params.maxs, params.n_features, sizeof(ssi_real_t), fp);
				} else {
					ssi_real_t *mins = params.mins;
					ssi_real_t *maxs = params.maxs;
					for (ssi_size_t i = 0; i < params.n_features; i++) {
						ssi_fprint(fp, "%f %f\n", *mins++, *maxs++);
					}
				}
				break;
			case METHOD::ZSCORE:
				if (type == File::BINARY) {
					fwrite(params.mean, params.n_features, sizeof(ssi_real_t), fp);
					fwrite(params.stdv, params.n_features, sizeof(ssi_real_t), fp);
				}
				else {
					ssi_real_t *mean = params.mean;
					ssi_real_t *stdv = params.stdv;
					for (ssi_size_t i = 0; i < params.n_features; i++) {
						ssi_fprint(fp, "%f %f\n", *mean++, *stdv++);
					}
				}
				
				break;
			}
		}
		else {
			ssi_wrn("could not open file '%s'", path_data);
			return false;
		}
		fclose(fp);
	}

	delete[] path_data;
	delete[] path_xml;

	return true;
}
예제 #10
0
void Evaluation::print (FILE *file, PRINT::List format) {

	if (!_conf_mat_ptr) {
		ssi_wrn ("nothing to print");
		return;
	}
		
	ssi_size_t max_label_len = 0;
	for (ssi_size_t i = 0; i < _n_classes; ++i) {
		ssi_size_t len = ssi_cast (ssi_size_t, strlen (_class_names[i]));
		if (len > max_label_len) {
			max_label_len = len;
		}
	}

	if (format == PRINT::CSV || format == PRINT::CSV_EX) {

		File *tmp = File::Create(File::ASCII, File::WRITE, 0, file);
		tmp->setType(SSI_UINT);
		tmp->setFormat(";", "");

		ssi_fprint(file, "#classes;%u\n", _n_classes);
		ssi_fprint(file, "#total;%u\n", _n_classified + _n_unclassified);
		ssi_fprint(file, "#classified;%u\n", _n_classified);
		ssi_fprint(file, "#unclassified;%u\n", _n_unclassified);

		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, ";%s", _class_names[i]);
		}

		ssi_fprint(file, "\n");
		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, "%s;", _class_names[i]);
			tmp->write(_conf_mat_ptr[i], 0, _n_classes);
			ssi_fprint(file, "%f\n", 100 * get_class_prob(i));
		}
		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, "; ");
		}
		ssi_fprint(file, ";%f;%f\n", 100 * get_classwise_prob(), 100 * get_accuracy_prob());

		if (format == PRINT::CSV_EX) {
			ssi_fprint(file, "\ntruth;prediction\n");
			ssi_size_t *ptr = _result_vec;
			for (ssi_size_t i = 0; i < _n_total; i++) {
				ssi_fprint(file, "%u;%u\n", ptr[0], ptr[1]);
				ptr += 2;
			}
		}

	} else {

		File *tmp = File::Create(File::ASCII, File::WRITE, 0, file);
		tmp->setType(SSI_UINT);
		tmp->setFormat(" ", "6");

		ssi_fprint(file, "#classes:      %u\n", _n_classes);
		ssi_fprint(file, "#total:        %u\n", _n_classified + _n_unclassified);
		ssi_fprint(file, "#classified:   %u\n", _n_classified);
		ssi_fprint(file, "#unclassified: %u\n", _n_unclassified);

		if (format != PRINT::CONSOLE_EX) {
			for (ssi_size_t j = 0; j < max_label_len + 3; j++) {
				ssi_fprint(file, " ");
			}
			ssi_char_t cut[7];
			for (ssi_size_t i = 0; i < _n_classes; ++i) {
				cutString(_class_names[i], 7, cut);
				ssi_fprint(file, " %6s", cut);
			}
		}
		ssi_fprint(file, "\n");
		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, "%*s: ", max_label_len, _class_names[i]);
			tmp->write(_conf_mat_ptr[i], 0, _n_classes);
			ssi_fprint(file, "   -> %8.2f%%\n", 100 * get_class_prob(i));
		}
		ssi_fprint(file, "   %*s  => %8.2f%% | %.2f%%\n", max_label_len + _n_classes * 7, "", 100 * get_classwise_prob(), 100 * get_accuracy_prob());
		delete tmp;
	}

	fflush (file);
}
예제 #11
0
파일: Rank.cpp 프로젝트: hihiy/IntelliVoice
void Rank::print (FILE *file) {
		
	for (ssi_size_t i = 0; i < _n_scores; i++) {
		ssi_fprint (file, "%u: %.2f\n", _scores[i].index, _scores[i].value);
	}
}
예제 #12
0
// blocksize is size of fft block, _T is period of fft frames
// sampling period is reconstructed by: _T/((blocksize-1)*2)
int OSMelspec::computeFilters (long blocksize, double frameSizeSec)
{

	// following code taken from openSMILE 1.0.1, melspec.cpp
	// http://opensmile.sourceforge.net/


	long _nBands = nBands;
	bs = blocksize;

	if (hfcc) {  // || custom filter
		// independent coefficients for every mel band
		_filterCoeffs = new FLOAT_DMEM[blocksize * _nBands];
		// channel map is different here: start and end fft bins of each band's filter
		_chanMap = new long[_nBands * 2];
	} else {
		_filterCoeffs = new FLOAT_DMEM[blocksize];
		_chanMap = new long[blocksize];
	}
	_filterCfs = new FLOAT_DMEM[_nBands+2];

	FLOAT_DMEM _N = (FLOAT_DMEM) ((blocksize-1)*2);
	FLOAT_DMEM F0 = (FLOAT_DMEM)(1.0/frameSizeSec);
	FLOAT_DMEM Fs = (FLOAT_DMEM)(_N/frameSizeSec);
	FLOAT_DMEM M = (FLOAT_DMEM)_nBands;

	if ((lofreq < 0.0)||(lofreq>Fs/2.0)||(lofreq>hifreq)) lofreq = 0.0;
	if ((hifreq<lofreq)||(hifreq>Fs/2.0)||(hifreq<=0.0)) hifreq = Fs/(FLOAT_DMEM)2.0; // Hertz(NtoFmel(blocksize+1,F0));
	FLOAT_DMEM LoF = (FLOAT_DMEM)specScaleTransfFwd(lofreq, specScale, param);  // Lo Cutoff Freq (mel)
	FLOAT_DMEM HiF = (FLOAT_DMEM)specScaleTransfFwd(hifreq, specScale, param);  // Hi Cutoff Freq (mel)
	nLoF = FtoN(lofreq,F0);  // Lo Cutoff Freq (fft bin)
	nHiF = FtoN(hifreq,F0);  // Hi Cutoff Freq (fft bin)

	if (nLoF > blocksize) nLoF = blocksize;
	if (nHiF > blocksize) nHiF = blocksize;
	if (nLoF < 0) nLoF = 0; //  exclude DC component??
	if (nHiF < 0) nHiF = 0;

	// TODO: option for fully flexible filter bank: n (cf, bw) pairs


	if (hfcc) {
		// custom bandwidth hfcc bank:

		// centre frequencies (similar to standard mfcc, but still a bit different for first and last filter)
		double B,C,b,c,a, bh, ch, ah;
		int m,n;

		// Moore and Glasberg's ERB coefficients for Hz scaling
		a = 0.00000623;
		b = 0.09339;
		c = 28.52;

		// first:
		double fl1 = lofreq;
		double fc1, fh1;

		ah = 0.5/(700.0 + fl1);
		bh = 700.0/(700.0 + fl1);
		ch = -fl1/2.0 * (1.0 + 700.0/(700.0+fl1));

		B = (b-bh)/(a-ah);
		C = (c-ch)/(a-ah);
		fc1 = 0.5*(-B+sqrt(B*B - 4*C));
		fh1 = 2.0 * (a*fc1*fc1 + b*fc1 + c) + fl1; //?

		// last:
		double fhN = hifreq;
		double fcN, flN;

		ah = -0.5/(700.0 + fhN);
		bh = -700.0/(700.0 + fhN);
		ch = fhN/2.0 * (1.0 + 700.0/(700.0+fhN));

		B = (b-bh)/(a-ah);
		C = (c-ch)/(a-ah);
		fcN = 0.5*(-B+sqrt(B*B - 4*C));
		flN = -2.0 * (a*fcN*fcN + b*fcN + c) + fhN; //?

		// equidistant spacing on mel-scale from fc1 to fcN of nBands-2 filters
		double fcNmel = specScaleTransfFwd(fcN, specScale, param);
		double fc1mel = specScaleTransfFwd(fc1, specScale, param);

		FLOAT_DMEM mBandw = (FLOAT_DMEM) ((fcNmel-fc1mel)/(M-1.0f));
		for (m=0; m<_nBands-1; m++) {
			_filterCfs[m] = (FLOAT_DMEM) (fc1mel + m*mBandw);
		}
		_filterCfs[m] = (FLOAT_DMEM) fcNmel;

		for (m=0; m<_nBands; m++) {
			double fc = specScaleTransfInv(_filterCfs[m], specScale, param);
			double ERB7 = a*fc*fc + b* fc + c + 700.0;
			double fl,fh;

			fl = -(ERB7) + sqrt((ERB7*ERB7) + fc*(fc+1400.0));
			fh = fl + 2*(ERB7-700.0);

			if (showFbank) {
				ssi_fprint (ssiout, "Band %i : center = %f Hz (fl: %f , fh: %f Hz ; ERB: %f Hz)",m,fc,fl,fh,(fh-fl)/2.0);
			}

			// start and end fft bins in chanMap
			long flI = _chanMap[m*2] =   FtoN((FLOAT_DMEM) fl,F0); // start
			long fcI = FtoN((FLOAT_DMEM) fc,F0);
			long fhI = _chanMap[m*2+1] = FtoN((FLOAT_DMEM) fh,F0); // end

			//// triangular filters
			// rising slope
			for (n=MAX(flI,0); (n<=fcI)&&(n<blocksize); n++) {
				double f = NtoF(n,F0);
				_filterCoeffs[m*blocksize + n] = (FLOAT_DMEM) ((f-fl)/(fc-fl));
			}
			// falling slope
			for (n=MAX(fcI,0)+1; (n<=fhI)&&(n<blocksize); n++) {
				double f = NtoF(n,F0);
				_filterCoeffs[m*blocksize + n] = (FLOAT_DMEM) ((fh-f)/(fh-fc));
			}
		}
	} else {
		// standard mel filter bank:

		int m,n;
		// compute mel center frequencies
		FLOAT_DMEM mBandw = (HiF-LoF)/(M+(FLOAT_DMEM)1.0); // half bandwidth of mel bands
		for (m=0; m<=_nBands+1; m++) {
			_filterCfs[m] = LoF+(FLOAT_DMEM)m*mBandw;
		}

		if (showFbank) {
			for (m=0; m<=_nBands+1; m++) {
				ssi_fprint (ssiout, "Band %i : center = %f Hz",m-1,specScaleTransfInv(_filterCfs[m], specScale, param));
			}
		}

		// compute channel mapping table:
		m = 0;
		for (n=0; n<blocksize; n++) {
			if ( (n<=nLoF)||(n>=nHiF) ) _chanMap[n] = -3;
			else {
				//printf("II: Cfs[%i]=%f n=%i F0=%f NtoFmel(n,F0)=%f\n",m,_filterCfs[m],n,F0,NtoFmel(n,F0));
				while (_filterCfs[m] < NtoFmel(n,F0)) {
					if (m>_nBands) break;
					m++;
					//printf("Cfs[%i]=%f n=%i F0=%f\n",m,_filterCfs[m],n,F0);
				}
				_chanMap[n] = m-2;
			}
		}

		// compute filter weights (falling slope only):
		m = 0;
		FLOAT_DMEM nM;
		for (n=nLoF;n<nHiF;n++) {
			nM = NtoFmel(n,F0);
			while ((nM > _filterCfs[m+1]) && (m<=_nBands)) m++;
			_filterCoeffs[n] = ( _filterCfs[m+1] - nM )/(_filterCfs[m+1] - _filterCfs[m]);
		}

	}
	return 0;
}