mixxx icon indicating copy to clipboard operation
mixxx copied to clipboard

RingDelayBuffer: ring buffer for delay handling

Open davidchocholaty opened this issue 2 years ago • 12 comments

The new ring buffer is introduced. The use case for the ring buffer is for delay handling, but it also could be used as a classic ring buffer with a jumping option with the reading position. It is based on the classic known ring buffer. The extensions are, that the ring delay buffer allows moving with the reading position subject to certain rules. Another difference between the classic ring buffer is, that the ring delay buffer offers to read zero values, which were not written by using the write method and write position. Both of these two specific properties are based on the cross-fading between changes of two delays.

davidchocholaty avatar Jul 12 '22 13:07 davidchocholaty

Thanks. Before I go into detail reviewing this. it would make sense to first introduce the std::/gsl::span shim we discussed.

Swiftb0y avatar Jul 12 '22 14:07 Swiftb0y

Another inspiration for a singlethreaded Ringbuffer: https://hg.sr.ht/~breakfastquay/rubberband/browse/src/common/SingleThreadRingBuffer.h?rev=tip

Swiftb0y avatar Jul 14 '22 21:07 Swiftb0y

Another inspiration for a singlethreaded Ringbuffer: https://hg.sr.ht/~breakfastquay/rubberband/browse/src/common/SingleThreadRingBuffer.h?rev=tip

Thank you for this tip.

davidchocholaty avatar Jul 15 '22 12:07 davidchocholaty

I would like to post a little info about the possible choice of using only memcpy for RingDelayBuffer or SampleUtil::copy instead (vectorized loop for SSE on 32-bit). Because my system uses 64-bit system (Ubuntu 22.04 LTS) and CPU (Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz) offers SSE and SSE2, the memcpy will be used for SampleUtil::copy too. I used benchmarks with standard deviation. The statistics including standard deviation can be computed as ./mixxx-test --benchmark --benchmark_repetitions=20 --benchmark_filter=BM_WriteReadWholeBuffer for only RingDelayBuffer benchmarks and 20 repetitions for example. As I expected, on my system the SampleUtil::copy version takes a little bit more time (function calls, evaluation of conditions, etc.). Another choice could be std::copy, but IMO the current RingDelayBuffer look can't be used and based on the survey from SampleUtil::copy takes the most time. I would like to ask you, which version from your point of view you prefer because we talked with @Swiftb0y that we should also take into account the standard deviation of benchmark results, but I can't test it for vectorized loop version. For interest the result of benchmarks:

memcpy:

----------------------------------------------------------------------------------------------
Benchmark                                                    Time             CPU   Iterations
----------------------------------------------------------------------------------------------
BM_WriteReadWholeBufferNoSkip/64                           517 ns          523 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           517 ns          523 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           513 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           515 ns          521 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           516 ns          522 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           515 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           513 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          520 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           513 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           514 ns          519 ns      1317352
BM_WriteReadWholeBufferNoSkip/64                           515 ns          521 ns      1317352
BM_WriteReadWholeBufferNoSkip/64_mean                      514 ns          520 ns           20
BM_WriteReadWholeBufferNoSkip/64_median                    514 ns          520 ns           20
BM_WriteReadWholeBufferNoSkip/64_stddev                   1.23 ns         1.14 ns           20
BM_WriteReadWholeBufferNoSkip/64_cv                       0.24 %          0.22 %            20
BM_WriteReadWholeBufferNoSkip/512                          589 ns          593 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          596 ns          600 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          590 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          593 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          593 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          590 ns          595 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          593 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          593 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          592 ns          596 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          590 ns          595 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          594 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          591 ns          596 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          589 ns          593 ns      1180062
BM_WriteReadWholeBufferNoSkip/512                          590 ns          595 ns      1180062
BM_WriteReadWholeBufferNoSkip/512_mean                     590 ns          594 ns           20
BM_WriteReadWholeBufferNoSkip/512_median                   589 ns          594 ns           20
BM_WriteReadWholeBufferNoSkip/512_stddev                  1.58 ns         1.58 ns           20
BM_WriteReadWholeBufferNoSkip/512_cv                      0.27 %          0.27 %            20
BM_WriteReadWholeBufferNoSkip/4096                        1205 ns         1242 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1204 ns         1241 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1224 ns         1262 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1207 ns         1244 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1210 ns         1247 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1206 ns         1243 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1207 ns         1244 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1211 ns         1248 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1207 ns         1244 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1220 ns         1258 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1221 ns         1259 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1219 ns         1257 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1225 ns         1263 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1224 ns         1263 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1220 ns         1258 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1221 ns         1259 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1219 ns         1257 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1200 ns         1238 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1199 ns         1237 ns       560769
BM_WriteReadWholeBufferNoSkip/4096                        1200 ns         1238 ns       560769
BM_WriteReadWholeBufferNoSkip/4096_mean                   1213 ns         1250 ns           20
BM_WriteReadWholeBufferNoSkip/4096_median                 1210 ns         1247 ns           20
BM_WriteReadWholeBufferNoSkip/4096_stddev                 9.00 ns         9.21 ns           20
BM_WriteReadWholeBufferNoSkip/4096_cv                     0.74 %          0.74 %            20
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 529 ns          534 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 519 ns          525 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          523 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 519 ns          524 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 516 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 517 ns          522 ns      1340491
BM_WriteReadWholeBufferSkipLeftNoCircle/64_mean            518 ns          523 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/64_median          517 ns          523 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/64_stddev         2.83 ns         2.77 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/64_cv             0.55 %          0.53 %            20
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          587 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                595 ns          600 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          589 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          587 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                586 ns          592 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          589 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          589 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          589 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                582 ns          588 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                596 ns          602 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                581 ns          586 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512                581 ns          586 ns      1191962
BM_WriteReadWholeBufferSkipLeftNoCircle/512_mean           584 ns          589 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/512_median         583 ns          588 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/512_stddev        4.12 ns         4.10 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/512_cv            0.71 %          0.70 %            20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1163 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1173 ns         1210 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1177 ns         1217 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1168 ns         1208 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1162 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1164 ns         1203 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1164 ns         1203 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1162 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1162 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1193 ns         1231 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1196 ns         1234 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1193 ns         1230 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1203 ns         1241 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1195 ns         1233 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1197 ns         1235 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1197 ns         1234 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1194 ns         1231 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1162 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1163 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1162 ns         1202 ns       582032
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_mean         1177 ns         1216 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_median       1170 ns         1209 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_stddev       16.0 ns         15.1 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_cv           1.36 %          1.24 %            20
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   531 ns          537 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   520 ns          526 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   520 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   527 ns          532 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   527 ns          533 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   520 ns          526 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   521 ns          527 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   522 ns          529 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          526 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          526 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   520 ns          526 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64                   519 ns          525 ns      1333871
BM_WriteReadWholeBufferSkipLeftCircle/64_mean              521 ns          527 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/64_median            519 ns          526 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/64_stddev           3.32 ns         3.27 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/64_cv               0.64 %          0.62 %            20
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  599 ns          605 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  592 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  593 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  593 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  592 ns          597 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  594 ns          599 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          597 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  592 ns          597 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  593 ns          599 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  592 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  592 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  592 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          598 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  594 ns          600 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          597 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512                  591 ns          597 ns      1171693
BM_WriteReadWholeBufferSkipLeftCircle/512_mean             592 ns          598 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/512_median           592 ns          598 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/512_stddev          1.84 ns         1.83 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/512_cv              0.31 %          0.31 %            20
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1255 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1216 ns         1260 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1224 ns         1268 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1215 ns         1260 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1254 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1209 ns         1254 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1209 ns         1254 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1255 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1255 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1289 ns         1334 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1289 ns         1333 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1288 ns         1332 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1301 ns         1345 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1289 ns         1333 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1289 ns         1333 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1289 ns         1333 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1288 ns         1332 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1254 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1254 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096                1210 ns         1255 ns       557719
BM_WriteReadWholeBufferSkipLeftCircle/4096_mean           1243 ns         1288 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/4096_median         1216 ns         1260 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/4096_stddev         39.7 ns         39.4 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/4096_cv             3.19 %          3.06 %            20

SampleUtil::copy:

----------------------------------------------------------------------------------------------
Benchmark                                                    Time             CPU   Iterations
----------------------------------------------------------------------------------------------
BM_WriteReadWholeBufferNoSkip/64                           516 ns          520 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           521 ns          525 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           522 ns          526 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           516 ns          520 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           517 ns          521 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           516 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           516 ns          520 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          520 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           516 ns          520 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64                           515 ns          519 ns      1305947
BM_WriteReadWholeBufferNoSkip/64_mean                      516 ns          520 ns           20
BM_WriteReadWholeBufferNoSkip/64_median                    515 ns          519 ns           20
BM_WriteReadWholeBufferNoSkip/64_stddev                   1.99 ns         1.92 ns           20
BM_WriteReadWholeBufferNoSkip/64_cv                       0.38 %          0.37 %            20
BM_WriteReadWholeBufferNoSkip/512                          580 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          588 ns          592 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          582 ns          586 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          583 ns          587 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          586 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          582 ns          586 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          584 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          584 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          584 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          584 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          580 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          582 ns          586 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          584 ns      1198103
BM_WriteReadWholeBufferNoSkip/512                          581 ns          585 ns      1198103
BM_WriteReadWholeBufferNoSkip/512_mean                     581 ns          585 ns           20
BM_WriteReadWholeBufferNoSkip/512_median                   581 ns          585 ns           20
BM_WriteReadWholeBufferNoSkip/512_stddev                  1.83 ns         1.83 ns           20
BM_WriteReadWholeBufferNoSkip/512_cv                      0.31 %          0.31 %            20
BM_WriteReadWholeBufferNoSkip/4096                        1219 ns         1248 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1224 ns         1254 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1245 ns         1274 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1224 ns         1254 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1221 ns         1251 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1218 ns         1247 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1217 ns         1246 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1220 ns         1249 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1217 ns         1246 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1207 ns         1238 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1207 ns         1238 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1206 ns         1237 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1211 ns         1241 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1204 ns         1235 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1201 ns         1232 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1204 ns         1235 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1203 ns         1234 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1217 ns         1246 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1219 ns         1248 ns       559876
BM_WriteReadWholeBufferNoSkip/4096                        1217 ns         1246 ns       559876
BM_WriteReadWholeBufferNoSkip/4096_mean                   1215 ns         1245 ns           20
BM_WriteReadWholeBufferNoSkip/4096_median                 1217 ns         1246 ns           20
BM_WriteReadWholeBufferNoSkip/4096_stddev                 10.2 ns         9.63 ns           20
BM_WriteReadWholeBufferNoSkip/4096_cv                     0.84 %          0.77 %            20
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          523 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 531 ns          535 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 521 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 519 ns          523 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 521 ns          525 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 521 ns          525 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 521 ns          525 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64                 520 ns          524 ns      1319954
BM_WriteReadWholeBufferSkipLeftNoCircle/64_mean            521 ns          525 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/64_median          520 ns          524 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/64_stddev         2.46 ns         2.44 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/64_cv             0.47 %          0.46 %            20
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                590 ns          593 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                585 ns          588 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          588 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          588 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                585 ns          589 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          588 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                585 ns          588 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                585 ns          589 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                584 ns          588 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512                583 ns          587 ns      1192974
BM_WriteReadWholeBufferSkipLeftNoCircle/512_mean           584 ns          588 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/512_median         584 ns          587 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/512_stddev        1.39 ns         1.34 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/512_cv            0.24 %          0.23 %            20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1189 ns         1216 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1194 ns         1221 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1201 ns         1228 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1191 ns         1218 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1188 ns         1215 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1188 ns         1216 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1188 ns         1216 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1190 ns         1217 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1189 ns         1217 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1191 ns         1221 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1190 ns         1221 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1193 ns         1224 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1193 ns         1223 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1194 ns         1225 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1187 ns         1218 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1188 ns         1218 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1187 ns         1218 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1189 ns         1216 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1188 ns         1215 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096              1189 ns         1215 ns       573397
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_mean         1190 ns         1219 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_median       1189 ns         1218 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_stddev       3.28 ns         3.80 ns           20
BM_WriteReadWholeBufferSkipLeftNoCircle/4096_cv           0.28 %          0.31 %            20
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          528 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   532 ns          536 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   525 ns          530 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          528 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   525 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          528 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   526 ns          531 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   525 ns          530 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          528 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64                   524 ns          529 ns      1324806
BM_WriteReadWholeBufferSkipLeftCircle/64_mean              525 ns          529 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/64_median            524 ns          529 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/64_stddev           1.89 ns         1.77 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/64_cv               0.36 %          0.33 %            20
BM_WriteReadWholeBufferSkipLeftCircle/512                  607 ns          611 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  616 ns          621 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  607 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  608 ns          613 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          611 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          611 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          611 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  611 ns          616 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  608 ns          613 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  609 ns          614 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512                  606 ns          612 ns      1146359
BM_WriteReadWholeBufferSkipLeftCircle/512_mean             607 ns          613 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/512_median           606 ns          612 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/512_stddev          2.35 ns         2.27 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/512_cv              0.39 %          0.37 %            20
BM_WriteReadWholeBufferSkipLeftCircle/4096                1242 ns         1284 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1247 ns         1289 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1271 ns         1313 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1246 ns         1288 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1240 ns         1282 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1243 ns         1285 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1241 ns         1283 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1242 ns         1284 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1241 ns         1283 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1234 ns         1276 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1235 ns         1277 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1234 ns         1276 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1239 ns         1281 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1237 ns         1279 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1233 ns         1275 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1233 ns         1275 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1236 ns         1278 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1241 ns         1283 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1243 ns         1285 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096                1241 ns         1283 ns       546739
BM_WriteReadWholeBufferSkipLeftCircle/4096_mean           1241 ns         1283 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/4096_median         1241 ns         1283 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/4096_stddev         8.25 ns         8.29 ns           20
BM_WriteReadWholeBufferSkipLeftCircle/4096_cv             0.66 %          0.65 %            20

davidchocholaty avatar Jul 19 '22 08:07 davidchocholaty

I think, that I should just summarize some of your reviews and the current code look. I would like to discuss, the problem, for most of the review's indirectly points. The problem, why the current code look is in some cases a little bit over-complicated is, that to follow the same behaviour as in EngineEffectsDelay, read of uninitialized (zero values) has to be enabled. The situation may arise for example for the following workflow:

Precondition: ring delay buffer is empty with uninitialized (zero) values and the read and the write positions are zero.

  1. Write 8 samples into the ring delay buffer and read them:
index:                            0,  1,  2,  3,  4,  5,  6,  7,  8
-  -  -  -  -  -  -  -  -  -  - -----------------------------------------------
... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 0 | 0 | ...
-  -  -  -  -  -  -  -  -  -  - -----------------------------------------------
                                                                  ^
                                                                  readPos, writePos
  1. Write another 8 samples and read with delay, for example, 12 samples
index:                            0,  1,  2,  3,  4,  5,  6,  7,  8,  9,   10,  11,  ...
-  -  -  -  -  -  -  -  -  -  - ---------------------------------------------------------
... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ...
-  -  -  -  -  -  -  -  -  -  - ---------------------------------------------------------
                  ^                                                                   ^
                  readPos                                                             writePos

In the shown situation, the uninitialized (zero) values have to be read. In EngineEffectsDelay this situation can arise for crossfading between two delays.

Now, here are two options:

  1. Allow the mentioned situation:
  • After ring delay buffer allocation all values have to be explicitly set to zero.
  • A little bit more complicated read position handling has to be used, but still the current code look can be refactorized a lot.
  • Follow the delay buffer workflow as in EngineEffectsDelay and EngineFilterDelay (here is this situation possible too).
  1. Not allow the mentioned situation:
  • The ring delay buffer doesn't behave properly for this situation and the VERIFY_OR_DEBUG_ASSERT has to be used.
  • Easier calculations for reading position.

Now, I would like to open a small discussion about this behaviour problem.

davidchocholaty avatar Jul 19 '22 10:07 davidchocholaty

I don't understand how it can happen that the read position is ahead of the write position. That would mean that you are trying to read more samples than given. When used in the filter delay, that would mean that there was a negative delay. Can you elaborate on the exact circumstances that would lead to this?

Irregardless of this, I still don't understand why the read position calculation has to as complicated as it currently is.

Swiftb0y avatar Jul 20 '22 14:07 Swiftb0y

Irregardless of this, I still don't understand why the read position calculation has to be as complicated as it currently is.

The read position calculation can be of course simplified by using modulo operation instead of AND operation. That's of course possible. I didn't mention it that strongly with the phrase _" but still the current code look can be refactorized a lot." _.

The reason, why I dwell so much on the mentioned situation is, that with simplification this situation must be taken into account. Based on your's and daschuer's reviews, the code can be simplified of course a lot, but IMO it makes sense to dig through simplification with the final decision for the mentioned situation because it is not at all common for a ring buffer as known and doesn't make sense to reimplement something without clear vision what it can and can't do.

davidchocholaty avatar Jul 21 '22 13:07 davidchocholaty

I don't understand how it can happen that the read position is ahead of the write position. That would mean that you are trying to read more samples than given. When used in the filter delay, that would mean that there was a negative delay. Can you elaborate on the exact circumstances that would lead to this?

Yeah, I understand that it is not easy to understand this situation without all the cases around. I think, that the best will be an example with calculations from the EngineEffectsDelay::process method. Let's assume the example from the previous drawing. Maybe it would be cool to have engineeffectsdelay.cpp code open, I will follow it.

Just for info, the EngineEffectsDelay::process code isn't exactly the same as RingDelayBuffer one-by-one, but if this situation is possible, using RingDelayBuffer for the mentioned method, the ring buffer should handle this situation.

For the following examples, I will assume kMaxDelay = 192000, but it doesn't matter now.

So, the first process call (zero delay, write 8 samples, then read 8 samples):

int delaySourcePos =
            (m_delayBufferWritePos + kMaxDelay - m_currentDelaySamples) %
            kMaxDelay;

delaySourcePos = (0 + 192000 - 0) % 192000 = 0

int oldDelaySourcePos =
                (m_delayBufferWritePos + kMaxDelay - m_prevDelaySamples) %
                kMaxDelay;

oldDelaySourcePos = (0 + 192000 - 0) % 192000 = 0

The second process call (delay 12 samples (a possible situation, but shouldn't be so common), write another 8 samples and read 8 samples):

int delaySourcePos =
            (m_delayBufferWritePos + kMaxDelay - m_currentDelaySamples) %
            kMaxDelay;

delaySourcePos = (8 + 192000 - 12) % 192000 = 191996 % 192000 = 191996

int oldDelaySourcePos =
                (m_delayBufferWritePos + kMaxDelay - m_prevDelaySamples) %
                kMaxDelay;

oldDelaySourcePos = (8 + 192000 - 0) % 192000 = 8

This is the situation, which I have in mind because at the start with a clear buffer, there isn't written data on 191996 index. Please, let me now if it is a little bit more clearer. I would like to know, "if we are on the same page" with this problem.

davidchocholaty avatar Jul 21 '22 13:07 davidchocholaty

Ah, I think understand. Yes in that case we should just have the buffer pre-filled with zeros IMO.

Swiftb0y avatar Jul 21 '22 18:07 Swiftb0y

Okay, perfect. Thank you. So now when we agreed to allow the mentioned special case, I will simplify all the calculations asap.

davidchocholaty avatar Jul 22 '22 14:07 davidchocholaty

When it happens that you read out the initial zeros, you will hear a click sound when the real samples starts. This can be avoided by fading in the fist input buffer.

daschuer avatar Jul 23 '22 03:07 daschuer

When it happens that you read out the initial zeros, you will hear a click sound when the real samples starts. This can be avoided by fading in the fist input buffer.

Good point. Thank you for this tip.

davidchocholaty avatar Jul 29 '22 05:07 davidchocholaty

Just a little sum up. To make this PR ready, the last thing from my side is to finish the documentation and descriptive comments, if the previous changes will pass your reviews. The last thing, that I have on my mind is, that the mentioned licence for mixxx/lib/portaudio/pa_ringbuffer.c is likely no longer required due to major previous changes and the creation of a new implementation during this PR. What do you think?

davidchocholaty avatar Aug 27 '22 20:08 davidchocholaty

Just a little sum up. To make this PR ready, the last thing from my side is to finish the documentation and descriptive comments, if the previous changes will pass your reviews. The last thing, that I have on my mind is, that the mentioned licence for mixxx/lib/portaudio/pa_ringbuffer.c is likely no longer required due to major previous changes and the creation of a new implementation during this PR. What do you think?

IANAL, but I don't think its required anymore...

Swiftb0y avatar Aug 29 '22 14:08 Swiftb0y

sorry for the nitpicks again....

Absolutely no problem, this is how I should have written it the first time, I just did it too much automatically. Now, it should be fixed. The indent was kept to make it a little bit more readable.

davidchocholaty avatar Aug 29 '22 19:08 davidchocholaty

Perfect, thank you very much for merging.

davidchocholaty avatar Aug 29 '22 20:08 davidchocholaty