Line data Source code
1 : /** 2 : * \file OutCircularPointerFilter.cpp 3 : */ 4 : 5 : #include "OutCircularPointerFilter.h" 6 : 7 : #include <algorithm> 8 : #include <complex> 9 : #include <cstring> 10 : 11 : namespace ATK 12 : { 13 : template<typename DataType> 14 2 : OutCircularPointerFilter<DataType>::OutCircularPointerFilter() 15 2 : :TypedBaseFilter<DataType>(1, 0) 16 : { 17 2 : } 18 : 19 : template<typename DataType> 20 138 : void OutCircularPointerFilter<DataType>::full_setup() 21 : { 22 138 : last_checked_out_buffer = -1; 23 138 : offset = 0; 24 138 : array.fill(0); 25 138 : } 26 : 27 : template<typename DataType> 28 272 : void OutCircularPointerFilter<DataType>::process_impl(gsl::index size) const 29 : { 30 272 : auto update_size = std::min(size, static_cast<gsl::index>(array.size()) - offset); 31 272 : memcpy(reinterpret_cast<void*>(&array[offset]), reinterpret_cast<const void*>(converted_inputs[0]), static_cast<size_t>(update_size) * sizeof(DataType)); 32 272 : offset += update_size; 33 272 : if(offset == array.size()) 34 : { 35 1 : auto additional_update_size = size - update_size; 36 1 : memcpy(reinterpret_cast<void*>(array.data()), reinterpret_cast<const void*>(converted_inputs[0] + update_size), static_cast<size_t>(additional_update_size) * sizeof(DataType)); 37 1 : offset = additional_update_size; 38 : } 39 : 40 272 : current_slice = offset / slice_size; // Current slice we are filing 41 272 : } 42 : 43 : template<typename DataType> 44 272 : auto OutCircularPointerFilter<DataType>::get_last_slice(bool& process) -> const SliceBuffer& 45 : { 46 272 : process = false; 47 272 : if(last_checked_out_buffer != current_slice) 48 : { 49 205 : process = true; 50 205 : auto first_index = static_cast<int>((current_slice - nb_slices + 2) * slice_size); 51 205 : if(first_index < 0) 52 : { 53 203 : first_index += nb_slices * slice_size; 54 : } 55 205 : auto last_index = std::min(first_index + out_slice_size, nb_slices * slice_size) - first_index; 56 11367600 : for(gsl::index i = 0; i < last_index; ++i) 57 : { 58 11367400 : last_slice[i] = array[first_index + i]; 59 : } 60 205 : auto remaining_index = out_slice_size - last_index; 61 2067660 : for(gsl::index i = 0; i < remaining_index; ++i) 62 : { 63 2067460 : last_slice[i + last_index] = array[i]; 64 : } 65 : 66 205 : last_checked_out_buffer = current_slice; 67 : } 68 272 : return last_slice; 69 : } 70 : 71 : #if ATK_ENABLE_INSTANTIATION 72 : template class OutCircularPointerFilter<std::int16_t>; 73 : template class OutCircularPointerFilter<std::int32_t>; 74 : template class OutCircularPointerFilter<std::int64_t>; 75 : #endif 76 : template class OutCircularPointerFilter<float>; 77 : #if ATK_ENABLE_INSTANTIATION 78 : template class OutCircularPointerFilter<double>; 79 : template class OutCircularPointerFilter<std::complex<float>>; 80 : template class OutCircularPointerFilter<std::complex<double>>; 81 : #endif 82 : }