Instrument Neutral Distributed Interface INDI  1.9.5
convolution.c
Go to the documentation of this file.
1 /*
2  * libDSPAU - a digital signal processing library for astronoms usage
3  * Copyright (C) 2017 Ilia Platone <info@iliaplatone.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "dsp.h"
20 
21 static void* dsp_convolution_convolution_th(void* arg)
22 {
23  dsp_stream_p matrix = (dsp_stream_p)arg;
24  dsp_stream_p field = (dsp_stream_p)matrix->parent;
25  dsp_stream_p stream = (dsp_stream_p)field->parent;
26  int y = matrix->ROI[0].start;
27  int* pos = dsp_stream_get_position(matrix, y);
28  int x, d;
29  for(x = 0; x < stream->len; x++)
30  {
31  int* pos1 = dsp_stream_get_position(field, x);
32  for(d = 0; d < field->dims; d++)
33  pos1[d] += pos[d];
34  int z = dsp_stream_set_position(field, pos1);
35  if(z >= 0 && z < field->len && x >= 0 && x < stream->len && y >= 0)
36  stream->buf[x] += field->buf[z] * matrix->buf[y];
37  free(pos1);
38  }
39  free(pos);
40  dsp_stream_free_buffer(matrix);
41  dsp_stream_free(matrix);
42  return NULL;
43 }
44 
46  dsp_stream_p field = dsp_stream_copy(stream);
47  dsp_stream_p tmp = dsp_stream_copy(stream);
48  dsp_buffer_set(tmp->buf, tmp->len, 0);
49  field->parent = tmp;
50  int n_threads = object->len;
51  pthread_t *th = malloc(sizeof(pthread_t)*n_threads);
52  int y, xy;
53  for(y = -n_threads; y < n_threads; y+=DSP_MAX_THREADS)
54  {
55  for(xy = 0; xy < DSP_MAX_THREADS; xy++) {
56  dsp_stream_p matrix = dsp_stream_copy(object);
57  matrix->parent = field;
58  matrix->ROI[0].start = xy;
59  matrix->ROI[0].len = 0;
60  pthread_create(&th[xy], NULL, dsp_convolution_convolution_th, (void*)matrix);
61  }
62  for(xy = 0; xy < DSP_MAX_THREADS; xy++)
63  pthread_join(th[xy], NULL);
64  }
66  dsp_stream_free(field);
67  return tmp;
68 }
th
std::thread th
Definition: activefocuser_utils.cpp:88
dsp_stream_p
struct dsp_stream_t * dsp_stream_p
dsp.h
dsp_stream_free
DLL_EXPORT void dsp_stream_free(dsp_stream_p stream)
Free the DSP stream passed as argument.
Definition: stream.c:76
dsp_stream_t
Contains a set of informations and data relative to a buffer and how to use it.
Definition: dsp.h:175
dsp_convolution_convolution
dsp_stream_p dsp_convolution_convolution(dsp_stream_p stream, dsp_stream_p object)
A cross-convolution processor.
Definition: convolution.c:45
dsp_stream_copy
DLL_EXPORT dsp_stream_p dsp_stream_copy(dsp_stream_p stream)
Create a copy of the DSP stream passed as argument.
Definition: stream.c:89
dsp_buffer_set
#define dsp_buffer_set(buf, len, _val)
Place the given value on each element of the buffer.
Definition: dsp.h:579
dsp_region_t::start
int start
Starting point within the buffer.
Definition: dsp.h:147
dsp_stream_set_position
DLL_EXPORT int dsp_stream_set_position(dsp_stream_p stream, int *pos)
Obtain the position the DSP stream by parsing multidimensional indexes.
Definition: stream.c:202
dsp_stream_t::len
int len
The buffers length.
Definition: dsp.h:178
dsp_stream_free_buffer
DLL_EXPORT void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
Definition: stream.c:41
dsp_stream_get_position
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.
Definition: stream.c:188
dsp_stream_t::dims
int dims
Number of dimensions of the buffers.
Definition: dsp.h:180
dsp_stream_t::ROI
dsp_region * ROI
Regions of interest for each dimension.
Definition: dsp.h:218
dsp_region_t::len
int len
Length of the region.
Definition: dsp.h:149
DSP_MAX_THREADS
#define DSP_MAX_THREADS
Definition: dsp.h:61
dsp_stream_t::parent
struct dsp_stream_t * parent
The stream this one is child of.
Definition: dsp.h:188
dsp_stream_t::buf
dsp_t * buf
buffer
Definition: dsp.h:184