Audacity 3.2.0
Equalization48x.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5Equalization48x.h
6
7Intrinsics (SSE/AVX) and Threaded Equalization
8
9***********************************************************************/
10
11#ifndef __AUDACITY_EFFECT_EQUALIZATION48X__
12#define __AUDACITY_EFFECT_EQUALIZATION48X__
13
14#ifdef EXPERIMENTAL_EQ_SSE_THREADED
15
16#include <memory>
17
18#include <wx/thread.h> // to inherit
19#include <audacity/Types.h>
20class WaveTrack;
21using fft_type = float;
22
23#ifdef __AVX_ENABLED
24#define __MAXBUFFERCOUNT 8
25#else
26#define __MAXBUFFERCOUNT 4
27#endif
28
29// bitwise function selection
30// options are
31#define MATH_FUNCTION_ORIGINAL 0 // 0 original path
32#define MATH_FUNCTION_BITREVERSE_TABLE 1 // 1 SSE BitReverse Table
33#define MATH_FUNCTION_SIN_COS_TABLE 2 // 2 SSE SinCos Table
34#define MATH_FUNCTION_THREADED 4 // 4 SSE threaded no SinCos and no BitReverse buffer
35#define MATH_FUNCTION_SSE 8 // 8 SSE no SinCos and no BitReverse buffer
36#define MATH_FUNCTION_AVX 16
37#define MATH_FUNCTION_SEGMENTED_CODE 32
38
39struct free_simd {
40 void operator () (void*) const;
41};
42using simd_floats = std::unique_ptr< float[], free_simd >;
43
44// added by Andrew Hallendorff intrinsics processing
45enum EQBufferStatus
46{
47 BufferEmpty=0,
48 BufferReady,
49 BufferBusy,
50 BufferDone
51};
52
53class BufferInfo {
54public:
55 BufferInfo() { mBufferLength=0; mBufferStatus=BufferEmpty; mContiguousBufferSize=0; };
56 float* mBufferSouce[__MAXBUFFERCOUNT];
57 float* mBufferDest[__MAXBUFFERCOUNT];
58 size_t mBufferLength;
59 size_t mFftWindowSize;
60 size_t mFftFilterSize;
61 float* mScratchBuffer;
62 size_t mContiguousBufferSize;
63 EQBufferStatus mBufferStatus;
64};
65
66typedef struct {
67 int x64;
68 int MMX;
69 int SSE;
70 int SSE2;
71 int SSE3;
72 int SSSE3;
73 int SSE41;
74 int SSE42;
75 int SSE4a;
76 int AVX;
77 int XOP;
78 int FMA3;
79 int FMA4;
80} MathCaps;
81
83
84class EffectEqualization48x;
85
86static int EQWorkerCounter=0;
87
88class EQWorker : public wxThread {
89public:
90 EQWorker():wxThread(wxTHREAD_JOINABLE) {
91 mBufferInfoList=NULL;
92 mBufferInfoCount=0;
93 mMutex=NULL;
94 mEffectEqualization48x=NULL;
95 mExitLoop=false;
96 mThreadID=EQWorkerCounter++;
97 mProcessingType=4;
98 }
99 void SetData( BufferInfo* bufferInfoList, int bufferInfoCount, wxMutex *mutex, EffectEqualization48x *effectEqualization48x) {
100 mBufferInfoList=bufferInfoList;
101 mBufferInfoCount=bufferInfoCount;
102 mMutex=mutex;
103 mEffectEqualization48x=effectEqualization48x;
104 }
105 void ExitLoop() { // this will cause the thread to drop from the loops
106 mExitLoop=true;
107 }
108 void* Entry() override;
109 BufferInfo* mBufferInfoList;
110 int mBufferInfoCount, mThreadID;
111 wxMutex *mMutex;
112 EffectEqualization48x *mEffectEqualization48x;
113 bool mExitLoop;
114 int mProcessingType;
115};
116
117class EffectEqualization48x {
118
119public:
120
121 EffectEqualization48x();
122 virtual ~EffectEqualization48x();
123
124 static MathCaps *GetMathCaps();
125 static void SetMathPath(int mathPath);
126 static int GetMathPath();
127 static void AddMathPathOption(int mathPath);
128 static void RemoveMathPathOption(int mathPath);
129
130 bool Process(EffectEqualization* effectEqualization);
131 bool Benchmark(EffectEqualization* effectEqualization);
132private:
133 bool RunFunctionSelect(int flags, int count, WaveTrack * t, sampleCount start, sampleCount len);
134 bool TrackCompare();
135 bool DeltaTrack(WaveTrack * t, const WaveTrack * t2, sampleCount start, sampleCount len);
136 bool AllocateBuffersWorkers(int nThreads);
137 bool FreeBuffersWorkers();
138
139 bool ProcessTail(WaveTrack * t, WaveTrack * output, sampleCount start, sampleCount len);
140
141 bool ProcessBuffer(fft_type *sourceBuffer, fft_type *destBuffer, size_t bufferLength);
142 bool ProcessBuffer1x(BufferInfo *bufferInfo);
143 bool ProcessOne1x(int count, WaveTrack * t, sampleCount start, sampleCount len);
144 void Filter1x(size_t len, float *buffer, float *scratchBuffer);
145
146 bool ProcessBuffer4x(BufferInfo *bufferInfo);
147 bool ProcessOne4x(int count, WaveTrack * t, sampleCount start, sampleCount len);
148 bool ProcessOne1x4xThreaded(int count, WaveTrack * t, sampleCount start, sampleCount len, int processingType=4);
149 void Filter4x(size_t len, float *buffer, float *scratchBuffer);
150
151#ifdef __AVX_ENABLED
152 bool ProcessBuffer8x(BufferInfo *bufferInfo);
153 bool ProcessOne8x(int count, WaveTrack * t, sampleCount start, sampleCount len);
154 bool ProcessOne8xThreaded(int count, WaveTrack * t, sampleCount start, sampleCount len);
155 void Filter8x(size_t len, float *buffer, float *scratchBuffer);
156#endif
157
158 EffectEqualization* mEffectEqualization;
159 size_t mThreadCount;
160 size_t mFilterSize;
161 size_t mBlockSize;
162 size_t mWindowSize;
163 int mBufferCount;
164 size_t mWorkerDataCount;
165 size_t mBlocksPerBuffer;
166 size_t mScratchBufferSize;
167 size_t mSubBufferSize;
168 simd_floats mBigBuffer;
169 ArrayOf<BufferInfo> mBufferInfo;
170 wxMutex mDataMutex;
171 ArrayOf<EQWorker> mEQWorkers;
172 bool mThreaded;
173 bool mBenching;
174 friend EQWorker;
175 friend EffectEqualization;
176};
177
178#endif
179
180#endif
float fft_type
Definition: RealFFTf48x.h:6
This simplifies arrays of arrays, each array separately allocated with NEW[] But it might be better t...
Definition: MemoryX.h:29
An Effect that modifies volume in different frequency bands.
Definition: Equalization.h:24
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19