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