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 WaveChannel;
22
24 {
31 };
32
33class VoiceKey {
34
35 public:
36 VoiceKey();
37 ~VoiceKey();
42
43 void CalibrateNoise(const WaveChannel & t, sampleCount start, sampleCount len);
44 void AdjustThreshold(double t);
45
46
47 bool AboveThreshold(const WaveChannel & 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 WaveChannel & t, sampleCount start,sampleCount len);
83 double TestSignChanges (
84 const WaveChannel & t, sampleCount start, sampleCount len);
86 const WaveChannel & 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 TestDirectionChanges(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:951
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
VoiceKey()
Definition: VoiceKey.cpp:38
sampleCount OffForward(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:382
double mSignalWindowSize
Definition: VoiceKey.h:80
bool mUseSignChangesLow
Definition: VoiceKey.h:73
sampleCount OnBackward(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:236
double mThresholdDirectionChangesUpper
Definition: VoiceKey.h:69
void AdjustThreshold(double t)
Definition: VoiceKey.cpp:726
sampleCount OnForward(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:84
double mThresholdDirectionChangesLower
Definition: VoiceKey.h:68
bool AboveThreshold(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:657
bool mUseDirectionChangesLow
Definition: VoiceKey.h:75
double mEnergySD
Definition: VoiceKey.h:59
double mSignChangesSD
Definition: VoiceKey.h:61
sampleCount OffBackward(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:518
double mSignChangesMean
Definition: VoiceKey.h:60
void TestEnergyUpdate(double &prevErg, int length, const float &drop, const float &add)
Definition: VoiceKey.cpp:887
double mThresholdSignChangesLower
Definition: VoiceKey.h:66
double mWindowSize
Definition: VoiceKey.h:54
bool mUseDirectionChangesHigh
Definition: VoiceKey.h:76
double TestEnergy(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:854
double mThresholdEnergy
Definition: VoiceKey.h:65
double TestSignChanges(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:895
void CalibrateNoise(const WaveChannel &t, sampleCount start, sampleCount len)
Definition: VoiceKey.cpp:739
double mEnergyMean
Definition: VoiceKey.h:58
~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
double mThresholdSignChangesUpper
Definition: VoiceKey.h:67
double mDirectionChangesSD
Definition: VoiceKey.h:63
double mDirectionChangesMean
Definition: VoiceKey.h:62
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