Reduce FFT memory slightly
This commit is contained in:
parent
bc8a7fd65e
commit
241ba8d97d
@ -1,8 +1,11 @@
|
|||||||
all: out/stretch
|
all: out/stretch
|
||||||
|
|
||||||
out/stretch: ../signalsmith-stretch.h main.cpp util/*.h
|
out/stretch: ../signalsmith-stretch.h main.cpp util/*.h util/*.hxx ../dsp/*.h
|
||||||
mkdir -p out
|
mkdir -p out
|
||||||
g++ main.cpp -o out/stretch -std=c++11 -Ofast -g
|
g++ main.cpp -o out/stretch -std=c++11 -O3 -g
|
||||||
|
|
||||||
|
examples: out/stretch
|
||||||
|
inputs/run-all.sh out/d1- out/stretch --semitones=-1
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf out
|
rm -rf out
|
||||||
10
cmd/main.cpp
10
cmd/main.cpp
@ -1,5 +1,11 @@
|
|||||||
|
#include "util/memory-tracker.hxx"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#define LOG_EXPR(expr) std::cout << #expr << " = " << (expr) << "\n";
|
#define LOG_EXPR(expr) std::cout << #expr << " = " << (expr) << "\n";
|
||||||
|
std::ostream& operator<<(std::ostream& output, const signalsmith::MemoryTracker& memory) {
|
||||||
|
output << "{.allocBytes=" << memory.allocBytes << ", .freeBytes=" << memory.freeBytes << ", .current=" << memory.currentBytes << "}";
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
@ -7,8 +13,6 @@
|
|||||||
#include "util/simple-args.h"
|
#include "util/simple-args.h"
|
||||||
#include "util/wav.h"
|
#include "util/wav.h"
|
||||||
|
|
||||||
#include "util/memory-tracker.hxx"
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
SimpleArgs args(argc, argv);
|
SimpleArgs args(argc, argv);
|
||||||
|
|
||||||
@ -62,7 +66,7 @@ int main(int argc, char* argv[]) {
|
|||||||
stretch.process(inWav, inputLength, outWav, outputLength);
|
stretch.process(inWav, inputLength, outWav, outputLength);
|
||||||
|
|
||||||
processMemory = processMemory.diff();
|
processMemory = processMemory.diff();
|
||||||
if (processMemory.allocBytes + processMemory.freeBytes > 0) {
|
if (processMemory) {
|
||||||
std::cout << "Processing (alloc/free/current):\t" << processMemory.allocBytes << "/" << processMemory.freeBytes << "/" << processMemory.currentBytes << "\n";
|
std::cout << "Processing (alloc/free/current):\t" << processMemory.allocBytes << "/" << processMemory.freeBytes << "/" << processMemory.currentBytes << "\n";
|
||||||
args.errorExit("allocated during process()");
|
args.errorExit("allocated during process()");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,11 @@ struct MemoryTracker {
|
|||||||
MemoryTracker now;
|
MemoryTracker now;
|
||||||
return {now.allocBytes - allocBytes, now.freeBytes - freeBytes};
|
return {now.allocBytes - allocBytes, now.freeBytes - freeBytes};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is a `.diff()` result non-zero
|
||||||
|
operator bool() const {
|
||||||
|
return allocBytes > 0 || freeBytes > 0;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
MemoryTracker(size_t allocBytes, size_t freeBytes) : allocBytes(allocBytes), freeBytes(freeBytes), currentBytes(allocBytes - freeBytes) {}
|
MemoryTracker(size_t allocBytes, size_t freeBytes) : allocBytes(allocBytes), freeBytes(freeBytes), currentBytes(allocBytes - freeBytes) {}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -164,8 +164,10 @@ namespace signalsmith { namespace fft {
|
|||||||
plan.resize(0);
|
plan.resize(0);
|
||||||
twiddleVector.resize(0);
|
twiddleVector.resize(0);
|
||||||
addPlanSteps(0, 0, _size, 1);
|
addPlanSteps(0, 0, _size, 1);
|
||||||
|
twiddleVector.shrink_to_fit();
|
||||||
|
|
||||||
permutation.resize(0);
|
permutation.resize(0);
|
||||||
|
permutation.reserve(_size);
|
||||||
permutation.push_back(PermutationPair{0, 0});
|
permutation.push_back(PermutationPair{0, 0});
|
||||||
size_t indexLow = 0, indexHigh = factors.size();
|
size_t indexLow = 0, indexHigh = factors.size();
|
||||||
size_t inputStepLow = _size, outputStepLow = 1;
|
size_t inputStepLow = _size, outputStepLow = 1;
|
||||||
@ -524,7 +526,8 @@ namespace signalsmith { namespace fft {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return complexFft.setSize(size/2);
|
size_t result = complexFft.setSize(size/2);
|
||||||
|
return result*2;
|
||||||
}
|
}
|
||||||
size_t setFastSizeAbove(size_t size) {
|
size_t setFastSizeAbove(size_t size) {
|
||||||
return setSize(fastSizeAbove(size));
|
return setSize(fastSizeAbove(size));
|
||||||
|
|||||||
@ -170,6 +170,7 @@ namespace spectral {
|
|||||||
*/
|
*/
|
||||||
template<typename Sample>
|
template<typename Sample>
|
||||||
class STFT : public signalsmith::delay::MultiBuffer<Sample> {
|
class STFT : public signalsmith::delay::MultiBuffer<Sample> {
|
||||||
|
|
||||||
using Super = signalsmith::delay::MultiBuffer<Sample>;
|
using Super = signalsmith::delay::MultiBuffer<Sample>;
|
||||||
using Complex = std::complex<Sample>;
|
using Complex = std::complex<Sample>;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user