MCPcopy Create free account
hub / github.com/andrewreeman/SpectralSuite / setNumOverlaps

Method setNumOverlaps

shared/SpectralAudioProcessorInteractor.cpp:95–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95void SpectralAudioProcessorInteractor::setNumOverlaps(int newOverlapCount) {
96 int newOverlapCallCount = (m_setOverlapsCallCount + 1) % 100;
97 m_setOverlapsCallCount = newOverlapCallCount;
98
99 if (newOverlapCount < 1 ||newOverlapCount > 8) {
100 return;
101 }
102
103 if (m_spectralProcess.size() == (size_t)m_numChans && m_numChans > 0) {
104 if (m_spectralProcess.at(0).size() == (size_t)newOverlapCount)
105 {
106 if (m_numOverlaps != newOverlapCount)
107 {
108 m_numOverlaps = newOverlapCount;
109 }
110
111 return;
112 }
113 }
114
115 if (m_setOverlapsCallCount != newOverlapCallCount) { /* race detected */ return;}
116
117 m_numOverlaps = newOverlapCount;
118 m_fftHopSize = getFftSize() / m_numOverlaps;
119
120 for (auto& processesPerChannel : m_spectralProcess) {
121 if (!processesPerChannel.empty())
122 {
123 if (m_setOverlapsCallCount != newOverlapCallCount) { /* race detected */ return;}
124 processesPerChannel.clear();
125 }
126 }
127
128 // TODO: sometimes this is called from the fft switcher thread and we being destroyed while creating new allocations
129 // If spectral process is empty then we may be destroyed and should not clear the buffer. Using a lock instead may prevent us needing to do these hacky checks
130 if (!m_spectralProcess.empty())
131 {
132 if (m_setOverlapsCallCount != newOverlapCallCount) { /* race detected */ return;}
133 m_spectralProcess.clear();
134 }
135
136 for (size_t chan = 0; chan < (size_t)m_numChans; ++chan) {
137 if (m_setOverlapsCallCount != newOverlapCallCount) { /* race detected */ return;}
138 m_spectralProcess.push_back(std::vector<std::unique_ptr<StandardFFTProcessor>>());
139
140 for (int specProcess = 0; specProcess < m_numOverlaps; specProcess++) {
141 // TODO: sometimes this is called from the fft switcher thread and we being destroyed while creating new allocations
142 // If spectral process is empty then we should not continue here. Using a lock instead may prevent us needing to do these hacky checks
143 if (m_spectralProcess.empty())
144 {
145 return;
146 }
147
148 if (m_setOverlapsCallCount != newOverlapCallCount) { /* race detected */ return;}
149
150 m_spectralProcess.at(chan).push_back(
151 createSpectralProcess(specProcess, m_fftSize, m_fftHopSize, m_sampleRate, m_numOverlaps, (int)chan, m_numChans)
152 );

Callers 1

switchOverlapCountMethod · 0.80

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected