30 for(x = 0; x < stream->
len/2; x++) {
32 for(d = 0; d < stream->
dims; d++) {
33 if(pos[d]<stream->
sizes[d] / 2) {
34 pos[d] += stream->
sizes[d] / 2;
36 pos[d] -= stream->
sizes[d] / 2;
43 memcpy(stream->
buf, tmp, stream->
len *
sizeof(
dsp_t));
52 for(k = 0; k < stream->
len; k++)
53 stream->
buf[k] = stream->
buf[k] - mean;
59 int len =
Min(stream->
len, inlen);
62 for(k = 0; k < len; k++) {
63 stream->
buf[k] = stream->
buf[k] - in[k];
70 int len =
Min(stream->
len, inlen);
73 for(k = 0; k < len; k++) {
74 stream->
buf[k] += in[k];
81 int len =
Min(stream->
len, inlen);
84 for(k = 0; k < len; k++) {
85 stream->
buf[k] =
Max(stream->
buf[k], in[k]);
92 int len =
Min(stream->
len, inlen);
95 for(k = 0; k < len; k++) {
96 stream->
buf[k] =
Min(stream->
buf[k], in[k]);
103 int len =
Min(stream->
len, inlen);
106 for(k = 0; k < len; k++) {
107 stream->
buf[k] = stream->
buf[k] / in[k];
114 int len =
Min(stream->
len, inlen);
117 for(k = 0; k < len; k++) {
118 stream->
buf[k] = stream->
buf[k] * in[k];
125 int len =
Min(stream->
len, inlen);
128 for(k = 0; k < len; k++) {
129 stream->
buf[k] = pow(stream->
buf[k], in[k]);
136 int len =
Min(stream->
len, inlen);
139 for(k = 0; k < len; k++) {
140 stream->
buf[k] =
Log(stream->
buf[k], in[k]);
149 for(k = 0; k < stream->
len; k++) {
150 stream->
buf[k] = val - stream->
buf[k];
159 for(k = 0; k < stream->
len; k++) {
160 stream->
buf[k] = stream->
buf[k] - val;
169 for(k = 0; k < stream->
len; k++) {
170 stream->
buf[k] += val;
179 for(k = 0; k < stream->
len; k++) {
180 stream->
buf[k] = val / stream->
buf[k];
189 for(k = 0; k < stream->
len; k++) {
190 stream->
buf[k] /= val;
199 for(k = 0; k < stream->
len; k++) {
200 stream->
buf[k] = stream->
buf[k] * val;
209 for(k = 0; k < stream->
len; k++) {
210 stream->
buf[k] = pow(stream->
buf[k], val);
219 for(k = 0; k < stream->
len; k++) {
220 stream->
buf[k] =
Log(stream->
buf[k], val);
225 static int compare(
const void* a,
const void* b)
230 if ( int_a == int_b )
return 0;
231 else if ( int_a < int_b )
return -1;
235 static void* dsp_buffer_median_th(
void* arg)
247 int cur_th = arguments->cur_th;
248 int size = arguments->size;
249 int median = arguments->median;
252 end =
Min(stream->
len, end);
255 int len = pow(size, in->
dims);
256 for(x = start; x < end; x++) {
258 for(y = 0; y < box->
len; y++) {
261 for(dim = 0; dim < stream->
dims; dim++) {
262 pos[dim] += mat[dim] - size / 2;
265 if(idx >= 0 && idx < in->len) {
266 *buf++ = in->
buf[idx];
271 qsort(sorted, len,
sizeof(
dsp_t), compare);
272 stream->
buf[x] = sorted[median*box->
len/size];
297 thread_arguments[y].cur_th = y;
298 thread_arguments[y].size = size;
299 thread_arguments[y].median = median;
300 thread_arguments[y].stream = stream;
302 for(d = 0; d < stream->
dims; d++)
305 pthread_create(&
th[y], NULL, dsp_buffer_median_th, &thread_arguments[y]);
308 pthread_join(
th[y], NULL);
316 static void* dsp_buffer_sigma_th(
void* arg)
327 int cur_th = arguments->cur_th;
328 int size = arguments->size;
331 end =
Min(stream->
len, end);
334 int len = pow(size, in->
dims);
335 for(x = start; x < end; x++) {
337 for(y = 0; y < box->
len; y++) {
340 for(dim = 0; dim < stream->
dims; dim++) {
341 pos[dim] += mat[dim] - size / 2;
344 if(idx >= 0 && idx < in->len) {
345 buf[y] = in->
buf[idx];
374 thread_arguments[y].cur_th = y;
375 thread_arguments[y].size = size;
376 thread_arguments[y].stream = stream;
378 for(d = 0; d < stream->
dims; d++)
380 pthread_create(&
th[y], NULL, dsp_buffer_sigma_th, &thread_arguments[y]);
383 pthread_join(
th[y], NULL);
395 for(k = 1; k < stream->
len; k++) {
396 stream->
buf[(int)
Max(0,
Min(stream->
len, ((deviation[k] - mindeviation) * (maxdeviation - mindeviation) + mindeviation) + k))] = tmp->
buf[k];
#define Max(a, b)
if max() is not present you can use this one
DLL_EXPORT unsigned long int dsp_max_threads(unsigned long value)
get/set the maximum number of threads allowed
#define Log(a, b)
Logarithm of a with arbitrary base b.
#define Min(a, b)
if min() is not present you can use this one
struct dsp_stream_t * parent
The parent stream.
int * sizes
Sizes of each dimension.
int dims
Number of dimensions of the buffers.
int len
The buffers length.
#define dsp_buffer_copy(in, out, len)
Fill the output buffer with the values of the elements of the input stream by casting them to the out...
void dsp_buffer_sum(dsp_stream_p stream, dsp_t *in, int inlen)
Sum elements of one stream to another's.
void dsp_buffer_log(dsp_stream_p stream, dsp_t *in, int inlen)
Logarithm elements of one stream using another's as base.
void dsp_buffer_median(dsp_stream_p in, int size, int median)
Median elements of the input stream.
void dsp_buffer_shift(dsp_stream_p stream)
Shift a stream on each dimension.
void dsp_buffer_deviate(dsp_stream_p stream, dsp_t *deviation, dsp_t mindeviation, dsp_t maxdeviation)
Deviate forward the first input stream using the second stream as indexing reference.
void dsp_buffer_div1(dsp_stream_p stream, double val)
Divide elements of the input stream to a value.
void dsp_buffer_removemean(dsp_stream_p stream)
Subtract mean from stream.
void dsp_buffer_1sub(dsp_stream_p stream, dsp_t val)
Subtract each element of the input stream a value.
void dsp_buffer_max(dsp_stream_p stream, dsp_t *in, int inlen)
Subtract elements of one stream from another's.
void dsp_buffer_sigma(dsp_stream_p in, int size)
Standard deviation of each element of the input stream within the given size.
#define dsp_buffer_set(buf, len, _val)
Fill the buffer with the passed value.
void dsp_buffer_div(dsp_stream_p stream, dsp_t *in, int inlen)
Divide elements of one stream to another's.
void dsp_buffer_sum1(dsp_stream_p stream, dsp_t val)
Sum elements of the input stream to a value.
void dsp_buffer_mul(dsp_stream_p stream, dsp_t *in, int inlen)
Multiply elements of one stream to another's.
void dsp_buffer_pow1(dsp_stream_p stream, double val)
Expose elements of the input stream to the given power.
void dsp_buffer_log1(dsp_stream_p stream, double val)
Logarithm elements of the input stream using the given base.
void dsp_buffer_pow(dsp_stream_p stream, dsp_t *in, int inlen)
Expose elements of one stream to another's.
void dsp_buffer_min(dsp_stream_p stream, dsp_t *in, int inlen)
Sum elements of one stream to another's.
void dsp_buffer_1div(dsp_stream_p stream, double val)
Divide a value to each element of the input stream.
void dsp_buffer_sub(dsp_stream_p stream, dsp_t *in, int inlen)
Subtract elements of one stream from another's.
void dsp_buffer_sub1(dsp_stream_p stream, dsp_t val)
Subtract a value from elements of the input stream.
void dsp_buffer_mul1(dsp_stream_p stream, double val)
Multiply elements of the input stream to a value.
DLL_EXPORT void dsp_stream_free(dsp_stream_p stream)
Free the DSP stream passed as argument.
DLL_EXPORT int dsp_stream_set_position(dsp_stream_p stream, int *pos)
Obtain the position the DSP stream by parsing multidimensional indexes.
DLL_EXPORT int * dsp_stream_get_position(dsp_stream_p stream, int index)
Return the multidimensional positional indexes of a DSP stream by specify a linear index.
DLL_EXPORT dsp_stream_p dsp_stream_copy(dsp_stream_p stream)
Create a copy of the DSP stream passed as argument.
DLL_EXPORT dsp_stream_p dsp_stream_new(void)
Allocate a new DSP stream type.
DLL_EXPORT void dsp_stream_add_dim(dsp_stream_p stream, int len)
Add a dimension with length len to a DSP stream.
DLL_EXPORT void dsp_stream_alloc_buffer(dsp_stream_p stream, int len)
Allocate a buffer with length len on the stream passed as argument.
DLL_EXPORT void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
#define dsp_stats_stddev(buf, len)
Standard deviation of the inut stream.
#define dsp_stats_mean(buf, len)
A mean calculator.
Contains a set of informations and data relative to a buffer and how to use it.