Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | List of all members
SpectralDataManager Class Reference

Performs the calculation for spectral editing. More...

#include <SpectralDataManager.h>

Classes

struct  Setting
 
class  Worker
 

Public Member Functions

 SpectralDataManager ()
 
 ~SpectralDataManager ()
 

Static Public Member Functions

static bool ProcessTracks (AudacityProject &project)
 
static int FindFrequencySnappingBin (const WaveChannel &channel, long long startSC, int hopSize, double threshold, int targetFreqBin)
 
static std::vector< int > FindHighestFrequencyBins (WaveChannel &wc, long long int startSC, int hopSize, double threshold, int targetFreqBin)
 

Detailed Description

Performs the calculation for spectral editing.

Definition at line 22 of file SpectralDataManager.h.

Constructor & Destructor Documentation

◆ SpectralDataManager()

SpectralDataManager::SpectralDataManager ( )
default

◆ ~SpectralDataManager()

SpectralDataManager::~SpectralDataManager ( )
default

Member Function Documentation

◆ FindFrequencySnappingBin()

int SpectralDataManager::FindFrequencySnappingBin ( const WaveChannel channel,
long long  startSC,
int  hopSize,
double  threshold,
int  targetFreqBin 
)
static

Definition at line 126 of file SpectralDataManager.cpp.

128{
129 Setting setting;
130 setting.mNeedOutput = false;
131 Worker worker{ nullptr, setting };
132
133 return worker.ProcessSnapping(
134 channel, startSC, hopSize, setting.mWindowSize, threshold, targetFreqBin);
135}
Definition: Prefs.h:178

References SpectralDataManager::Setting::mNeedOutput, and SpectralDataManager::Setting::mWindowSize.

Referenced by BrushHandle::Drag().

Here is the caller graph for this function:

◆ FindHighestFrequencyBins()

std::vector< int > SpectralDataManager::FindHighestFrequencyBins ( WaveChannel wc,
long long int  startSC,
int  hopSize,
double  threshold,
int  targetFreqBin 
)
static

Definition at line 137 of file SpectralDataManager.cpp.

142 {
143 Setting setting;
144 setting.mNeedOutput = false;
145 Worker worker{ nullptr, setting };
146
147 return worker.ProcessOvertones(wc, startSC, hopSize, setting.mWindowSize, threshold, targetFreqBin);
148 }

References SpectralDataManager::Setting::mNeedOutput, and SpectralDataManager::Setting::mWindowSize.

Referenced by BrushHandle::Drag().

Here is the caller graph for this function:

◆ ProcessTracks()

bool SpectralDataManager::ProcessTracks ( AudacityProject project)
static

Definition at line 56 of file SpectralDataManager.cpp.

56 {
58 int applyCount = 0;
59 Setting setting;
60 for (auto wt : tracks.Any<WaveTrack>()) {
61 using Type = long long;
62 Type startSample{ std::numeric_limits<Type>::max() };
64 for (auto pChannel : wt->Channels()) {
65 if (const auto pData = FindSpectralData(pChannel.get())) {
66 const auto &hopSize = pData->GetHopSize();
67 auto start = pData->GetStartSample();
68 endSample = std::max(endSample, pData->GetEndSample());
69
70 // Correct the start of range so that the first full window is
71 // centered at that position
72 start = std::max(static_cast<long long>(0), start - 2 * hopSize);
73 startSample = std::min(startSample, start);
74 }
75 }
76 if (startSample >= endSample)
77 continue;
78 const auto t0 = wt->LongSamplesToTime(startSample);
79 const auto len = endSample - startSample;
80 const auto tLen = wt->LongSamplesToTime(len);
81 auto tempTrack = wt->EmptyCopy();
82 auto iter = tempTrack->Channels().begin();
83 long long processed{};
84 for (auto pChannel : wt->Channels()) {
85 Worker worker{ (*iter++).get(), setting };
86 auto &view = ChannelView::Get(*pChannel);
87
88 if (auto waveChannelViewPtr = dynamic_cast<WaveChannelView*>(&view)){
89 for (const auto &subViewPtr : waveChannelViewPtr->GetAllSubViews()){
90 if (!subViewPtr->IsSpectral())
91 continue;
92 auto sView = std::static_pointer_cast<SpectrumView>(subViewPtr).get();
93 auto pSpectralData = sView->GetSpectralData();
94
95 if (!pSpectralData->dataHistory.empty()) {
96 // TODO make this correct in case start or end of spectral data in
97 // the channels differs
98 processed = std::max(processed, pSpectralData->GetLength());
99 worker.Process(*pChannel, pSpectralData);
100 applyCount += static_cast<int>(pSpectralData->dataHistory.size());
101 pSpectralData->clearAllData();
102 }
103 }
104 }
105 }
106 if (tempTrack) {
107 TrackSpectrumTransformer::PostProcess(*tempTrack, processed);
108 // Take the output track and insert it in place of the original
109 // sample data
110 // TODO make this correct in case start or end of spectral data in
111 // the channels differs
112 wt->ClearAndPaste(t0, t0 + tLen, *tempTrack, true, false);
113 }
114 }
115
116 if (applyCount) {
118 XO("Applied effect to selection"),
119 XO("Applied effect to selection"));
121 }
122
123 return applyCount > 0;
124}
int min(int a, int b)
XO("Cut/Copy/Paste")
const auto tracks
const auto project
static ChannelView & Get(Channel &channel)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static bool PostProcess(WaveTrack &outputTrack, sampleCount len)
Final flush and trimming of tail samples.
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
const std::shared_ptr< SpectralData > FindSpectralData(Channel *pChannel)

References anonymous_namespace{SpectralDataManager.cpp}::FindSpectralData(), ProjectHistory::Get(), TrackList::Get(), ChannelView::Get(), min(), ProjectHistory::ModifyState(), TrackSpectrumTransformer::PostProcess(), project, ProjectHistory::PushState(), tracks, and XO().

Referenced by SpectrumView::KeyDown().

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

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