Audacity  3.2.0
VoiceKey.h
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Audacity: A Digtial Audio Editor
4 
5  VoiceKey.h: a class implementing a voice key
6 
7  (c) 2002-2005 Shane T. Mueller
8  Distributed under the terms of the GPL Version 2 or later.
9 
10 ***************************************************************************/
11 #ifndef __AUDACITY_VOICEKEY__
12 #define __AUDACITY_VOICEKEY__
13 
14 
15 #ifndef M_PI
16 #define M_PI 3.14159265358979323846 /* pi */
17 #endif
18 
19 #include "SampleCount.h"
20 
21 class WaveTrack;
22 
24  {
25  VKT_NONE = 0,
31  };
32 
33 class VoiceKey {
34 
35  public:
36  VoiceKey();
37  ~VoiceKey();
38  sampleCount OnForward (const WaveTrack & t, sampleCount start, sampleCount len);
39  sampleCount OnBackward (const WaveTrack & t, sampleCount start, sampleCount len);
40  sampleCount OffForward (const WaveTrack & t, sampleCount start, sampleCount len);
42 
43  void CalibrateNoise(const WaveTrack & t, sampleCount start, sampleCount len);
44  void AdjustThreshold(double t);
45 
46 
47  bool AboveThreshold(const WaveTrack & t, sampleCount start,sampleCount len);
48 
49  void SetKeyType(bool erg, bool scLow, bool scHigh,
50  bool dcLow, bool dcHigh);
51 
52  private:
53 
54  double mWindowSize; //Size of analysis window, in milliseconds
55 
56  double mThresholdAdjustment; //User-accessible sensitivity calibration variable
57 
58  double mEnergyMean;
59  double mEnergySD;
64 
65  double mThresholdEnergy; // Threshold[*] is equal to [*]Mean + [*]SD * ThresholdAdjustment
70 
71  //These determine which statistics should be used.
72  bool mUseEnergy;
77 
78 
79  double mSilentWindowSize; //Time in milliseconds of below-threshold windows required for silence
80  double mSignalWindowSize; //Time in milliseconds of above-threshold windows required for speech
81 
82  double TestEnergy (const WaveTrack & t, sampleCount start,sampleCount len);
83  double TestSignChanges (
84  const WaveTrack & t, sampleCount start, sampleCount len);
85  double TestDirectionChanges(
86  const WaveTrack & t, sampleCount start, sampleCount len);
87 
88  void TestEnergyUpdate (double & prevErg, int length, const float & drop, const float & add);
89  void TestSignChangesUpdate(double & currentsignchanges,int length, const float & a1,
90  const float & a2, const float & z1, const float & z2);
91  void TestDirectionChangesUpdate(double & currentdirectionchanges,int length,
92  int & atrend, const float & a1, const float & a2,
93  int & ztrend, const float & z1, const float & z2);
94 
95 };
96 
97 
98 inline int sgn(int number){ return (number<0) ? -1: 1;}
99 
100 //This returns a logistic density based on a z-score
101 // a logistic distn has variance (pi*s)^2/3
102 
103 //inline float inline float logistic(float z){ return fexp(-1 * z/(pi / sqrt(3)) / (1 + pow(fexp(-1 * z(pi / sqrt(3))),2)));}
104 #endif
VoiceKey::AboveThreshold
bool AboveThreshold(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:660
VoiceKeyTypes
VoiceKeyTypes
Definition: VoiceKey.h:24
VoiceKey::mSignalWindowSize
double mSignalWindowSize
Definition: VoiceKey.h:80
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
VoiceKey::OffBackward
sampleCount OffBackward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:521
VoiceKey::AdjustThreshold
void AdjustThreshold(double t)
Definition: VoiceKey.cpp:729
VoiceKey::VoiceKey
VoiceKey()
Definition: VoiceKey.cpp:41
VoiceKey::TestEnergy
double TestEnergy(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:857
sgn
int sgn(int number)
Definition: VoiceKey.h:98
VKT_ENERGY
@ VKT_ENERGY
Definition: VoiceKey.h:26
VoiceKey::TestDirectionChanges
double TestDirectionChanges(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:954
VoiceKey
This implements a voice key, detecting either the next "ON" or "OFF" point.
Definition: VoiceKey.h:33
VoiceKey::OnForward
sampleCount OnForward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:87
VKT_DIRECTION_CHANGES_HIGH
@ VKT_DIRECTION_CHANGES_HIGH
Definition: VoiceKey.h:30
VoiceKey::TestSignChanges
double TestSignChanges(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:898
VoiceKey::mUseSignChangesLow
bool mUseSignChangesLow
Definition: VoiceKey.h:73
VoiceKey::mEnergyMean
double mEnergyMean
Definition: VoiceKey.h:58
VoiceKey::mWindowSize
double mWindowSize
Definition: VoiceKey.h:54
SampleCount.h
VoiceKey::TestEnergyUpdate
void TestEnergyUpdate(double &prevErg, int length, const float &drop, const float &add)
Definition: VoiceKey.cpp:890
VoiceKey::SetKeyType
void SetKeyType(bool erg, bool scLow, bool scHigh, bool dcLow, bool dcHigh)
Definition: VoiceKey.cpp:845
VoiceKey::mThresholdSignChangesUpper
double mThresholdSignChangesUpper
Definition: VoiceKey.h:67
VoiceKey::TestDirectionChangesUpdate
void TestDirectionChangesUpdate(double &currentdirectionchanges, int length, int &atrend, const float &a1, const float &a2, int &ztrend, const float &z1, const float &z2)
Definition: VoiceKey.cpp:1003
VKT_SIGN_CHANGES_HIGH
@ VKT_SIGN_CHANGES_HIGH
Definition: VoiceKey.h:28
VoiceKey::mUseDirectionChangesLow
bool mUseDirectionChangesLow
Definition: VoiceKey.h:75
VoiceKey::mUseDirectionChangesHigh
bool mUseDirectionChangesHigh
Definition: VoiceKey.h:76
VoiceKey::mUseEnergy
bool mUseEnergy
Definition: VoiceKey.h:72
VoiceKey::mSignChangesMean
double mSignChangesMean
Definition: VoiceKey.h:60
VKT_NONE
@ VKT_NONE
Definition: VoiceKey.h:25
VoiceKey::mThresholdDirectionChangesUpper
double mThresholdDirectionChangesUpper
Definition: VoiceKey.h:69
VoiceKey::TestSignChangesUpdate
void TestSignChangesUpdate(double &currentsignchanges, int length, const float &a1, const float &a2, const float &z1, const float &z2)
Definition: VoiceKey.cpp:941
VoiceKey::mThresholdEnergy
double mThresholdEnergy
Definition: VoiceKey.h:65
VoiceKey::~VoiceKey
~VoiceKey()
Definition: VoiceKey.cpp:69
VoiceKey::mSignChangesSD
double mSignChangesSD
Definition: VoiceKey.h:61
VoiceKey::CalibrateNoise
void CalibrateNoise(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:742
VKT_SIGN_CHANGES_LOW
@ VKT_SIGN_CHANGES_LOW
Definition: VoiceKey.h:27
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
VoiceKey::mSilentWindowSize
double mSilentWindowSize
Definition: VoiceKey.h:79
VoiceKey::mEnergySD
double mEnergySD
Definition: VoiceKey.h:59
VoiceKey::OffForward
sampleCount OffForward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:385
VKT_DIRECTION_CHANGES_LOW
@ VKT_DIRECTION_CHANGES_LOW
Definition: VoiceKey.h:29
VoiceKey::mThresholdSignChangesLower
double mThresholdSignChangesLower
Definition: VoiceKey.h:66
VoiceKey::OnBackward
sampleCount OnBackward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:239
VoiceKey::mDirectionChangesSD
double mDirectionChangesSD
Definition: VoiceKey.h:63
VoiceKey::mThresholdDirectionChangesLower
double mThresholdDirectionChangesLower
Definition: VoiceKey.h:68
VoiceKey::mDirectionChangesMean
double mDirectionChangesMean
Definition: VoiceKey.h:62
VoiceKey::mThresholdAdjustment
double mThresholdAdjustment
Definition: VoiceKey.h:56
VoiceKey::mUseSignChangesHigh
bool mUseSignChangesHigh
Definition: VoiceKey.h:74