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 (WaveTrack *wt, 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 127 of file SpectralDataManager.cpp.

129{
130 Setting setting;
131 setting.mNeedOutput = false;
132 Worker worker{ nullptr, setting };
133
134 return worker.ProcessSnapping(
135 channel, startSC, hopSize, setting.mWindowSize, threshold, targetFreqBin);
136}
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 ( WaveTrack wt,
long long int  startSC,
int  hopSize,
double  threshold,
int  targetFreqBin 
)
static

Definition at line 138 of file SpectralDataManager.cpp.

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

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 tempList = wt->WideEmptyCopy();
82 auto iter = (*tempList->Any<WaveTrack>().begin())->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 (!tempList->empty()) {
107 const auto pTrack = *tempList->Any<WaveTrack>().begin();
108 TrackSpectrumTransformer::PostProcess(*pTrack, processed);
109 // Take the output track and insert it in place of the original
110 // sample data
111 // TODO make this correct in case start or end of spectral data in
112 // the channels differs
113 wt->ClearAndPaste(t0, t0 + tLen, *tempList, true, false);
114 }
115 }
116
117 if (applyCount) {
119 XO("Applied effect to selection"),
120 XO("Applied effect to selection"));
122 }
123
124 return applyCount > 0;
125}
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:347
static bool PostProcess(WaveTrack &outputTrack, sampleCount len)
Final flush and trimming of tail samples.
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
const std::shared_ptr< SpectralData > FindSpectralData(Channel *pChannel)

References PackedArray::begin(), 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: