Пример #1
0
void MvgConDiv::transform_flush (ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num ,
	ssi_stream_t xtra_stream_in[]) {

	_mvgs->transform_flush (stream_in, _mvgs_tmp);
	_mvgl->transform_flush (stream_in, _mvgl_tmp);
	ssi_stream_destroy (_mvgs_tmp);
	ssi_stream_destroy (_mvgl_tmp);
	delete _mvgs; _mvgs = 0;
	delete _mvgl; _mvgl = 0;
}
Пример #2
0
PaintData::~PaintData() {

	delete _colormap;
	delete _pen;	
	delete _brush;
	delete _font;
	delete _font_pen;
	delete _font_brush;
	delete _painter;

	ssi_stream_destroy(_stream);
	ssi_stream_destroy(_resample);
	delete[] _mins;
	delete[] _maxs;
}
Пример #3
0
void Chain::transform_flush (ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	// destroy arrays and flush transformer
	_stream_tmp[0] = &stream_in; // first is always the input stream
	_stream_tmp[_stream_tmp_num-1] = &stream_out; // last is always the output stream
	for (ssi_size_t i = 0; i < _n_filters; i++) {
		_filters[i]->transform_flush (*_stream_tmp[i], *_stream_tmp[i+1]);
	}
	if (_n_features > 0) {
		for (ssi_size_t i = 0; i < _n_features; i++) {
			_stream_tmp[_stream_tmp_num-1]->dim = _feature_dim_out[i];				
			_features[i]->transform_flush (*_stream_tmp[_stream_tmp_num-2], *_stream_tmp[_stream_tmp_num-1]);	
		}
		_stream_tmp[_stream_tmp_num-1]->dim = _feature_dim_out_tot;	
	}
	for (ssi_size_t i = 1; i < _stream_tmp_num - 1; i++) {
		ssi_stream_destroy (*_stream_tmp[i]);
		delete _stream_tmp[i];
	}

	delete[] _stream_tmp; _stream_tmp = 0;
	delete[] _feature_dim_out; _feature_dim_out = 0;
}
Пример #4
0
void AudioActivity::transform_flush (ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	

	if (_convert_input) {
		_feature->transform_flush (_stream_convert, _stream_feat);
		delete _convert; _convert = 0;
		ssi_stream_destroy (_stream_convert);
	} else {
		_feature->transform_flush (stream_in, _stream_feat);
	}

	delete _feature; _feature = 0;
	ssi_stream_destroy (_stream_feat);
}
Пример #5
0
Transformer::~Transformer () {

	if (_xtra_stream_num > 0) {
		for (ssi_size_t i = 0; i < _xtra_stream_num; i++) {
			ssi_stream_destroy (_xtra_streams[i]);
		}		
	}
	delete[] _xtra_streams;
	delete[] _xtra_stream_ids;
}
Пример #6
0
bool FileReader::disconnect () {

	ssi_msg(SSI_LOG_LEVEL_BASIC, "stop reading from '%s'", _options.path);

	delete _timer; _timer = 0;
	ssi_stream_destroy(_stream);

	if (!_file_stream_in.close())
	{
		ssi_err("could not close stream '%s'", _options.path);
	}

	return true;
}
Пример #7
0
bool FeatureFusion::forward (ssi_size_t n_models,
	IModel **models,
	ssi_size_t n_streams,
	ssi_stream_t *streams[],
	ssi_size_t n_probs,
	ssi_real_t *probs) {

	if (!isTrained ()) {
		ssi_wrn ("not trained");
		return false;
	}

	if (n_streams != _n_streams) {
		ssi_wrn ("#streams (%u) differs from #streams (%u)", n_streams, _n_streams);
		return false;
	}

	if (_n_models != n_models) {
		ssi_wrn ("#models (%u) differs from #models (%u)", n_models, _n_models);
		return false;
	}

	if (_n_classes != n_probs) {
		ssi_wrn ("#probs (%u) differs from #classes (%u)", n_probs ,_n_classes);
		return false;
	}

	//No Missing Data:
	if(!_handle_md){

		IModel *model = 0;
		ssi_stream_t *stream = 0;

		model = models[0];

		ssi_stream_t *fusion_stream = new ssi_stream_t;

		ssi_size_t fusion_stream_dim = 0;
		for(ssi_size_t nstrm = 0; nstrm < _n_streams; nstrm++){
			fusion_stream_dim += streams[nstrm]->dim;
		}

		//create aligned streams
		ssi_stream_init (*fusion_stream, 1, fusion_stream_dim, streams[0]->byte, streams[0]->type, streams[0]->sr);
		
		ssi_byte_t *ptr = fusion_stream->ptr;
		for(ssi_size_t i = 0; i < _n_streams; i++){
			memcpy(ptr, streams[i]->ptr, ( streams[i]->byte * streams[i]->dim ) );
			ptr += ( streams[i]->byte * streams[i]->dim );
		}

		//clear probs
		for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
			probs[num_probs] = 0.0f;
		}

		model->forward (*fusion_stream, n_probs, probs);

		ssi_stream_destroy(*fusion_stream);
		delete fusion_stream;
		fusion_stream = 0;

		///// is there a draw ? ///
		ssi_size_t max_ind = 0;
		ssi_size_t max_ind_draw = 0;
		ssi_real_t max_val = probs[0];
		bool draw = false;

		for (ssi_size_t i = 1; i < n_probs; i++) {
			if (probs[i] >= max_val) {
				if(probs[i] == max_val){
					draw = true;
					max_ind_draw = i;
				}
				max_val = probs[i];
				max_ind = i;
			}
		}
		
		if(draw && (max_ind == max_ind_draw)){
			return false;
		}else{
			return true;
		}

	}//No Missing Data


	//Missing Data:
	bool found_data = false;

	IModel *model = 0;
	ssi_stream_t *stream = 0;

	//calculate actual models
	ssi_size_t miss_counter = 0;
	ssi_size_t *available = new ssi_size_t[n_models];
	available[0] = 1;
	for (ssi_size_t n_model = 1; n_model < _n_models; n_model++) {
		stream = streams[n_model - 1];
		if (stream->num > 0) {
			found_data = true;
			available[n_model] = 1;
		}
		else{
			miss_counter++;
			available[n_model] = 0;
			if(available[0] == 1){
				available[0] = 0;
				miss_counter++;
			}
		}
	}
	ssi_size_t counter = 0;
	ssi_size_t *models_actual = new ssi_size_t[(n_models - miss_counter)];
	for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
		if(available[n_model] == 1){
			models_actual[counter] = n_model;
			counter++;
		}
	}

	if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
		ssi_print("\n\n-----------------------------\navailable models:\n");
		for(ssi_size_t i = 0; i < (n_models - miss_counter); i++){
			ssi_print("%d ", models_actual[i]);
		}ssi_print("\n");
	}

	if(found_data){

		if(available[0] == 1){
			//feature fusion possible
			if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
				ssi_print("\nfeature fusion possible\n");
			}

			model = models[0];
			stream = 0;
			ssi_stream_t *fusion_stream = new ssi_stream_t;

			ssi_size_t fusion_stream_dim = 0;
			for(ssi_size_t nstrm = 0; nstrm < _n_streams; nstrm++){
				fusion_stream_dim += streams[nstrm]->dim;
			}

			//create aligned streams
			ssi_stream_init (*fusion_stream, 1, fusion_stream_dim, streams[0]->byte, streams[0]->type, streams[0]->sr);
			
			ssi_byte_t *ptr = fusion_stream->ptr;
			for(ssi_size_t i = 0; i < _n_streams; i++){
				memcpy(ptr, streams[i]->ptr, ( streams[i]->byte * streams[i]->dim ) );
				ptr += ( streams[i]->byte * streams[i]->dim );
			}

			//clear probs
			for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
				probs[num_probs] = 0.0f;
			}

			model->forward (*fusion_stream, n_probs, probs);

			ssi_stream_destroy(*fusion_stream);
			delete fusion_stream;
			fusion_stream = 0;

			if(available){
				delete [] available;
				available = 0;
			}
			if(models_actual){
				delete [] models_actual;
				models_actual = 0;
			}

			return true;

		}else{
			//feature fusion not possible, choose filler ...
			if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
				ssi_print("\nfeature fusion not possible: filler needed\n");
				ssi_print("\nfiller:\n");
				for (ssi_size_t n_model = 0; n_model < _n_streams; n_model++) {
					ssi_print("%d ", _filler[n_model]);
				}ssi_print("\n");
			}

			bool model_available = false;
			ssi_size_t model_id = 0;
			for(ssi_size_t h = 0; h < _n_streams; h++){
				model_id = _filler[h];
				for(ssi_size_t i = 0; i < (n_models - miss_counter); i++){
					if(model_id == models_actual[i]){
						model_available = true;
						break;
					}
				}
				if(model_available == true){
					model = models[model_id];
					if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
						ssi_print("\nSelected Model: %d", model_id);
					}
					break;
				}
			}

			model->forward(*streams[model_id - 1], n_probs, probs);

		}

	}

	if(available){
		delete [] available;
		available = 0;
	}
	if(models_actual){
		delete [] models_actual;
		models_actual = 0;
	}
	

	/// is there a draw ? ///
	ssi_size_t max_ind = 0;
	ssi_size_t max_ind_draw = 0;
	ssi_real_t max_val = probs[0];
	bool draw = false;

	for (ssi_size_t i = 1; i < n_probs; i++) {
		if (probs[i] >= max_val) {
			if(probs[i] == max_val){
				draw = true;
				max_ind_draw = i;
			}
			max_val = probs[i];
			max_ind = i;
		}
	}
	
	if(draw && (max_ind == max_ind_draw)){
		return false;
	}else{
		return found_data;
	}
}
Пример #8
0
ISMergeDim::~ISMergeDim () {

	ssi_stream_destroy (_stream);
	delete[] _sample_out.streams;

}	
Пример #9
0
void PaintData::paint(ICanvas *canvas, ssi_handle_t context, ssi_rect_t area) {

	Lock lock(_mutex);

	if (_stream.num == 0) {
		return;
	}

	_painter->begin(context, area);

	if (_stream_has_changed) {

		if (_stream.dim != _dim) {
			ssi_stream_destroy(_resample);
			ssi_stream_init(_resample, 0, _stream.dim, _stream.byte, _stream.type, _stream.sr, _stream.time);
			_dim = _stream.dim;
			delete[] _mins; delete[] _maxs;
			_mins = new ssi_real_t[_dim];
			_maxs = new ssi_real_t[_dim];
		}

		switch (_type) {
		case TYPE::SIGNAL:
		case TYPE::AUDIO:
		case TYPE::IMAGE: {

			ssi_stream_adjust(_resample, ssi_cast(ssi_size_t, area.width));
			ssi_resample(_stream.num, _resample.num, _stream.dim, ssi_pcast(ssi_real_t, _stream.ptr), ssi_pcast(ssi_real_t, _resample.ptr), _type == TYPE::AUDIO ? ssi_max : ssi_mean);			

			break;
		}

		case TYPE::PATH:
		case TYPE::SCATTER: {

			ssi_stream_adjust(_resample, _stream.num);
			memcpy(_resample.ptr, _stream.ptr, _stream.tot);						

			break;
		}
		}

		if (!_fix_limits) {
			if (_reset_limits) {
				ssi_minmax(_resample.num, _resample.dim, ssi_pcast(ssi_real_t, _resample.ptr), _mins, _maxs);
				_reset_limits = false;
			}
			else {
				ssi_real_t *mins = new ssi_real_t[_dim];
				ssi_real_t *maxs = new ssi_real_t[_dim];
				ssi_minmax(_resample.num, _resample.dim, ssi_pcast(ssi_real_t, _resample.ptr), mins, maxs);
				for (ssi_size_t i = 0; i < _dim; i++) {
					_mins[i] = min(_mins[i], mins[i]);
					_maxs[i] = max(_maxs[i], maxs[i]);
				}
				delete[] mins;
				delete[] maxs;
			}
			if (_type == TYPE::AUDIO) {
				for (ssi_size_t i = 0; i < _dim; i++) {
					_maxs[i] = abs(_maxs[i]);
					_mins[i] = -_maxs[i];
				}
			}
		}
		else {
			for (ssi_size_t i = 0; i < _dim; i++) {
				_mins[i] = _fix_min;
				_maxs[i] = _fix_max;
			}
		}

		ssi_norm(_resample.num, _resample.dim, ssi_pcast(ssi_real_t, _resample.ptr), _mins, _maxs);

		_stream_has_changed = false;
	}

	if (_back_toggle) {
		_painter->fill(*_back_brush, area);
	}

	switch (_type) {
	case TYPE::SIGNAL:
		GraphicTools::PaintAsSignal(_resample, *_painter, *_pen);
		break;
	case TYPE::AUDIO:
		GraphicTools::PaintAsAudio(_resample, *_painter, *_pen);
		break;
	case TYPE::PATH:
		GraphicTools::PaintAsPath(_resample, _indx, _indy, *_painter, *_pen);
		break;
	case TYPE::SCATTER:
		GraphicTools::PaintAsScatter(_resample, _indx, _indy, *_painter, *_pen, *_brush, _point_size);
		break;
	case TYPE::IMAGE:
		GraphicTools::PaintAsImage(_resample, *_painter, *_colormap);
		break;
	}

	switch (_type) {
	case TYPE::SIGNAL:
	case TYPE::AUDIO:
		GraphicTools::PaintAxis(_stream.dim, _stream.time, _stream.time + (_stream.sr > 0 ? _stream.num / _stream.sr : 0), _mins, _maxs, *_painter, *_font, *_font_pen, *_font_brush, _precision);
		break;
	case TYPE::PATH:
	case TYPE::SCATTER:
	case TYPE::IMAGE:
		ssi_real_t minval, maxval, tmp;
		ssi_minmax(_dim, 1, _mins, &minval, &tmp);
		ssi_minmax(_dim, 1, _maxs, &tmp, &maxval);
		GraphicTools::PaintAxis(1, _stream.time, _stream.time + (_stream.sr > 0 ? _stream.num / _stream.sr : 0), &minval, &maxval, *_painter, *_font, *_font_pen, *_font_brush, _precision);
		break;
	}

	_painter->end();
}