diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-08-04 09:19:47 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-08-04 09:19:47 +0200 |
commit | 05bf6d15a5361fd5518babb5c4908a1a1158404d (patch) | |
tree | 9cba0736b4280fb53db2cb6ea57505c6bfd8b3ef /src/canvastoolranges.cc | |
parent | fc29354d86e6a8b5601e92405b89a1da27406ce7 (diff) |
WIPposition
Diffstat (limited to 'src/canvastoolranges.cc')
-rw-r--r-- | src/canvastoolranges.cc | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/canvastoolranges.cc b/src/canvastoolranges.cc index 9a76163..ce9ae37 100644 --- a/src/canvastoolranges.cc +++ b/src/canvastoolranges.cc @@ -342,49 +342,72 @@ void CanvasToolRanges::doAutoCreateRanges(bool preview) .fadein = 2, .fadeout = ((to - from) / 3) * fadeout }; - +// det er her det foregaard ///////////////////////////////////////////////////////////////////////// if(positionData1 && positionData2) { //TODO: set window in ms instead of samples - int pos_window_size{1000}; // +/- 500 from detected, + int pos_window_size{256}; // +/- 500 from detected, double threshold = 0.1; // 1/3 is about right - float norm{0}; - for(int idx = range.from - pos_window_size / 2; - idx < range.from + pos_window_size / 2; +//////////////////////////////////////////////////////////// + double signal_max{0}; + for(int idx = (int)range.from - pos_window_size / 2; + idx < (int)range.from + pos_window_size / 2; + ++idx) + { + signal_max = + std::max((double)std::abs(positionData1[idx]), signal_max); + } + constexpr int noise_len{128}; +// constexpr double noise_to_threshold_scalar{200}; + double noise_floor{0}; + for(int idx = (int)range.from - pos_window_size / 2 - noise_len; + idx < (int)range.from - pos_window_size / 2; ++idx) { - norm = std::max(std::abs(positionData1[idx]), norm); + noise_floor = + std::max((double)std::abs(positionData1[idx]), noise_floor); } + threshold = noise_floor + (signal_max - noise_floor) / 10; - int pos1{range.from - pos_window_size / 2}; - for(int idx = range.from - pos_window_size / 2; - idx < range.from + pos_window_size / 2; + int pos1{(int)range.from - pos_window_size / 2}; + for(int idx = (int)range.from - pos_window_size / 2; + idx < (int)range.from + pos_window_size / 2; ++idx) { - if(std::abs(positionData1[idx]) / norm > threshold) + if(std::abs(positionData1[idx]) > threshold) { pos1 = idx; range.pos1 = pos1; break; } } - - norm = 0; +//////////////////////////////////////////////////////////// + signal_max = 0; for(int idx = range.from - pos_window_size / 2; idx < range.from + pos_window_size / 2; ++idx) { - norm = std::max(std::abs(positionData1[idx]), norm); + signal_max = + std::max((double)std::abs(positionData1[idx]), signal_max); + } + noise_floor = 0; + for(int idx = (int)range.from - pos_window_size / 2 - noise_len; + idx < (int)range.from - pos_window_size / 2; + ++idx) + { + noise_floor = + std::max((double)std::abs(positionData2[idx]), noise_floor); } + threshold = noise_floor + (signal_max - noise_floor) / 10; - int pos2{range.from + pos_window_size / 2}; - for(int idx = range.from - pos_window_size / 2; - idx < range.from + pos_window_size / 2; + int pos2{(int)range.from + pos_window_size / 2}; + for(int idx = (int)range.from - pos_window_size / 2; + idx < (int)range.from + pos_window_size / 2; ++idx) { - if(std::abs(positionData2[idx]) / norm > threshold) + if(std::abs(positionData2[idx]) > threshold) { pos2 = idx; range.pos2 = pos2; @@ -392,10 +415,12 @@ void CanvasToolRanges::doAutoCreateRanges(bool preview) } } +//////////////////////////////////////////////////////////// + constexpr double speed_of_sound{343100}; // mm/s constexpr double samplerate{48000}; // 48kHz - TODO get from audio - range.position = std::abs(pos1 - pos2) * speed_of_sound / samplerate / 2.0; + range.position = std::abs(pos1 - pos2);// * speed_of_sound / samplerate / 2.0; } ///////////////////////////////////////////////////////////////////////// |