Audacity 3.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PlotSpectrumBase Class Reference

#include <PlotSpectrumBase.h>

Inheritance diagram for PlotSpectrumBase:
[legend]
Collaboration diagram for PlotSpectrumBase:
[legend]

Public Member Functions

 PlotSpectrumBase (AudacityProject &project)
 

Protected Member Functions

bool GetAudio ()
 

Protected Attributes

AudacityProjectmProject
 
std::unique_ptr< SpectrumAnalystmAnalyst
 
bool mDrawGrid
 
int mSize
 
SpectrumAnalyst::Algorithm mAlg
 
int mFunc
 
int mAxis
 
int dBRange
 
double mRate
 
size_t mDataLen
 
ArrayOf< float > mData
 
size_t mWindowSize
 

Detailed Description

Definition at line 19 of file PlotSpectrumBase.h.

Constructor & Destructor Documentation

◆ PlotSpectrumBase()

PlotSpectrumBase::PlotSpectrumBase ( AudacityProject project)

Definition at line 18 of file PlotSpectrumBase.cpp.

19 : mProject { &project }
20 , mAnalyst(std::make_unique<SpectrumAnalyst>())
21{
22 mRate = 0;
23 mDataLen = 0;
24
25 gPrefs->Read(wxT("/FrequencyPlotDialog/DrawGrid"), &mDrawGrid, true);
26 gPrefs->Read(wxT("/FrequencyPlotDialog/SizeChoice"), &mSize, 3);
27
28 int alg;
29 gPrefs->Read(wxT("/FrequencyPlotDialog/AlgChoice"), &alg, 0);
30 mAlg = static_cast<SpectrumAnalyst::Algorithm>(alg);
31
32 gPrefs->Read(wxT("/FrequencyPlotDialog/FuncChoice"), &mFunc, 3);
33 gPrefs->Read(wxT("/FrequencyPlotDialog/AxisChoice"), &mAxis, 1);
34}
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
const auto project
std::unique_ptr< SpectrumAnalyst > mAnalyst
SpectrumAnalyst::Algorithm mAlg
AudacityProject * mProject
virtual bool Read(const wxString &key, bool *value) const =0

References gPrefs, mAlg, mAxis, mDataLen, mDrawGrid, mFunc, mRate, mSize, audacity::BasicSettings::Read(), and wxT().

Here is the call graph for this function:

Member Function Documentation

◆ GetAudio()

bool PlotSpectrumBase::GetAudio ( )
protected

Definition at line 36 of file PlotSpectrumBase.cpp.

37{
38 mData.reset();
39 mDataLen = 0;
40
41 int selcount = 0;
42 bool warning = false;
43 for (auto track : TrackList::Get(*mProject).Selected<const WaveTrack>())
44 {
45 auto& selectedRegion = ViewInfo::Get(*mProject).selectedRegion;
46 auto start = track->TimeToLongSamples(selectedRegion.t0());
47 if (selcount == 0)
48 {
49 mRate = track->GetRate();
50 auto end = track->TimeToLongSamples(selectedRegion.t1());
51 auto dataLen = end - start;
52 // Permit approximately 46.60 minutes of selected samples at
53 // a sampling frequency of 48 kHz (11.65 minutes at 192 kHz).
54 auto maxDataLen = size_t(2) << 26;
55 if (dataLen > maxDataLen)
56 {
57 warning = true;
58 mDataLen = maxDataLen;
59 }
60 else
61 mDataLen = dataLen.as_size_t();
62 mData = Floats { mDataLen };
63 }
64 const auto nChannels = track->NChannels();
65 if (track->GetRate() != mRate)
66 {
67 using namespace BasicUI;
69 XO("To plot the spectrum, all selected tracks must have the same sample rate."),
70 MessageBoxOptions {}.Caption(XO("Error")).IconStyle(Icon::Error));
71 mData.reset();
72 mDataLen = 0;
73 return false;
74 }
75 Floats buffer1 { mDataLen };
76 Floats buffer2 { mDataLen };
77 float* const buffers[] { buffer1.get(), buffer2.get() };
78 // Don't allow throw for bad reads
79 if (!track->GetFloats(
80 0, nChannels, buffers, start, mDataLen, false,
82 {
83 using namespace BasicUI;
85 XO("Audio could not be analyzed. This may be due to a stretched or pitch-shifted clip.\nTry resetting any stretched clips, or mixing and rendering the tracks before analyzing"),
86 MessageBoxOptions {}.Caption(XO("Error")).IconStyle(Icon::Error));
87 mData.reset();
88 mDataLen = 0;
89 return false;
90 }
91 size_t iChannel = 0;
92 if (selcount == 0)
93 {
94 // First channel -- assign into mData
95 for (size_t i = 0; i < mDataLen; i++)
96 mData[i] = buffers[0][i];
97 ++iChannel;
98 }
99 // Later channels -- accumulate
100 for (; iChannel < nChannels; ++iChannel)
101 {
102 const auto buffer = buffers[iChannel];
103 for (size_t i = 0; i < mDataLen; i++)
104 mData[i] += buffer[i];
105 }
106 ++selcount;
107 }
108
109 if (selcount == 0)
110 return false;
111
112 if (warning)
113 {
114 auto msg =
115 XO("Too much audio was selected. Only the first %.1f seconds of audio will be analyzed.")
116 .Format(mDataLen / mRate);
118 }
119 return true;
120}
XO("Cut/Copy/Paste")
ArrayOf< float > mData
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
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
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
MessageBoxOptions && Caption(TranslatableString caption_) &&
Definition: BasicUI.h:101

References BasicUI::MessageBoxOptions::Caption(), details::end(), fillZero, ViewInfo::Get(), TrackList::Get(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, mData, mDataLen, mRate, TrackList::Selected(), ViewInfo::selectedRegion, BasicUI::ShowMessageBox(), and XO().

Referenced by FrequencyPlotDialog::OnReplot(), and FrequencyPlotDialog::Show().

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

Member Data Documentation

◆ dBRange

int PlotSpectrumBase::dBRange
protected

◆ mAlg

SpectrumAnalyst::Algorithm PlotSpectrumBase::mAlg
protected

◆ mAnalyst

std::unique_ptr<SpectrumAnalyst> PlotSpectrumBase::mAnalyst
protected

◆ mAxis

int PlotSpectrumBase::mAxis
protected

◆ mData

ArrayOf<float> PlotSpectrumBase::mData
protected

◆ mDataLen

size_t PlotSpectrumBase::mDataLen
protected

◆ mDrawGrid

bool PlotSpectrumBase::mDrawGrid
protected

◆ mFunc

int PlotSpectrumBase::mFunc
protected

◆ mProject

AudacityProject* PlotSpectrumBase::mProject
protected

Definition at line 27 of file PlotSpectrumBase.h.

◆ mRate

double PlotSpectrumBase::mRate
protected

◆ mSize

int PlotSpectrumBase::mSize
protected

Definition at line 31 of file PlotSpectrumBase.h.

Referenced by PlotSpectrumBase(), and FrequencyPlotDialog::Populate().

◆ mWindowSize

size_t PlotSpectrumBase::mWindowSize
protected

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