Audacity 3.2.0
Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
ContrastBase Class Referenceabstract

#include <ContrastBase.h>

Inheritance diagram for ContrastBase:
[legend]

Public Attributes

double mT0
 
double mT1
 
double mProjectRate
 
double mStartTimeF
 
double mEndTimeF
 
double mStartTimeB
 
double mEndTimeB
 

Protected Member Functions

bool GetDB (float &dB)
 
void SetStartAndEndTime ()
 

Protected Attributes

float foregrounddB
 
float backgrounddB
 
bool mForegroundIsDefined
 
bool mBackgroundIsDefined
 
double mT0orig
 
double mT1orig
 
bool mDoBackground
 
double length
 

Private Member Functions

virtual AudacityProjectGetProject ()=0
 

Detailed Description

Definition at line 12 of file ContrastBase.h.

Member Function Documentation

◆ GetDB()

bool ContrastBase::GetDB ( float &  dB)
protected

Definition at line 16 of file ContrastBase.cpp.

17{
18 float rms = float(0.0);
19
20 // For stereo tracks: sqrt((mean(L)+mean(R))/2)
21 double meanSq = 0.0;
22
23 auto& p = GetProject();
24 auto range = TrackList::Get(p).Selected<const WaveTrack>();
25 auto numberSelectedTracks = range.size();
26 using namespace BasicUI;
27 if (numberSelectedTracks > 1)
28 {
30 XO("You can only measure one track at a time."),
31 MessageBoxOptions {}.IconStyle(Icon::Error));
32 return false;
33 }
34 if (numberSelectedTracks == 0)
35 {
37 XO("Please select an audio track."),
38 MessageBoxOptions {}.IconStyle(Icon::Error));
39 return false;
40 }
41
42 const auto first = *range.begin();
43 const auto channels = first->Channels();
44 assert(mT0 <= mT1);
45 // Ignore whitespace beyond ends of track.
46 mT0 = std::max(mT0, first->GetStartTime());
47 mT1 = std::min(mT1, first->GetEndTime());
48 for (auto t : channels)
49 {
50
51 auto SelT0 = t->TimeToLongSamples(mT0);
52 auto SelT1 = t->TimeToLongSamples(mT1);
53
54 if (SelT0 > SelT1)
55 {
57 XO("Invalid audio selection.\nPlease ensure that audio is selected."),
58 MessageBoxOptions {}.IconStyle(Icon::Error));
59 return false;
60 }
61
62 if (SelT0 == SelT1)
63 {
65 XO("Nothing to measure.\nPlease select a section of a track."),
66 MessageBoxOptions {}.IconStyle(Icon::Error));
67 return false;
68 }
69
70 // Don't throw in this analysis dialog
71 rms = WaveChannelUtilities::GetRMS(*t, mT0, mT1, false);
72 meanSq += rms * rms;
73 }
74 // TODO: This works for stereo, provided the audio clips are in both
75 // channels. We should really count gaps between clips as silence.
76 rms = (meanSq > 0.0) ? sqrt(meanSq / static_cast<double>(channels.size())) :
77 0.0;
78
79 // Gives warning C4056, Overflow in floating-point constant arithmetic
80 // -INFINITY is intentional here.
81 // Looks like we are stuck with this warning, as
82 // #pragma warning( disable : 4056)
83 // even around the whole function does not disable it successfully.
84
85 dB = (rms == 0.0) ? -INFINITY : LINEAR_TO_DB(rms);
86 return true;
87}
int min(int a, int b)
XO("Cut/Copy/Paste")
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:339
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:260
virtual AudacityProject & GetProject()=0
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
#define INFINITY
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287
WAVE_TRACK_API float GetRMS(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
__finl float_x4 __vecc sqrt(const float_x4 &a)
MessageBoxOptions && IconStyle(Icon style) &&
Definition: BasicUI.h:104

References TrackList::Get(), GetProject(), WaveChannelUtilities::GetRMS(), BasicUI::MessageBoxOptions::IconStyle(), INFINITY, LINEAR_TO_DB, min(), mT0, mT1, TrackList::Selected(), BasicUI::ShowMessageBox(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), staffpad::audio::simd::sqrt(), and XO().

Referenced by ContrastDialog::OnGetBackground(), and ContrastDialog::OnGetForeground().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetProject()

virtual AudacityProject & ContrastBase::GetProject ( )
privatepure virtual

Implemented in ContrastDialog.

Referenced by GetDB(), and SetStartAndEndTime().

Here is the caller graph for this function:

◆ SetStartAndEndTime()

void ContrastBase::SetStartAndEndTime ( )
protected

Definition at line 89 of file ContrastBase.cpp.

90{
91 auto& p = GetProject();
92 auto& selectedRegion = ViewInfo::Get(p).selectedRegion;
93 mT0 = selectedRegion.t0();
94 mT1 = selectedRegion.t1();
95}
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References ViewInfo::Get(), GetProject(), mT0, mT1, and ViewInfo::selectedRegion.

Referenced by ContrastDialog::OnGetBackground(), and ContrastDialog::OnGetForeground().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ backgrounddB

float ContrastBase::backgrounddB
protected

◆ foregrounddB

float ContrastBase::foregrounddB
protected

◆ length

double ContrastBase::length
protected

Definition at line 35 of file ContrastBase.h.

◆ mBackgroundIsDefined

bool ContrastBase::mBackgroundIsDefined
protected

◆ mDoBackground

bool ContrastBase::mDoBackground
protected

Definition at line 31 of file ContrastBase.h.

◆ mEndTimeB

double ContrastBase::mEndTimeB

Definition at line 21 of file ContrastBase.h.

◆ mEndTimeF

double ContrastBase::mEndTimeF

Definition at line 19 of file ContrastBase.h.

◆ mForegroundIsDefined

bool ContrastBase::mForegroundIsDefined
protected

◆ mProjectRate

double ContrastBase::mProjectRate

Definition at line 17 of file ContrastBase.h.

Referenced by ContrastDialog::ContrastDialog().

◆ mStartTimeB

double ContrastBase::mStartTimeB

Definition at line 20 of file ContrastBase.h.

◆ mStartTimeF

double ContrastBase::mStartTimeF

Definition at line 18 of file ContrastBase.h.

◆ mT0

double ContrastBase::mT0

Definition at line 15 of file ContrastBase.h.

Referenced by ContrastDialog::ContrastDialog(), GetDB(), and SetStartAndEndTime().

◆ mT0orig

double ContrastBase::mT0orig
protected

Definition at line 28 of file ContrastBase.h.

◆ mT1

double ContrastBase::mT1

Definition at line 16 of file ContrastBase.h.

Referenced by ContrastDialog::ContrastDialog(), GetDB(), and SetStartAndEndTime().

◆ mT1orig

double ContrastBase::mT1orig
protected

Definition at line 29 of file ContrastBase.h.


The documentation for this class was generated from the following files: