MCPcopy Create free account
hub / github.com/audacity/audacity / TestDirectionChanges

Method TestDirectionChanges

src/VoiceKey.cpp:951–993  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

949
950
951double VoiceKey::TestDirectionChanges(
952 const WaveChannel & t, sampleCount start, sampleCount len)
953{
954
955
956 auto s = start; //Keep track of start
957 auto originalLen = len; //Keep track of the length of block to process (its not the length of t)
958 const auto blockSize = limitSampleBufferSize(
959 t.GetMaxBlockSize(), len); //Determine size of sampling buffer
960 unsigned long directionchanges = 1;
961 float lastval=float(0);
962 int lastdirection=1;
963
964 Floats buffer{ blockSize }; //Get a sampling buffer
965
966 while(len > 0) {
967 //Figure out how much to grab
968 auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
969
970 t.GetFloats(buffer.get(), s, block); //grab the block;
971
972 if (len == originalLen) {
973 //The first time through, set stuff up special.
974 lastval = buffer[0];
975 }
976
977 //Now, go through the block and calculate zero crossings
978
979
980 for(decltype(block) i = 0; i< block; i++){
981
982 if( sgn(buffer[i]-lastval) != lastdirection) {
983 directionchanges++;
984 lastdirection = sgn(buffer[i] - lastval);
985 }
986 lastval = buffer[i];
987
988 }
989 len -= block;
990 s += block;
991 }
992 return (double)directionchanges/originalLen.as_double();
993}
994
995
996

Callers

nothing calls this directly

Calls 6

limitSampleBufferSizeFunction · 0.85
sgnFunction · 0.85
GetMaxBlockSizeMethod · 0.45
GetBestBlockSizeMethod · 0.45
GetFloatsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected