MCPcopy Create free account
hub / github.com/audacity/audacity / GetAudio

Method GetAudio

libraries/lib-builtin-effects/PlotSpectrumBase.cpp:36–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36bool PlotSpectrumBase::GetAudio()
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;
68 ShowMessageBox(
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,
81 FillFormat::fillZero, false))
82 {
83 using namespace BasicUI;
84 ShowMessageBox(
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 {

Callers

nothing calls this directly

Calls 9

GetFunction · 0.85
ShowMessageBoxFunction · 0.85
TimeToLongSamplesMethod · 0.80
as_size_tMethod · 0.80
resetMethod · 0.45
GetRateMethod · 0.45
NChannelsMethod · 0.45
getMethod · 0.45
GetFloatsMethod · 0.45

Tested by

no test coverage detected