Exemple #1
0
ssi_point_t Painter::pointf2point(ssi_pointf_t point, ssi_rect_t area) {

	ssi_point_t p;
	p.x = ssi_cast(ssi_int_t, point.x * area.width + 0.5f);
	p.y = ssi_cast(ssi_int_t, point.y * area.height + 0.5f);
	return p;
}
Exemple #2
0
void QRSDetection::sendEvent_h(ITransformer::info &info, ssi_time_t sample_rate, ssi_size_t frame_count, ssi_size_t sample_number){

	ssi_size_t samples_per_frame = info.frame_num;
	ssi_size_t frame_time = ssi_sec2ms (info.time);
	ssi_real_t time_per_sample = 1000.0f / (ssi_real_t) sample_rate;

	ssi_size_t current_sample = frame_count * samples_per_frame + sample_number;
	ssi_size_t current_sample_time = ssi_cast (ssi_size_t, current_sample * time_per_sample + 0.5);

	if (_listener) {
		_r_event.time = current_sample_time;
		_r_event.dur = ssi_cast (ssi_size_t, time_per_sample + 0.5);

		if(_send_etuple) {
			ssi_event_map_t *ptr = ssi_pcast (ssi_event_map_t, _r_event.ptr);
			ptr[0].value = ssi_real_t (current_sample_time - _last_R);
		} else {
			ssi_real_t *ptr = ssi_pcast (ssi_real_t, _r_event.ptr);
			ptr[0] = ssi_real_t(current_sample_time - _last_R);
		}

		_listener->update (_r_event);
	} else {
		ssi_print("\nR-spike detected in \n\tframe number %u with starting time %u ms", frame_count, frame_time);
		ssi_print("\n\tat sample number %u at time %u ms", current_sample, current_sample_time);
	}

	_last_R = current_sample_time;
}
Exemple #3
0
ssi_point_t Painter::pointf2point(ssi_pointf_t point) {

	ssi_point_t p;
	p.x = ssi_cast(ssi_int_t, point.x + 0.5f);
	p.y = ssi_cast(ssi_int_t, point.y + 0.5f);
	return p;
}
Exemple #4
0
void AudioConvert::transform (ITransformer::info info,
	ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	if (_short_to_float) {

        int16_t *srcptr = ssi_pcast (int16_t, stream_in.ptr);
		ssi_real_t *dstptr = ssi_pcast (ssi_real_t, stream_out.ptr);
		ssi_size_t N = stream_in.num * stream_in.dim;

		for (ssi_size_t i = 0; i < N; i++) {
			*dstptr++ = ssi_cast (ssi_real_t, *srcptr++) / 32768.0f;
		}		

	} else {

		ssi_real_t *srcptr = ssi_pcast (ssi_real_t, stream_in.ptr);
        int16_t *dstptr = ssi_pcast (int16_t, stream_out.ptr);
		ssi_size_t N = stream_in.num * stream_in.dim;
		
		for (ssi_size_t i = 0; i < N; i++) {
            *dstptr++ = ssi_cast (int16_t, *srcptr++ * 32768.0f);
		}		
	}	
}
Exemple #5
0
void SignalTools::Series (ssi_stream_t &series,		
	ssi_time_t duration, 		
	ssi_real_t offset) {

	/* matlab code:

	t = 0:1/sr:dur-1/sr;

	*/

	ssi_real_t delta = ssi_cast (ssi_real_t, 1.0 / series.sr);
	ssi_size_t number = ssi_cast (ssi_size_t, duration / delta);
	SSI_ASSERT (number > 0);

	ssi_stream_adjust (series, number);
	ssi_real_t *out = ssi_pcast (ssi_real_t, series.ptr);
	ssi_real_t *outptr_new = out;
	ssi_real_t *outptr_old = out;
	for (ssi_size_t i = 0; i < series.dim; ++i) {
		*outptr_new++ = offset;
	}
	for (ssi_size_t i = series.dim; i < series.dim * series.num; ++i) {
		*outptr_new++ = *outptr_old++ + delta;	
	}
}
Exemple #6
0
	ssi_real_t Statistics::calculateSkewness(ssi_size_t dim_idx)
	{
		running_stat_t * rs = &(_running_stats[dim_idx]);
		if (rs->M2 == 0.0){
			return 0.0f;
		}
		return ssi_cast(ssi_real_t, sqrt(ssi_cast(ssi_stat_ultra_precision_t, rs->n)) * rs->M3 / pow(rs->M2, ssi_cast(ssi_stat_ultra_precision_t, 1.5)));
	}
Exemple #7
0
ssi_rect_t Painter::rectf2rect(ssi_rectf_t rect, ssi_rect_t area) {

	ssi_rect_t r;
	r.left = ssi_cast(ssi_int_t, rect.left * area.width + 0.5f);
	r.top = ssi_cast(ssi_int_t, rect.top * area.height + 0.5f);
	r.width = ssi_cast(ssi_int_t, rect.width * area.width + 0.5f);
	r.height = ssi_cast(ssi_int_t, rect.height * area.height + 0.5f);
	return r;
}
Exemple #8
0
ssi_rect_t Painter::rectf2rect(ssi_rectf_t rect) {

	ssi_rect_t r;
	r.left = ssi_cast(ssi_int_t, rect.left + 0.5f);
	r.top = ssi_cast(ssi_int_t, rect.top + 0.5f);
	r.width = ssi_cast(ssi_int_t, rect.width + 0.5f);
	r.height = ssi_cast(ssi_int_t, rect.height + 0.5f);
	return r;
}
Exemple #9
0
ssi_real_t Evaluation::get_class_prob (ssi_size_t index) {

	ssi_size_t sum = 0;
	for (ssi_size_t i = 0; i < _n_classes; ++i) {
		sum += _conf_mat_ptr[index][i];
	}
	ssi_real_t prob = sum > 0 ? ssi_cast (ssi_real_t, _conf_mat_ptr[index][index]) / ssi_cast (ssi_real_t, sum) : 0; 

	return prob;
}
Exemple #10
0
	ssi_real_t Statistics::calculateKurtosis(ssi_size_t dim_idx)
	{
		running_stat_t * rs = &(_running_stats[dim_idx]);

		if (rs->M2 == 0.0){
			return 0.0f;
		}

		return ssi_cast(ssi_real_t, ssi_cast(ssi_stat_ultra_precision_t, rs->n)*rs->M4 / (rs->M2*rs->M2) - 3.0);
	}
