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

Method TestSignChanges

src/VoiceKey.cpp:895–936  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

893
894
895double VoiceKey::TestSignChanges(
896 const WaveChannel & t, sampleCount start, sampleCount len)
897{
898
899
900 auto s = start; //Keep track of start
901 auto originalLen = len; //Keep track of the length of block to process (its not the length of t)
902 const auto blockSize = limitSampleBufferSize(
903 t.GetMaxBlockSize(), len); //Determine size of sampling buffer
904 unsigned long signchanges = 1;
905 int currentsign=0;
906
907 Floats buffer{ blockSize }; //Get a sampling buffer
908
909 while(len > 0) {
910 //Figure out how much to grab
911 auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
912
913 t.GetFloats(buffer.get(), s, block); //grab the block;
914
915 if (len == originalLen)
916 {
917 //The first time through, set stuff up special.
918 currentsign = sgn(buffer[0]);
919 }
920
921 //Now, go through the block and calculate zero crossings
922
923 for(decltype(block) i = 0; i< block; i++)
924 {
925 if( sgn(buffer[i]) != currentsign)
926 {
927 currentsign = sgn(buffer[i]);
928 signchanges++;
929 }
930
931 }
932 len -= block;
933 s += block;
934 }
935 return (double)signchanges / originalLen.as_double();
936}
937
938void VoiceKey::TestSignChangesUpdate(double & currentsignchanges, int len,
939 const float & a1,

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