21 static int dsp_debug = 0;
22 static char* dsp_app_name = NULL;
24 static int DSP_MAX_THREADS = 1;
26 static unsigned long MAX_THREADS = 1;
28 static FILE *out = NULL;
29 static FILE *err = NULL;
35 DSP_MAX_THREADS = value;
53 fprintf(out,
"%s", str);
55 fprintf(err,
"%s", str);
80 if(stream->
buf != NULL) {
85 if(stream->
dft.
buf != NULL) {
86 stream->
dft.
buf = (
double*)realloc(stream->
dft.
buf,
sizeof(
double) * len * 2);
88 stream->
dft.
buf = (
double*)malloc(
sizeof(
double) * len * 2);
97 if(stream->
phase != NULL)
114 if(stream->
buf != NULL)
116 if(stream->
dft.
buf != NULL)
129 stream->
dft.
buf = (
double*)malloc(
sizeof(
dsp_t) * 0);
131 stream->
phase = NULL;
132 stream->
sizes = (
int*)malloc(
sizeof(
int) * 1);
133 stream->
pixel_sizes = (
double*)malloc(
sizeof(
double) * 1);
137 stream->
target = (
double*)malloc(
sizeof(
double) * 3);
167 if(stream->
sizes != NULL)
173 if(stream->
ROI != NULL)
177 if(stream->
target != NULL)
179 if(stream->
stars != NULL)
196 for(i = 0; i < stream->
dims; i++)
212 memcpy(dest->
target, stream->
target,
sizeof(
double) * 3);
215 if(dest->
buf != NULL)
233 stream->
sizes = (
int*)realloc(stream->
sizes,
sizeof(
int) * (stream->
dims + 1));
242 if(stream->
phase != NULL)
255 if(dim < stream->dims) {
256 stream->
sizes[dim] = size;
258 for(d = 0; d < stream->
dims; d++)
262 if(stream->
phase != NULL)
274 int* sizes = (
int*)malloc(
sizeof(
int) * stream->
dims);
275 int dims = stream->
dims;
276 memcpy(sizes, stream->
sizes,
sizeof(
int) * stream->
dims);
280 for(i = 0; i < dims; i++) {
287 if(stream->
phase != NULL)
317 for(i = 0; i < child_count; i++) {
355 for(i = 0; i < stars_count; i++) {
378 for (s = 0; s < triangle.
dims; s++) {
379 if(s < stream->dims - 1) {
407 for(i = 0; i < triangles_count; i++) {
424 int* pos = (
int*)malloc(
sizeof(
int) * stream->
dims);
425 for (dim = 0; dim < stream->
dims; dim++) {
427 y %= stream->
sizes[dim];
428 m *= stream->
sizes[dim];
444 for (dim = 0; dim < stream->
dims; dim++) {
445 index += m * pos[dim];
446 m *= stream->
sizes[dim];
451 static void* dsp_stream_align_th(
void* arg)
459 int cur_th = arguments->cur_th;
462 end =
Min(stream->
len, end);
464 for(y = start; y < end; y++)
468 for (dim = 1; dim < stream->
dims; dim++) {
474 double x = pos[dim-1];
476 double h = pow(pow(x, 2)+pow(y, 2), 0.5);
477 double r2 = acos(x/h);
480 pos[dim] = sin(r2-r1)*h;
481 pos[dim-1] = cos(r2-r1)*h;
489 if(x >= 0 && x < in->len)
490 stream->
buf[y] = in->
buf[x];
507 thread_arguments[y].cur_th = y;
508 thread_arguments[y].stream = stream;
509 pthread_create(&
th[y], NULL, dsp_stream_align_th, &thread_arguments[y]);
512 pthread_join(
th[y], NULL);
524 static void* dsp_stream_crop_th(
void* arg)
532 int cur_th = arguments->cur_th;
535 end =
Min(stream->
len, end);
537 for(y = start; y < end; y++)
542 for (dim = 0; dim < stream->
dims; dim++) {
544 if(pos[dim] < in->
ROI[dim].
start || pos[dim] > in->
ROI[dim].
start + in->
ROI[dim].
len || pos[dim] < 0 || pos[dim] >= in->
sizes[dim])
549 stream->
buf[y] = in->
buf[x];
570 thread_arguments[y].cur_th = y;
571 thread_arguments[y].stream = stream;
572 pthread_create(&
th[y], NULL, dsp_stream_crop_th, &thread_arguments[y]);
575 pthread_join(
th[y], NULL);
585 int* offset = (
int*)malloc(
sizeof(
int)*stream->
dims);
592 int len = stream->
len-z-k;
596 memcpy(data, buf,
sizeof(
dsp_t)*len);
606 static void* dsp_stream_scale_th(
void* arg)
614 int cur_th = arguments->cur_th;
617 end =
Min(stream->
len, end);
619 for(y = start; y < end; y++)
623 for(d = 0; d < stream->
dims; d++) {
629 factor = sqrt(factor);
631 if(x >= 0 && x < in->len)
632 stream->
buf[y] += in->
buf[x]/(factor*stream->
dims);
650 thread_arguments[y].cur_th = y;
651 thread_arguments[y].stream = stream;
652 pthread_create(&
th[y], NULL, dsp_stream_scale_th, &thread_arguments[y]);
655 pthread_join(
th[y], NULL);
662 static void* dsp_stream_rotate_th(
void* arg)
670 int cur_th = arguments->cur_th;
673 end =
Min(stream->
len, end);
675 for(y = start; y < end; y++)
679 for (dim = 1; dim < stream->
dims; dim++) {
683 double x = pos[dim-1];
685 pos[dim] = x*-sin(r);
686 pos[dim-1] = x*cos(r);
687 pos[dim] += y*cos(r);
688 pos[dim-1] += y*sin(r);
694 if(x >= 0 && x < in->len)
695 stream->
buf[y] = in->
buf[x];
712 thread_arguments[y].cur_th = y;
713 thread_arguments[y].stream = stream;
714 pthread_create(&
th[y], NULL, dsp_stream_rotate_th, &thread_arguments[y]);
717 pthread_join(
th[y], NULL);
int dsp_get_debug_level()
get the debug level
void dsp_set_stderr(FILE *f)
set the error log streeam
#define Max(a, b)
if max() is not present you can use this one
unsigned long int dsp_max_threads(unsigned long value)
get/set the maximum number of threads allowed
void dsp_set_debug_level(int value)
set the debug level
#define Min(a, b)
if min() is not present you can use this one
void dsp_set_stdout(FILE *f)
set the output log streeam
void dsp_print(int x, char *str)
log a message to the error or output streams
char * dsp_get_app_name()
get the application name
void dsp_set_app_name(char *name)
set the application name
struct dsp_stream_t * dsp_stream_p
struct dsp_stream_t * phase
Fourier transform phase.
double samplerate
Sample rate of the buffers.
double * pixel_sizes
Sensor size.
dsp_point center
The center of the star.
int frame_number
Frame number (if part of a series)
int triangles_count
Triangles of stars or objects quantity.
int dims
Dimensions limit.
double * factor
Scaling factor.
double wavelength
Wavelength observed, used as reference with signal generators or filters.
double focal_ratio
Focal ratio.
int start
Starting point within the buffer.
double * center
Center of rotation coordinates.
struct dsp_stream_t * parent
The parent stream.
int * sizes
Sizes of each dimension.
double * location
Center of the point.
dsp_complex dft
Fourier transform.
double * radians
Rotational offset.
double index
The index of the triangle.
dsp_star * stars
Stars or objects identified into the buffers - TODO.
struct timespec starttimeutc
Time at the beginning of the stream.
dsp_star * stars
The stars of the triangle.
double * sizes
The sizes of the triangle.
double * buf
Linear double array containing complex numbers.
double * target
Target coordinates.
int stars_count
Stars or objects quantity.
struct dsp_stream_t * magnitude
Fourier transform magnitude.
double diameter
The diameter of the star.
int dims
The dimensions of the triangle.
double * theta
The inclination of the triangle.
dsp_align_info align_info
Align/scale/rotation settings.
dsp_triangle * triangles
Triangles of stars or objects.
char name[150]
The name of the star.
int dims
Number of dimensions of the buffers.
dsp_location * location
Location coordinates pointer, can be extended to the main buffer size as location companion.
struct dsp_stream_t ** children
Children streams.
int len
Length of the region.
int dims
Dimensions limit of the point.
int child_count
Children streams count.
int is_copy
Increments by one on the copied stream.
double * ratios
The sizes of the triangle.
dsp_region * ROI
Regions of interest for each dimension.
int len
The buffers length.
double * offset
Translation offset.
#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...
#define dsp_buffer_set(buf, len, _val)
Fill the buffer with the passed value.
void dsp_stream_free(dsp_stream_p stream)
dsp_stream_free
void dsp_stream_scale(dsp_stream_p in)
Scale a stream.
void dsp_stream_set_dim(dsp_stream_p stream, int dim, int size)
dsp_stream_set_dim
void dsp_stream_rotate(dsp_stream_p in)
Rotate a stream around an axis and offset.
void dsp_stream_del_triangle(dsp_stream_p stream, int index)
dsp_stream_del_triangle
int dsp_stream_set_position(dsp_stream_p stream, int *pos)
dsp_stream_set_position
int * dsp_stream_get_position(dsp_stream_p stream, int index)
dsp_stream_get_position
dsp_stream_p dsp_stream_copy(dsp_stream_p stream)
dsp_stream_copy
void dsp_stream_add_triangle(dsp_stream_p stream, dsp_triangle triangle)
dsp_stream_add_triangle
void dsp_stream_add_child(dsp_stream_p stream, dsp_stream_p child)
dsp_stream_add_child
void dsp_stream_del_dim(dsp_stream_p stream, int index)
dsp_stream_del_dim
dsp_t * dsp_stream_get_buffer(dsp_stream_p stream)
Return the buffer of the stream passed as argument.
void dsp_stream_set_buffer(dsp_stream_p stream, void *buffer, int len)
Set the buffer of the stream passed as argument to a specific memory location.
void dsp_stream_del_child(dsp_stream_p stream, int index)
dsp_stream_del_child
dsp_stream_p dsp_stream_new()
dsp_stream_new
void dsp_stream_add_dim(dsp_stream_p stream, int size)
dsp_stream_add_dim
void dsp_stream_alloc_buffer(dsp_stream_p stream, int len)
Allocate a buffer with length len on the stream passed as argument.
void dsp_stream_crop(dsp_stream_p in)
Crop the buffers of the stream passed as argument by reading the ROI field.
void dsp_stream_translate(dsp_stream_p in)
Translate a stream.
void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
void dsp_stream_del_star(dsp_stream_p stream, int index)
dsp_stream_del_star
void dsp_stream_add_star(dsp_stream_p stream, dsp_star star)
dsp_stream_add_star
void dsp_stream_align(dsp_stream_p in)
Perform scale, translate and rotate transformations in-place.
std::vector< uint8_t > buffer
Alignment informations needed.
Delimits a region in a single dimension of a buffer.
A star or object contained into a buffer.
Contains a set of informations and data relative to a buffer and how to use it.
A star or object contained into a buffer.