Exemple #11
0
bool FileReader::prepare_file () {

	if (_options.offsetInSamples > 0) {
		_offset_in_samples = _options.offsetInSamples;
	} else {
		_offset_in_samples = ssi_cast (ssi_size_t, _stream.sr * _options.offset);
	}
	_offset_in_bytes = _offset_in_samples * _stream.dim * _stream.byte;

	if (_offset_in_samples > _sample_number_total) {
		ssi_wrn ("offset exceeds stream number");
		return false;
	}

	if (_options.cutoffInSamples > 0) {
		_cutoff_in_samples = _options.cutoffInSamples;
	} else {
		_cutoff_in_samples = ssi_cast (ssi_size_t, _stream.sr * _options.cutoff);
	}
	
	if (_options.blockInSamples > 0) {
		_sample_number_per_step = _options.blockInSamples;
	} else {
		_sample_number_per_step = ssi_cast (ssi_size_t, _stream.sr * _options.block);
	}

	_step_counter = 0;
	if (_cutoff_in_samples == 0) {
		_max_steps = (_sample_number_total - _offset_in_samples)  / _sample_number_per_step;
	} else {

		if (_cutoff_in_samples > _sample_number_total) {
			ssi_wrn ("cutoff exceeds stream number");
			return false;
		}

		if (_offset_in_samples > _cutoff_in_samples) {
			ssi_wrn ("offset exceeds cutoff");
			return false;
		}

		_max_steps = (_cutoff_in_samples - _offset_in_samples)  / _sample_number_per_step;
	}

	if (_max_steps == 0) {
		ssi_wrn ("file too short");
		return false;
	}
	_options.block = _sample_number_per_step / _stream.sr;
	
	ssi_stream_adjust (_stream, _sample_number_per_step);
	_file_stream_in.getDataFile ()->seek (_offset_in_bytes);

	return true;
}
Exemple #12
0
void EmoVoicePitch::transform_enter (ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	if (!_cfg) {
		_cfg = pitch_create (ssi_cast (pitch_method_t, _options.method));
		_cfg->minimumPitch = ssi_cast (mx_real_t, _options.minfreq);
		_cfg->maximumPitch = ssi_cast (mx_real_t, _options.maxfreq);
	}
}
Exemple #13
0
ssi_real_t Evaluation::get_accuracy_prob () {

	ssi_size_t sum_correct = 0;
	for (ssi_size_t i = 0; i < _n_classes; ++i) {
		sum_correct += _conf_mat_ptr[i][i];
	}

	ssi_real_t prob = _n_classified > 0 ? ssi_cast (ssi_real_t, sum_correct) / ssi_cast (ssi_real_t, _n_classified) : 0; 

	return prob;
}
Exemple #14
0
void MyEventSender::consume(IConsumer::info consume_info,
	ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	ssi_real_t *in = ssi_pcast(ssi_real_t, stream_in[0].ptr);
	ssi_real_t *out = ssi_pcast(ssi_real_t, _event.ptr);

	ssi_mean(stream_in[0].num, stream_in[0].dim, in, out);

	_event.time = ssi_cast(ssi_size_t, consume_info.time * 1000);
	_event.dur = ssi_cast(ssi_size_t, consume_info.dur * 1000);
	_elistener->update(_event);
}
void TupleEventSender::consume (IConsumer::info consume_info,
	ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	ssi_size_t dim = stream_in[0].dim;
	ssi_size_t num = stream_in[0].num;

	ssi_real_t *src = ssi_pcast(ssi_real_t, stream_in[0].ptr);
	ssi_event_tuple_t *dst = ssi_pcast(ssi_event_tuple_t, _event.ptr);
	
	_event.time = ssi_cast (ssi_size_t, 1000 * consume_info.time + 0.5);
	_event.dur = ssi_cast (ssi_size_t, 1000 * consume_info.dur + 0.5);	
	_event.state = consume_info.status == IConsumer::COMPLETED ? SSI_ESTATE_COMPLETED : SSI_ESTATE_CONTINUED;
	
	if (_options.mean) {			
		ssi_real_t *mean = new ssi_real_t[dim];
		ssi_mean(num, dim, src, mean);
		for (ssi_size_t i = 0; i < dim; i++) {
			dst++->value = mean[i];
		}		
	}
	if (_options.var) {
		ssi_real_t *var = new ssi_real_t[dim];
		ssi_var(num, dim, src, var);
		for (ssi_size_t i = 0; i < dim; i++) {
			dst++->value = var[i];
		}
	}
	if (_options.minval || _options.maxval) {
		ssi_real_t *minval = new ssi_real_t[dim];
		ssi_size_t *minpos = new ssi_size_t[dim];
		ssi_real_t *maxval = new ssi_real_t[dim];
		ssi_size_t *maxpos = new ssi_size_t[dim];
		ssi_minmax(num, dim, src, minval, minpos, maxval, maxpos);
		if (_options.minval) {
			for (ssi_size_t i = 0; i < dim; i++) {
				dst++->value = minval[i];
			}
		}
		if (_options.maxval) {
			for (ssi_size_t i = 0; i < dim; i++) {
				dst++->value = maxval[i];
			}
		}
	}

	_listener->update(_event);

}
Exemple #16
0
bool ISTrigger::setTriggerStream (ssi_size_t index, ssi_stream_t &trigger, ssi_real_t thres) {

	if (trigger.type != SSI_REAL) {
		ssi_wrn ("ISTrigger::setTriggerStream () -> stream.type != SSI_REAL"); 
		return false;
	}

	if (trigger.dim != 1) {
		ssi_wrn ("ISTrigger::setTriggerStream () -> stream.dim != 1"); 
		return false;
	}

	_samples.reset ();
	ssi_sample_t *sample;
	ssi_size_t count = 0;
	ssi_real_t *ptr = 0;
	ssi_real_t sum = 0;
	ssi_size_t from, to;
	while (sample = _samples.next ()) {
				
		if (sample->streams[index] == 0) {
			_trigger[index][count] = false;
			++count;
			continue;
		}

		from = ssi_cast (ssi_size_t, sample->time * trigger.sr + 0.5);
		to = from + ssi_cast (ssi_size_t, sample->streams[index]->num / sample->streams[index]->sr * trigger.sr + 0.5) - 1;

		if (to >= trigger.num) {
			ssi_wrn ("sample#%u exceeds trigger stream, setting remaining samples to false", count);
			for (; count < _samples.getSize (); count++) {
				_trigger[index][count] = false;
			}
			break;
		}

		sum = 0; 		
		ptr = ssi_pcast (ssi_real_t, trigger.ptr) + from;
		for (ssi_size_t i = from; i <= to; i++) {
			sum += *ptr++;
		}
		
		_trigger[index][count] = sum / (to - from + 1) > thres;
		++count;
	}
	
	return true;
}
Exemple #17
0
void SignalTools::Random(ssi_stream_t &stream) {

	ssi_real_t *ptr = ssi_pcast(ssi_real_t, stream.ptr);
	for (ssi_size_t i = 0; i < stream.dim * stream.num; i++) {
		*ptr++ = ssi_cast (ssi_real_t, ssi_random());
	}
}
Exemple #18
0
ssi_size_t FileBinary::writeLine (const ssi_char_t *string) {

	if (!_is_open) {
		ssi_wrn ("file not open (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	if (!_write_mode) {
		ssi_wrn ("file not in write mode (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	ssi_size_t result_1 = 0;
	ssi_size_t result_2 = 0;
	ssi_size_t len = ssi_cast (ssi_size_t, strlen (string));

	result_1 = write (&len, sizeof (ssi_size_t), 1);
	if (!result_1) 
	{
		ssi_wrn ("write() failed (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	result_2 = write (string, sizeof (ssi_char_t), len);
	if (!result_2)
	{
		ssi_wrn ("write() failed (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	return result_1 + result_2;
}
Exemple #19
0
bool Fisher::transform (ssi_stream_t &stream, ssi_stream_t &stream_t) {	

	ae_state state;

	ae_vector feature_v;
	ae_vector_init (&feature_v, 0, DT_REAL, &state, ae_true);
	AlgLibTools::Stream2vector (stream, &feature_v, &state);

	ae_vector reduced_v;
	ae_vector_init (&reduced_v, _basis->rows, DT_REAL, &state, ae_true);
	
	
	rmatrixmv (_basis->cols, _basis->rows, _basis, 0, 0, 1, &feature_v, 0, &reduced_v, 0, &state);

	ae_int_t cnt = reduced_v.cnt;
	if (_options.n > 0 && ssi_cast (ssi_size_t, reduced_v.cnt) >= _options.n) {
		reduced_v.cnt = _options.n;
	}
	AlgLibTools::Vector2stream (&reduced_v, stream_t, &state);
	reduced_v.cnt = cnt;

	ae_vector_clear (&feature_v);
	ae_vector_clear (&reduced_v);

	return true;
}
Exemple #20
0
	ssi_real_t Statistics::calculateVariance(ssi_size_t dim_idx)
	{
		running_stat_t * rs = &(_running_stats[dim_idx]);
		if (rs->n == 1){
			return 0.0f;
		}
		return ssi_cast(ssi_real_t, rs->M2 / (rs->n - 1.0));
	}
Exemple #21
0
void Thread::sleep_s (ssi_time_t seconds) {
    #if hasCXX11threads

    std::chrono::milliseconds dura((int)(seconds*1000 +0.5));
    std::this_thread::sleep_for( dura );
    #else
	::Sleep (ssi_cast (DWORD, 1000.0*seconds + 0.5));
    #endif // hasCXX11threads
}
Exemple #22
0
void Evaluation::evalSplit (Trainer *trainer, ISamples &samples, ssi_real_t split) {

	if (split <= 0 || split >= 1) {
		ssi_err ("split must be a value between 0 and 1");
	}

	_trainer = trainer;
	destroy_conf_mat ();
	init_conf_mat (samples);
	
	ssi_size_t *indices = new ssi_size_t[samples.getSize ()];
	ssi_size_t *indices_count_lab = new ssi_size_t[samples.getClassSize ()];
	ssi_size_t indices_count_all;

	indices_count_all = 0;
	for (ssi_size_t j = 0; j < samples.getClassSize (); j++) {
		indices_count_lab[j] = 0;
	}

	ssi_size_t label;
	ssi_size_t label_size;
	for (ssi_size_t j = 0; j < samples.getSize (); j++) {
		label = samples.get (j)->class_id;
		label_size = samples.getSize (label);
		if (++indices_count_lab[label] <= ssi_cast (ssi_size_t, label_size * split + 0.5f)) {
			indices[indices_count_all++] = j;			
		}
	}

	SampleList strain;
	SampleList stest;

	// split off samples
	ModelTools::SelectSampleList (samples, strain, stest, indices_count_all, indices);
	_n_total = stest.getSize ();
	_result_vec = new ssi_size_t[2*_n_total];
	_result_vec_ptr = _result_vec;

	// train with remaining samples
	_trainer->release ();	
	if (_preproc_mode) {
		_trainer->setPreprocMode (_preproc_mode, _n_streams_refs, _stream_refs);
	} else if (_fselmethod) {
		_trainer->setSelection (strain, _fselmethod, _pre_fselmethod, _n_pre_feature);
	}
	_trainer->train (strain);		

	// test with remaining samples
	eval_h (stest);

	delete[] indices;
	delete[] indices_count_lab;

}
Exemple #23
0
void EmoVoicePitch::transform (ITransformer::info info,
	ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	ssi_size_t sample_number = stream_in.num;

	short *srcptr = ssi_pcast (short, stream_in.ptr);
	mx_real_t *dstptr = ssi_pcast (mx_real_t, stream_out.ptr);

	mx_real_t *p = pitch_calc (_cfg, srcptr, sample_number);
	memcpy (dstptr, p, _cfg->nframes * sizeof (mx_real_t));

	pitch_destroy (_cfg);
	_cfg = pitch_create (ssi_cast (pitch_method_t, _options.method));
	_cfg->minimumPitch = ssi_cast (mx_real_t, _options.minfreq);
	_cfg->maximumPitch = ssi_cast (mx_real_t, _options.maxfreq);

	free (p);
}
Exemple #24
0
void MapEventSender::consume (IConsumer::info consume_info,
	ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	ssi_size_t dim = stream_in[0].dim;
	ssi_size_t num = stream_in[0].num;

	_event.time = ssi_cast (ssi_size_t, 1000 * consume_info.time + 0.5);
	_event.dur = ssi_cast (ssi_size_t, 1000 * consume_info.dur + 0.5);	
	_event.state = consume_info.status == IConsumer::COMPLETED ? SSI_ESTATE_COMPLETED : SSI_ESTATE_CONTINUED;
	
	if (_options.mean) {			
		ssi_real_t *src = ssi_pcast(ssi_real_t, stream_in[0].ptr);
		ssi_event_map_t *dst = ssi_pcast(ssi_event_map_t, _event.ptr);
		ssi_real_t *mean = new ssi_real_t[dim];
		ssi_mean(num, dim, src, mean);
		for (ssi_size_t i = 0; i < dim; i++) {
			dst++->value = mean[i];
		}		
		if (_listener) {
			_listener->update(_event);
		}
		delete[] mean;
	} else {
		ssi_real_t *src = ssi_pcast(ssi_real_t, stream_in[0].ptr);
		ssi_event_map_t *dst = ssi_pcast(ssi_event_map_t, _event.ptr);
		for (ssi_size_t i = 0; i < num; i++) {
			for (ssi_size_t j = 0; j < dim; j++) {
				dst++->value = *src++;
			}
			if (_listener) {
				_listener->update(_event);
			}
		}
	}
}
Exemple #25
0
ssi_size_t EmoVoicePitch::getSampleNumberOut (ssi_size_t sample_number_in) {

	// check if we already know the result
	if (sample_number_in == _sample_number_in) {
		return _sample_number_out;
	}

	if (!_cfg) {
		_cfg = pitch_create (ssi_cast (pitch_method_t, _options.method));
		_cfg->minimumPitch = ssi_cast (mx_real_t, _options.minfreq);
		_cfg->maximumPitch = ssi_cast (mx_real_t, _options.maxfreq);
	}

	// calculate new sample number
	pitch_method_t method = _cfg->method;
	mx_real_t minimumPitch = _cfg->minimumPitch;
	mx_real_t dt = _cfg->dt;
	int periodsPerWindow = _cfg->periodsPerWindow;
	if (method == AC_GAUSS) 
		 periodsPerWindow *= 2;
	mx_real_t x1 = (mx_real_t) 0.5/SAMPLERATE;
	mx_real_t dt_window = periodsPerWindow / minimumPitch;

	int nFrames;
	mx_real_t t1;

	int result = fitInFrame (method >= FCC_NORMAL ? 1 / minimumPitch + dt_window : dt_window, dt, &nFrames, &t1, x1, sample_number_in);
	SSI_ASSERT (result);

	if (method >= FCC_NORMAL)
		nFrames = nFrames - 1;

	_sample_number_out = nFrames;

	return nFrames;
}
Exemple #26
0
Matrix<T> *MatrixOps<T>::Rand (ssi_size_t rows, ssi_size_t cols, T maxval) {

	Matrix<T> *matrix = new Matrix<T> (rows, cols);
	ssi_size_t elems = rows * cols;
	
	T *dataptr = matrix->data;
	double number;
	for (ssi_size_t i = 0; i < elems; i++) {
		// generate random number in interval [0..1)
		number = static_cast<double>(rand ()) / (static_cast<double>(RAND_MAX) + 1.0);
		*dataptr++ = ssi_cast (T, number * maxval);	
	}

	return matrix;
}
Exemple #27
0
void Painter::fill(ITool &brush, ssi_rect_t rect) {

	if (rect.width == 1 && rect.height == 1) {

		::SetPixel(ssi_cast(HDC, _device), _area.left + rect.left, _area.top + rect.top, brush.getColor());

	} else {

		::RECT r;
		r.left = _area.left + rect.left;
		r.top = _area.top + rect.top;
		r.right = _area.left + rect.left + rect.width;
		r.bottom = _area.top + rect.top + rect.height;

		::FillRect((HDC)_device, &r, (HBRUSH)brush.getHandle());
	}
}
Exemple #28
0
void Painter::rect(ITool &pen, ITool &brush, ssi_rect_t rect) {

	if (rect.width == 1 && rect.height == 1) {

		::SetPixel(ssi_cast(HDC, _device), _area.left + rect.left, _area.top + rect.top, pen.getColor());

	} else {

		::SelectObject((HDC)_device, pen.getHandle());
		::SelectObject((HDC)_device, brush.getHandle());

		::RECT r;
		r.left = _area.left + rect.left;
		r.top = _area.top + rect.top;
		r.right = _area.left + rect.left + rect.width;
		r.bottom = _area.top + rect.top + rect.height;

		::Rectangle((HDC)_device, r.left, r.top, r.right, r.bottom);
	}
}
Exemple #29
0
ssi_size_t FileBinary::readLine (ssi_size_t num, ssi_char_t *string) {

	if (!_is_open) {
		ssi_wrn ("file not open (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	if (!_read_mode) {
		ssi_wrn ("file not in read mode (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}
	
	ssi_size_t result_1 = 0;
	ssi_size_t result_2 = 0;
	ssi_size_t len = 0;

	result_1 = read (&len, sizeof (ssi_size_t), 1);
	if (!result_1)
	{
		return 0;
	}
	if (num <= len) 
	{
		ssi_wrn ("input string too short (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	result_2 = read (string, ssi_cast (ssi_size_t, sizeof (ssi_char_t)), len);
	if (!result_2)
	{
		return 0;
	}
	string[len] = '\0';

	return result_1 + result_2;
}
Exemple #30
0
ssi_size_t FileBinary::write (const void *ptr, ssi_size_t size, ssi_size_t count) {

	if (!_is_open) {
		ssi_wrn ("file not open (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	if (!_write_mode) {
		ssi_wrn ("file not in write mode (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	int64_t old_pos = tell();

	ssi_size_t res = ssi_cast (ssi_size_t, fwrite (ptr, size, count, _file));
	if (res != count) {
		ssi_wrn ("fwrite() failed (path=%s, mode=%d, type=%d, shared=false)", _path, _mode, _type);
		return 0;
	}

	int64_t new_pos = tell();

	return ssi_size_t(new_pos - old_pos);
}