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
21class WaveTrack;
22
24 {
31 };
32
33class VoiceKey {
34
35 public:
36 VoiceKey();
37 ~VoiceKey();
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
59 double mEnergySD;
64
65 double mThresholdEnergy; // Threshold[*] is equal to [*]Mean + [*]SD * ThresholdAdjustment
70
71 //These determine which statistics should be used.
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);
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
98inline 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
VoiceKeyTypes
Definition: VoiceKey.h:24
@ VKT_SIGN_CHANGES_HIGH
Definition: VoiceKey.h:28
@ VKT_DIRECTION_CHANGES_LOW
Definition: VoiceKey.h:29
@ VKT_NONE
Definition: VoiceKey.h:25
@ VKT_SIGN_CHANGES_LOW
Definition: VoiceKey.h:27
@ VKT_ENERGY
Definition: VoiceKey.h:26
@ VKT_DIRECTION_CHANGES_HIGH
Definition: VoiceKey.h:30
int sgn(int number)
Definition: VoiceKey.h:98
This implements a voice key, detecting either the next "ON" or "OFF" point.
Definition: VoiceKey.h:33
double mThresholdAdjustment
Definition: VoiceKey.h:56
bool mUseSignChangesHigh
Definition: VoiceKey.h:74
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:1000
sampleCount OnBackward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:236
VoiceKey()
Definition: VoiceKey.cpp:38
double TestDirectionChanges(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:951
double mSignalWindowSize
Definition: VoiceKey.h:80
bool mUseSignChangesLow
Definition: VoiceKey.h:73
double mThresholdDirectionChangesUpper
Definition: VoiceKey.h:69
void AdjustThreshold(double t)
Definition: VoiceKey.cpp:726
double mThresholdDirectionChangesLower
Definition: VoiceKey.h:68
double TestEnergy(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:854
bool mUseDirectionChangesLow
Definition: VoiceKey.h:75
double mEnergySD
Definition: VoiceKey.h:59
double mSignChangesSD
Definition: VoiceKey.h:61
double mSignChangesMean
Definition: VoiceKey.h:60
sampleCount OffForward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:382
void TestEnergyUpdate(double &prevErg, int length, const float &drop, const float &add)
Definition: VoiceKey.cpp:887
bool AboveThreshold(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:657
double mThresholdSignChangesLower
Definition: VoiceKey.h:66
double mWindowSize
Definition: VoiceKey.h:54
bool mUseDirectionChangesHigh
Definition: VoiceKey.h:76
double mThresholdEnergy
Definition: VoiceKey.h:65
double TestSignChanges(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:895
double mEnergyMean
Definition: VoiceKey.h:58
void CalibrateNoise(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:739
~VoiceKey()
Definition: VoiceKey.cpp:66
bool mUseEnergy
Definition: VoiceKey.h:72
void SetKeyType(bool erg, bool scLow, bool scHigh, bool dcLow, bool dcHigh)
Definition: VoiceKey.cpp:842
double mSilentWindowSize
Definition: VoiceKey.h:79
void TestSignChangesUpdate(double &currentsignchanges, int length, const float &a1, const float &a2, const float &z1, const float &z2)
Definition: VoiceKey.cpp:938
sampleCount OffBackward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:518
double mThresholdSignChangesUpper
Definition: VoiceKey.h:67
sampleCount OnForward(const WaveTrack &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:84
double mDirectionChangesSD
Definition: VoiceKey.h:63
double mDirectionChangesMean
Definition: VoiceKey.h:62
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
void add(const T *src1, const T *src2, T *dst, int32_t n)
Definition: VectorOps.h:46