예제 #1
0
void SocketEventReader::flush () {
	
	delete _socket; _socket = 0;
	delete _socket_osc; _socket_osc = 0;
	delete[] _buffer; _buffer = 0;

	ssi_char_t string[SSI_MAX_CHAR];
	ssi_sprint(string, "%s@%u", _options.host, _options.port);
	ssi_msg(SSI_LOG_LEVEL_BASIC, "stopped'%s'", string);
}
예제 #2
0
void MyConsumer::consume(IConsumer::info consume_info,
	ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	ssi_char_t string[20];
	for (ssi_size_t i = 0; i < stream_in_num; i++) {
		ssi_sprint(string, "stream#%u", i);
		_file->writeLine(string);
		_file->write(stream_in[i].ptr, stream_in[i].dim, stream_in[i].dim * stream_in[i].num);
	}
}
예제 #3
0
void FFMPEGReader::enter () {

	ssi_char_t str[SSI_MAX_CHAR];
	ssi_sprint (str, "FFMPEGReader@%s", _options.url);
	Thread::setName (str);

	if (_mode == MODE::AUDIO) { 
		_timer = new Timer (_options.ablock);	
	} else {
		_timer = new Timer (1.0/_video_format.framesPerSecond);	
	}
}
예제 #4
0
void SocketEventReader::enter () {

	_socket = Socket::CreateAndConnect (_options.type, Socket::SERVER, _options.port, _options.host);	
	if (_options.osc) {
		_socket_osc = new SocketOsc (*_socket, _options.size);
	} else {
		_buffer = new ssi_byte_t[_options.size];
	}
	
	if (!_socket) {
		ssi_wrn ("could not connect '%s@%u'", _options.host, _options.port);
	}

	_frame = Factory::GetFramework ();
	
	ssi_char_t string[SSI_MAX_CHAR];
	ssi_sprint (string, "SocketEventReader@'%s@%u'", _options.host, _options.port); 	
	Thread::setName (string);

	ssi_sprint(string, "%s@%u", _options.host, _options.port);
	ssi_msg(SSI_LOG_LEVEL_BASIC, "started '%s'", string);
}
예제 #5
0
void MapEventSender::consume_enter (ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	if (stream_in[0].type != SSI_REAL) {
		ssi_err ("type '%s' not supported", SSI_TYPE_NAMES[stream_in[0].type]);
	}

	ssi_size_t dim = stream_in[0].dim;

	ssi_event_adjust(_event, sizeof(ssi_event_map_t) * dim);
	ssi_event_map_t *dst = ssi_pcast(ssi_event_map_t, _event.ptr);

	ssi_char_t **keys = 0;
	if (_options.keys[0] != '\0') {
		ssi_size_t n = ssi_split_string_count(_options.keys, ',');
		keys = new ssi_char_t *[dim];
		ssi_split_string(n, keys, _options.keys, ',');
		for (ssi_size_t i = n; i < dim; i++) {			
			keys[i] = ssi_strcpy(keys[i%n]);
		}
	}

	ssi_char_t str[512];
	if (keys) {
		for (ssi_size_t i = 0; i < dim; i++) {
			dst++->id = Factory::AddString(keys[i]);
		}
	} else {
		for (ssi_size_t i = 0; i < dim; i++) {
			ssi_sprint(str, "dim#%u", i);
			dst++->id = Factory::AddString(str);
		}
	}

	if (keys) {
		for (ssi_size_t i = 0; i < dim; i++) {
			delete[] keys[i];
		}
		delete[] keys; keys = 0;
	}
}
예제 #6
0
void SignalPainter::consume_enter (ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	_n_windows = stream_in_num;
	_window = new IWindow *[_n_windows];	
	_canvas = new ICanvas *[_n_windows];
	_client = new ICanvasClient *[_n_windows];

	ssi_char_t **titles = new ssi_char_t *[_n_windows];
	if (_n_windows == 1)
	{
		titles[0] = ssi_strcpy(_options.title);
	} 
	else
	{
		ssi_char_t n_titles = ssi_split_string_count(_options.title, ';');
		if (n_titles == _n_windows)
		{
			ssi_split_string(_n_windows, titles, _options.title, ';');
		}
		else
		{
			ssi_char_t string[SSI_MAX_CHAR];
			for (ssi_size_t i = 0; i < _n_windows; i++)
			{
				ssi_sprint(string, "%s#%02d", _options.title, i);
				titles[i] = ssi_strcpy(string);
			}
		}
	}

	int pos_top = _options.pos[1];
	int pos_height = _options.pos[3] / _n_windows;
	for (ssi_size_t i = 0; i < _n_windows; i++) {

		if (_options.type == PaintSignalType::BAR || _options.type == PaintSignalType::BAR_POS) {
			PaintBars *plot = new PaintBars(_options.type == PaintSignalType::BAR ? PaintBars::TYPE::BAR : PaintBars::TYPE::BAR_POS);
			if (!_options.autoscale){
				plot->setFixedLimit(ssi_cast(ssi_real_t, _options.fix[0]));
			} else {
				if (!_options.reset) {
					plot->setGlobalLimit(false);
				}
			}
			plot->setPrecision(_options.axisPrecision);
			_client[i] = plot;
		} else {
			PaintSignal *plot = new PaintSignal(stream_in[i].sr, stream_in[i].dim, _options.size, _options.type, _options.indx, _options.indy, _options.staticImage);
			plot->setIndices(_options.indx, _options.indy);
			plot->setPrecision(_options.axisPrecision);
			plot->setColormap(_options.colormap);
			if (!_options.autoscale){
				plot->setLimits(ssi_cast(ssi_real_t, _options.fix[0]), ssi_cast(ssi_real_t, _options.fix[1]));
			}
			_client[i] = plot;
		}		

		_canvas[i] = new Canvas();
		_canvas[i]->addClient(_client[i]);

		_window[i] = new Window();
		_window[i]->setClient(_canvas[i]);
			
		_window[i]->setTitle(titles[i]);				
		_window[i]->setPosition(ssi_rect(_options.pos[0], pos_top + i * pos_height, _options.pos[2], pos_height));

		_window[i]->create();
		_window[i]->show();	

		delete[] titles[i];
	}
	delete[] titles;
}
예제 #7
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;
		}
예제 #8
0
bool FileSamplesOut::open (ISamples &data,
	const ssi_char_t *path,
	File::TYPE type, 
	File::VERSION version) {

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "open files '%s'", path);	

	_version = version;

	if (_version < File::V2) {
		ssi_wrn ("version < V2 not supported");
		return false;
	}

	if (_file_info || _file_data) {
		ssi_wrn ("samples already open");
		return false;
	}

	_n_users = data.getUserSize ();
	_users = new ssi_char_t *[_n_users];
	_n_per_user = new ssi_size_t[_n_users];
	for (ssi_size_t i = 0; i < _n_users; i++) {
		_users[i] = ssi_strcpy (data.getUserName (i));
		_n_per_user[i] = 0;
	}
	_n_classes = data.getClassSize ();
	_classes = new ssi_char_t *[_n_classes];
	_n_per_class = new ssi_size_t[_n_classes];
	for (ssi_size_t i = 0; i < _n_classes; i++) {
		_classes[i] = ssi_strcpy (data.getClassName (i));
		_n_per_class[i] = 0;
	}
	
	_n_streams = data.getStreamSize ();
	_streams = new ssi_stream_t[_n_streams];
	for (ssi_size_t i = 0; i < _n_streams; i++) {
		ssi_stream_t s = data.getStream (i);
		ssi_stream_init (_streams[i], 0, s.dim, s.byte, s.type, s.sr, 0);
	}

	_has_missing_data = false;

	if (path == 0 || path[0] == '\0') {
		_console = true;
	}

	if (_console) {
		
		_file_data = File::CreateAndOpen (type, File::WRITE, "");
		if (!_file_data) {
			ssi_wrn ("could not open console");
			return false;
		}

	} else {

		FilePath fp (path);
		ssi_char_t *path_info = 0;
		if (strcmp (fp.getExtension (), SSI_FILE_TYPE_SAMPLES) != 0) {
			path_info = ssi_strcat (path, SSI_FILE_TYPE_SAMPLES);
		} else {
			path_info = ssi_strcpy (path);
		}	
		_path = ssi_strcpy (path_info);

		_file_info = File::CreateAndOpen (File::ASCII, File::WRITE, path_info);
		if (!_file_info) {
			ssi_wrn ("could not open info file '%s'", path_info);
			return false;
		}

		ssi_sprint (_string, "<?xml version=\"1.0\" ?>\n<samples ssi-v=\"%d\">", version);
		_file_info->writeLine (_string);
	
		ssi_char_t *path_data = ssi_strcat (path_info, "~");			
		_file_data = File::CreateAndOpen (type, File::WRITE, path_data);
		if (!_file_data) {
			ssi_wrn ("could not open data file '%s'", path_data);
			return false;
		}

		if (_version == File::V3) {

			_file_streams = new FileStreamOut[_n_streams];
			ssi_char_t string[SSI_MAX_CHAR];
			for (ssi_size_t i = 0; i < _n_streams; i++) {
				ssi_sprint (string, "%s.#%u", path_info, i);
				_file_streams[i].open (_streams[i], string, type);				
			}

		}

		delete[] path_info;
		delete[] path_data;

	}

	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;
}