diff options
| author | Joshua Bakita <bakitajoshua@gmail.com> | 2019-10-07 19:13:39 -0400 |
|---|---|---|
| committer | Joshua Bakita <bakitajoshua@gmail.com> | 2019-10-07 19:13:39 -0400 |
| commit | 386b7d3366f1359a265da207a9cafa3edf553b64 (patch) | |
| tree | c76120c2c138faed822e4ae386be6ef22a738a78 /all_pairs/source/audiobeam/audiobeam.c | |
| parent | 54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff) | |
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'all_pairs/source/audiobeam/audiobeam.c')
| -rw-r--r-- | all_pairs/source/audiobeam/audiobeam.c | 594 |
1 files changed, 594 insertions, 0 deletions
diff --git a/all_pairs/source/audiobeam/audiobeam.c b/all_pairs/source/audiobeam/audiobeam.c new file mode 100644 index 0000000..ed5d656 --- /dev/null +++ b/all_pairs/source/audiobeam/audiobeam.c | |||
| @@ -0,0 +1,594 @@ | |||
| 1 | /* | ||
| 2 | |||
| 3 | This program is part of the TACLeBench benchmark suite. | ||
| 4 | Version V 2.0 | ||
| 5 | |||
| 6 | Name: audiobeam | ||
| 7 | |||
| 8 | Author: Eugene Weinstein | ||
| 9 | |||
| 10 | Function: Audio beam former | ||
| 11 | |||
| 12 | Source: StreamIt | ||
| 13 | http://groups.csail.mit.edu/cag/streamit/ | ||
| 14 | |||
| 15 | Changes: no functional changes | ||
| 16 | |||
| 17 | License: see license.txt | ||
| 18 | |||
| 19 | */ | ||
| 20 | |||
| 21 | |||
| 22 | /* | ||
| 23 | Include section | ||
| 24 | */ | ||
| 25 | |||
| 26 | #include "../extra.h" | ||
| 27 | #include "audiobeamlibm.h" | ||
| 28 | #include "audiobeamlibmalloc.h" | ||
| 29 | #include "audiobeam.h" | ||
| 30 | |||
| 31 | /* | ||
| 32 | Forward declaration of functions | ||
| 33 | */ | ||
| 34 | |||
| 35 | void audiobeam_init(); | ||
| 36 | int audiobeam_return(); | ||
| 37 | void audiobeam_main( void ); | ||
| 38 | //int main( void ); | ||
| 39 | void audiobeam_preprocess_delays( struct audiobeam_PreprocessedDelays | ||
| 40 | prep_delays[], float *delays ); | ||
| 41 | float *audiobeam_parse_line( float *float_arr, int num_mic ); | ||
| 42 | long int audiobeam_find_max_in_arr( float *arr, int size ); | ||
| 43 | long int audiobeam_find_min_in_arr( float *arr, int size ); | ||
| 44 | int audiobeam_wrapped_inc_offset( int i, int offset, int max_i ); | ||
| 45 | int audiobeam_wrapped_dec_offset( int i, int offset, int max_i ); | ||
| 46 | int audiobeam_wrapped_inc( int i, int max_i ); | ||
| 47 | int audiobeam_wrapped_dec( int i, int max_i ); | ||
| 48 | struct audiobeam_DataQueue *audiobeam_init_data_queue( int max_delay, | ||
| 49 | int num_mic ); | ||
| 50 | struct audiobeam_Delays *audiobeam_init_delays ( int num_angles, int num_mic ); | ||
| 51 | void audiobeam_calc_distances( float *source_location, | ||
| 52 | float audiobeam_mic_locations[15][3], | ||
| 53 | float *distances, | ||
| 54 | int num_mic ); | ||
| 55 | void audiobeam_calc_delays( float *distances, float *delays, int sound_speed, | ||
| 56 | int sampling_rate, int num_mic ); | ||
| 57 | void audiobeam_adjust_delays( float *delays, int num_mic ); | ||
| 58 | float *audiobeam_calc_weights_lr ( int num_mic ); | ||
| 59 | float *audiobeam_calc_weights_left_only ( int num_mic ); | ||
| 60 | float audiobeam_calculate_energy( float *samples, int num_samples ); | ||
| 61 | float audiobeam_do_beamforming( struct audiobeam_PreprocessedDelays | ||
| 62 | preprocessed_delays[], | ||
| 63 | float **sample_queue, | ||
| 64 | int queue_head, | ||
| 65 | long int max_delay, | ||
| 66 | int num_mic, | ||
| 67 | float *weights ); | ||
| 68 | int audiobeam_process_signal( struct audiobeam_Delays *delays, int num_mic, | ||
| 69 | float sampling_rate, float **beamform_results, | ||
| 70 | struct audiobeam_DataQueue *queue, | ||
| 71 | int num_beams, int window, float *weights ); | ||
| 72 | int audiobeam_calc_beamforming_result( struct audiobeam_Delays *delays, | ||
| 73 | float **beamform_results, | ||
| 74 | float *energies, | ||
| 75 | struct audiobeam_DataQueue *queue, | ||
| 76 | int num_beams, int window, | ||
| 77 | int hamming ); | ||
| 78 | void audiobeam_calc_single_pos( float source_location[3], | ||
| 79 | float audiobeam_mic_locations[15][3], | ||
| 80 | int hamming ); | ||
| 81 | |||
| 82 | |||
| 83 | /* | ||
| 84 | Declaration of global variables | ||
| 85 | */ | ||
| 86 | |||
| 87 | extern float audiobeam_input[5760]; | ||
| 88 | extern float audiobeam_mic_locations[15][3]; | ||
| 89 | extern float audiobeam_source_location[3]; | ||
| 90 | extern float audiobeam_origin_location[3]; | ||
| 91 | int audiobeam_input_pos; | ||
| 92 | int audiobeam_checksum; | ||
| 93 | |||
| 94 | |||
| 95 | /* | ||
| 96 | Initialization- and return-value-related functions | ||
| 97 | */ | ||
| 98 | |||
| 99 | void audiobeam_init() | ||
| 100 | { | ||
| 101 | audiobeam_input_pos = 0; | ||
| 102 | audiobeam_checksum = 0; | ||
| 103 | |||
| 104 | unsigned int i; | ||
| 105 | unsigned char *p; | ||
| 106 | volatile char bitmask = 0; | ||
| 107 | |||
| 108 | /* | ||
| 109 | Apply volatile XOR-bitmask to entire input array. | ||
| 110 | */ | ||
| 111 | p = ( unsigned char * ) &audiobeam_input[ 0 ]; | ||
| 112 | _Pragma( "loopbound min 23040 max 23040" ) | ||
| 113 | for ( i = 0; i < sizeof( audiobeam_input ); ++i, ++p ) | ||
| 114 | *p ^= bitmask; | ||
| 115 | |||
| 116 | p = ( unsigned char * ) &audiobeam_mic_locations[ 0 ]; | ||
| 117 | _Pragma( "loopbound min 180 max 180" ) | ||
| 118 | for ( i = 0; i < sizeof( audiobeam_mic_locations ); ++i, ++p ) | ||
| 119 | *p ^= bitmask; | ||
| 120 | |||
| 121 | p = ( unsigned char * ) &audiobeam_source_location[ 0 ]; | ||
| 122 | _Pragma( "loopbound min 12 max 12" ) | ||
| 123 | for ( i = 0; i < sizeof( audiobeam_source_location ); ++i, ++p ) | ||
| 124 | *p ^= bitmask; | ||
| 125 | |||
| 126 | p = ( unsigned char * ) &audiobeam_origin_location[ 0 ]; | ||
| 127 | _Pragma( "loopbound min 12 max 12" ) | ||
| 128 | for ( i = 0; i < sizeof( audiobeam_origin_location ); ++i, ++p ) | ||
| 129 | *p ^= bitmask; | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
| 133 | int audiobeam_return() | ||
| 134 | { | ||
| 135 | return ( audiobeam_checksum +1!= 0 ); | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | /* | ||
| 140 | Algorithm core functions | ||
| 141 | */ | ||
| 142 | |||
| 143 | void audiobeam_preprocess_delays( struct audiobeam_PreprocessedDelays | ||
| 144 | prep_delays[], float *delays ) | ||
| 145 | { | ||
| 146 | int i; | ||
| 147 | |||
| 148 | _Pragma( "loopbound min 15 max 15" ) | ||
| 149 | for ( i = 0; i < 15; i++ ) { | ||
| 150 | prep_delays[i].delay = delays[i]; | ||
| 151 | prep_delays[i].high = ( int ) audiobeam_ceil( delays[i] ); | ||
| 152 | prep_delays[i].low = ( int ) audiobeam_floor( delays[i] ); | ||
| 153 | prep_delays[i].offset = delays[i] - prep_delays[i].low; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | |||
| 158 | float *audiobeam_parse_line( float *float_arr, int num_mic ) | ||
| 159 | { | ||
| 160 | int i; | ||
| 161 | |||
| 162 | _Pragma( "loopbound min 15 max 15" ) | ||
| 163 | for ( i = 0; i < num_mic; i++ ) | ||
| 164 | float_arr[i] = audiobeam_input[audiobeam_input_pos++]; | ||
| 165 | |||
| 166 | return float_arr; | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | long int audiobeam_find_max_in_arr( float *arr, int size ) | ||
| 171 | { | ||
| 172 | int i; | ||
| 173 | float max = 0; | ||
| 174 | |||
| 175 | _Pragma( "loopbound min 15 max 15" ) | ||
| 176 | for ( i = 0; i < size; i++ ) { | ||
| 177 | if ( arr[i] > max ) | ||
| 178 | max = arr[i]; | ||
| 179 | } | ||
| 180 | |||
| 181 | return audiobeam_ceil( max ); | ||
| 182 | } | ||
| 183 | |||
| 184 | |||
| 185 | long int audiobeam_find_min_in_arr( float *arr, int size ) | ||
| 186 | { | ||
| 187 | int i; | ||
| 188 | float min = arr[0]; | ||
| 189 | |||
| 190 | _Pragma( "loopbound min 15 max 15" ) | ||
| 191 | for ( i = 0; i < size; i++ ) { | ||
| 192 | if ( arr[i] < min ) | ||
| 193 | min = arr[i]; | ||
| 194 | } | ||
| 195 | |||
