21static int dsp_debug = 0;
22static char* dsp_app_name = NULL;
24static int DSP_MAX_THREADS = 1;
26static unsigned long MAX_THREADS = 1;
28static FILE *out = NULL;
29static 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)
120 if(stream->
phase != NULL)
135 stream->
phase = NULL;
136 stream->
sizes = (
int*)malloc(
sizeof(
int) * 1);
137 stream->
pixel_sizes = (
double*)malloc(
sizeof(
double) * 1);
141 stream->
target = (
double*)malloc(
sizeof(
double) * 3);
171 if(stream->
sizes != NULL)
177 if(stream->
ROI != NULL)
181 if(stream->
target != NULL)
183 if(stream->
stars != NULL)
189 if(stream->
phase != NULL)
204 for(i = 0; i < stream->
dims; i++)
220 memcpy(dest->
target, stream->
target,
sizeof(
double) * 3);
223 if(dest->
buf != NULL)
241 stream->
sizes = (
int*)realloc(stream->
sizes,
sizeof(
int) * (stream->
dims + 1));
250 if(stream->
phase != NULL)
263 if(dim < stream->dims) {
264 stream->
sizes[dim] = size;
266 for(d = 0; d < stream->
dims; d++)
270 if(stream->
phase != NULL)
282 int* sizes = (
int*)malloc(
sizeof(
int) * stream->
dims);
283 int dims = stream->
dims;
284 memcpy(sizes, stream->
sizes,
sizeof(
int) * stream->
dims);
288 for(i = 0; i < dims; i++) {
295 if(stream->
phase != NULL)
325 for(i = 0; i < child_count; i++) {
366 for(i = 0; i < stars_count; i++) {
391 for (s = 0; s < triangle.
dims; s++) {
392 if(s < stream->dims - 1) {
407 for(s = 0; s < num_baselines; s++) {
434 if(index < stream->triangles_count) {
455 int* pos = (
int*)malloc(
sizeof(
int) * stream->
dims);
456 for (dim = 0; dim < stream->
dims; dim++) {
458 y %= stream->
sizes[dim];
459 m *= stream->
sizes[dim];
475 for (dim = 0; dim < stream->
dims; dim++) {
476 index += m * pos[dim];
477 m *= stream->
sizes[dim];
482static void* dsp_stream_align_th(
void* arg)
490 int cur_th = arguments->cur_th;
493 end =
Min(stream->
len, end);
495 for(y = start; y < end; y++)
499 for (dim = 1; dim < stream->
dims; dim++) {
505 double x = pos[dim-1];
507 double h = pow(pow(x, 2)+pow(y, 2), 0.5);
508 double r2 = acos(x/h);
511 pos[dim] = sin(r2-r1)*h;
512 pos[dim-1] = cos(r2-r1)*h;
520 if(x >= 0 && x < in->len)
521 stream->
buf[y] = in->
buf[x];
538 thread_arguments[y].cur_th = y;
539 thread_arguments[y].stream = stream;
540 pthread_create(&
th[y], NULL, dsp_stream_align_th, &thread_arguments[y]);
543 pthread_join(
th[y], NULL);
555static void* dsp_stream_crop_th(
void* arg)
563 int cur_th = arguments->cur_th;
566 end =
Min(stream->
len, end);
568 for(y = start; y < end; y++)
573 for (dim = 0; dim < stream->
dims; dim++) {
575 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])
580 stream->
buf[y] = in->
buf[x];
601 thread_arguments[y].cur_th = y;
602 thread_arguments[y].stream = stream;
603 pthread_create(&
th[y], NULL, dsp_stream_crop_th, &thread_arguments[y]);
606 pthread_join(
th[y], NULL);
616 int* offset = (
int*)malloc(
sizeof(
int)*stream->
dims);
623 int len = stream->
len-z-k;
627 memcpy(data, buf,
sizeof(
dsp_t)*len);
637static void* dsp_stream_scale_th(
void* arg)
645 int cur_th = arguments->cur_th;
648 end =
Min(stream->
len, end);
650 for(y = start; y < end; y++)
654 for(d = 0; d < stream->
dims; d++) {
660 factor = sqrt(factor);
662 if(x >= 0 && x < in->len)
663 stream->
buf[y] += in->
buf[x]/(factor*stream->
dims);
681 thread_arguments[y].cur_th = y;
682 thread_arguments[y].stream = stream;
683 pthread_create(&
th[y], NULL, dsp_stream_scale_th, &thread_arguments[y]);
686 pthread_join(
th[y], NULL);
693static void* dsp_stream_rotate_th(
void* arg)
701 int cur_th = arguments->cur_th;
704 end =
Min(stream->
len, end);
706 for(y = start; y < end; y++)
710 for (dim = 1; dim < stream->
dims; dim++) {
714 double x = pos[dim-1];
716 pos[dim] = x*-sin(r);
717 pos[dim-1] = x*cos(r);
718 pos[dim] += y*cos(r);
719 pos[dim-1] += y*sin(r);
725 if(x >= 0 && x < in->len)
726 stream->
buf[y] = in->
buf[x];
743 thread_arguments[y].cur_th = y;
744 thread_arguments[y].stream = stream;
745 pthread_create(&
th[y], NULL, dsp_stream_rotate_th, &thread_arguments[y]);
748 pthread_join(
th[y], NULL);
755static double stack_delegate_multiply(
double x,
double y)
760static double stack_delegate_sum(
double x,
double y)
762 return (x + y) / 2.0;
765static double stack_delegate_subtraction(
double x,
double y)
767 return fmax(0.0, x - y);
770static void* dsp_stream_stack_th(
void* arg)
775 double(*delegate)(double, double);
777 double(*delegate)(double, double) = arguments->delegate;
780 int cur_th = arguments->cur_th;
783 end =
Min(stream->
len, end);
785 for(y = start; y < end; y++)
790 if(x >= 0 && x < in->len)
791 stream->
buf[y] = delegate(stream->
buf[y], in->
buf[x]);
805 double(*delegate)(double, double);
808 thread_arguments[y].cur_th = y;
809 thread_arguments[y].stream = stream;
810 thread_arguments[y].delegate = stack_delegate_sum;
811 pthread_create(&
th[y], NULL, dsp_stream_stack_th, &thread_arguments[y]);
814 pthread_join(
th[y], NULL);
830 double(*delegate)(double, double);
833 thread_arguments[y].cur_th = y;
834 thread_arguments[y].stream = stream;
835 thread_arguments[y].delegate = stack_delegate_multiply;
836 pthread_create(&
th[y], NULL, dsp_stream_stack_th, &thread_arguments[y]);
839 pthread_join(
th[y], NULL);
855 double(*delegate)(double, double);
858 thread_arguments[y].cur_th = y;
859 thread_arguments[y].stream = stream;
860 thread_arguments[y].delegate = stack_delegate_subtraction;
861 pthread_create(&
th[y], NULL, dsp_stream_stack_th, &thread_arguments[y]);
864 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
char * dsp_get_app_name()
get the application name
#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
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.
int stars_count
The number of stars of the triangle.
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 theta
The deviation of the star.
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.
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.
char name[DSP_NAME_SIZE]
The name of the star.
int dims
Dimensions limit of the point.
int child_count
Children streams count.
double peak
The peak of the star.
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 flux
The flux of the star.
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_subtract(dsp_stream_p in, dsp_stream_p str)
Subtract a stream to another.
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
void dsp_stream_sum(dsp_stream_p in, dsp_stream_p str)
Sum a stream with another.
int dsp_stream_set_position(dsp_stream_p stream, int *pos)
dsp_stream_set_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_multiply(dsp_stream_p in, dsp_stream_p str)
Multiply a stream with another.
int * dsp_stream_get_position(dsp_stream_p stream, int index)
dsp_stream_get_position
void dsp_stream_del_dim(dsp_stream_p stream, int index)
dsp_stream_del_dim
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.
dsp_t * dsp_stream_get_buffer(dsp_stream_p stream)
Return the buffer of the stream passed as argument.
Alignment information needed.
Delimits a region in a single dimension of a buffer.
A star or object contained into a buffer.
Contains a set of information and data relative to a buffer and how to use it.
A star or object contained into a buffer.