ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

ogl_beamformer_lib_base.h (7341B)


      1 /* See LICENSE for license details. */
      2 #ifndef LIB_FN
      3   #if defined(_WIN32)
      4     #define LIB_FN __declspec(dllexport)
      5   #else
      6     #define LIB_FN
      7   #endif
      8 #endif
      9 
     10 #define BEAMFORMER_LIB_ERRORS \
     11 	X(NONE,                         0, "None") \
     12 	X(VERSION_MISMATCH,             1, "host-library version mismatch")                     \
     13 	X(INVALID_ACCESS,               2, "library in invalid state")                          \
     14 	X(PARAMETER_BLOCK_OVERFLOW,     3, "parameter block count overflow")                    \
     15 	X(PARAMETER_BLOCK_UNALLOCATED,  4, "push to unallocated parameter block")               \
     16 	X(COMPUTE_STAGE_OVERFLOW,       5, "compute stage overflow")                            \
     17 	X(INVALID_COMPUTE_STAGE,        6, "invalid compute shader stage")                      \
     18 	X(INVALID_START_SHADER,         7, "starting shader not Decode or Demodulate")          \
     19 	X(INVALID_DEMOD_DATA_KIND,      8, "data kind for demodulation not Int16 or Float")     \
     20 	X(INVALID_IMAGE_PLANE,          9, "invalid image plane")                               \
     21 	X(BUFFER_OVERFLOW,             10, "passed buffer size exceeds available space")        \
     22 	X(DATA_SIZE_MISMATCH,          11, "data size is less than specified from parameters")  \
     23 	X(WORK_QUEUE_FULL,             12, "work queue full")                                   \
     24 	X(EXPORT_SPACE_OVERFLOW,       13, "not enough space for data export")                  \
     25 	X(SHARED_MEMORY,               14, "failed to open shared memory region")               \
     26 	X(SYNC_VARIABLE,               15, "failed to acquire lock within timeout period")      \
     27 	X(INVALID_TIMEOUT,             16, "invalid timeout value")                             \
     28 	X(INVALID_FILTER_KIND,         17, "invalid filter kind")                               \
     29 	X(INVALID_FILTER_PARAM_COUNT,  18, "invalid parameters count passed for filter")        \
     30 	X(INVALID_SIMPLE_PARAMETERS,   19, "invalid simple parameters struct")
     31 
     32 #define X(type, num, string) BF_LIB_ERR_KIND_ ##type = num,
     33 typedef enum {BEAMFORMER_LIB_ERRORS} BeamformerLibErrorKind;
     34 #undef X
     35 
     36 LIB_FN uint32_t beamformer_get_api_version(void);
     37 
     38 LIB_FN BeamformerLibErrorKind beamformer_get_last_error(void);
     39 LIB_FN const char *beamformer_get_last_error_string(void);
     40 LIB_FN const char *beamformer_error_string(BeamformerLibErrorKind kind);
     41 
     42 ///////////////////////////
     43 // NOTE: Simple API
     44 /* Usage:
     45  *   - fill out a BeamformerSimpleParameters
     46  *     - filters need to be created with beamformer_create_filter, and the slot
     47  *       needs to be assigned in compute_stage_parameters
     48  *   - allocate a buffer with enough space for all Float32 or Float32Complex output points
     49  *   - pass the buffer along with the data and parameters to beamformer_beamform_data()
     50  *   - if the function was unsuccessful you can check the error with beamformer_get_last_error()
     51  *     or beamformer_get_last_error_string()
     52  */
     53 LIB_FN uint32_t beamformer_beamform_data(BeamformerSimpleParameters *bp, void *data, uint32_t data_size,
     54                                          void *out_data, int32_t timeout_ms);
     55 
     56 /* NOTE: sets timeout for all functions which may timeout but don't
     57  * take a timeout argument. The majority of such functions will not
     58  * timeout in the normal case and so passing a timeout parameter around
     59  * every where is cumbersome.
     60  *
     61  * timeout_ms: milliseconds in the range [-1, ...) (Default: 0)
     62  *
     63  * IMPORTANT: timeout of -1 will block forever */
     64 LIB_FN uint32_t beamformer_set_global_timeout(int32_t timeout_ms);
     65 
     66 ///////////////////////////
     67 // NOTE: Advanced API
     68 
     69 /* NOTE: downloads the last 32 frames worth of compute timings into output */
     70 LIB_FN uint32_t beamformer_compute_timings(BeamformerComputeStatsTable *output, int32_t timeout_ms);
     71 
     72 /* NOTE: pushes data and tries to immediately starts a compute */
     73 LIB_FN uint32_t beamformer_push_data_with_compute(void *data, uint32_t size,
     74                                                   uint32_t image_plane_tag,
     75                                                   uint32_t parameter_slot);
     76 
     77 ///////////////////////////
     78 // Parameter Configuration
     79 LIB_FN uint32_t beamformer_reserve_parameter_blocks(uint32_t count);
     80 LIB_FN uint32_t beamformer_set_pipeline_stage_parameters(uint32_t stage_index, int32_t parameter);
     81 LIB_FN uint32_t beamformer_push_pipeline(int32_t *shaders, uint32_t shader_count, BeamformerDataKind data_kind);
     82 
     83 LIB_FN uint32_t beamformer_set_pipeline_stage_parameters_at(uint32_t stage_index,
     84                                                             int32_t  parameter,
     85                                                             uint32_t parameter_slot);
     86 LIB_FN uint32_t beamformer_push_pipeline_at(int32_t *shaders, uint32_t shader_count,
     87                                             BeamformerDataKind data_kind, uint32_t parameter_slot);
     88 
     89 LIB_FN uint32_t beamformer_push_simple_parameters(BeamformerSimpleParameters *bp);
     90 LIB_FN uint32_t beamformer_push_simple_parameters_at(BeamformerSimpleParameters *bp, uint32_t parameter_slot);
     91 
     92 LIB_FN uint32_t beamformer_push_parameters(BeamformerParameters *);
     93 LIB_FN uint32_t beamformer_push_parameters_ui(BeamformerUIParameters *);
     94 LIB_FN uint32_t beamformer_push_parameters_head(BeamformerParametersHead *);
     95 
     96 LIB_FN uint32_t beamformer_push_parameters_at(BeamformerParameters *, uint32_t parameter_slot);
     97 
     98 LIB_FN uint32_t beamformer_push_channel_mapping(int16_t *mapping, uint32_t count);
     99 LIB_FN uint32_t beamformer_push_channel_mapping_at(int16_t *mapping, uint32_t count, uint32_t parameter_slot);
    100 
    101 LIB_FN uint32_t beamformer_push_sparse_elements(int16_t *elements, uint32_t count);
    102 LIB_FN uint32_t beamformer_push_sparse_elements_at(int16_t *elements, uint32_t count, uint32_t parameter_slot);
    103 
    104 LIB_FN uint32_t beamformer_push_focal_vectors(float *vectors, uint32_t count);
    105 LIB_FN uint32_t beamformer_push_focal_vectors_at(float *vectors, uint32_t count, uint32_t parameter_slot);
    106 
    107 LIB_FN uint32_t beamformer_push_transmit_receive_orientations(uint8_t *values, uint32_t count);
    108 LIB_FN uint32_t beamformer_push_transmit_receive_orientations_at(uint8_t *values, uint32_t count, uint32_t parameter_slot);
    109 
    110 ////////////////////
    111 // Filter Creation
    112 
    113 /* Kaiser Low-Pass Parameter Selection
    114  * see: "Discrete Time Signal Processing" (Oppenheim)
    115  * δ:   fractional passband ripple
    116  * ω_p: highest angular frequency of passband
    117  * ω_s: lowest  angular frequency of stopband
    118  * ω_c: cutoff angular frequency. midpoint of ω_s and ω_p
    119  * M:   length of filter
    120  *
    121  * Define: A = -20log10(δ)
    122  * β:
    123  *   β = 0.1102(A - 8.7)                             if 50 <  A
    124  *   β = 0.5842 * pow(A - 21, 0.4) + 0.07886(A − 21) if 21 <= A <= 50
    125  *   β = 0                                           if       A <  21
    126  * M:
    127  *   M = (A - 8) / (2.285 (ω_s - ω_p))
    128  */
    129 
    130 LIB_FN uint32_t beamformer_create_filter(BeamformerFilterKind kind, float *filter_parameters,
    131                                          uint32_t filter_parameter_count, float sampling_frequency,
    132                                          uint32_t complex, uint8_t filter_slot, uint8_t parameter_block);
    133 
    134 //////////////////////////
    135 // Live Imaging Controls
    136 LIB_FN int32_t  beamformer_live_parameters_get_dirty_flag(void);
    137 LIB_FN uint32_t beamformer_set_live_parameters(BeamformerLiveImagingParameters *);
    138 LIB_FN BeamformerLiveImagingParameters *beamformer_get_live_parameters(void);