Audaspace  1.3.0
A high level audio library.
Convolver.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2015-2016 Juan Francisco Crespo Galán
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16 
17 #pragma once
18 
25 #include "FFTConvolver.h"
26 #include "util/ThreadPool.h"
27 #include "util/FFTPlan.h"
28 
29 #include <memory>
30 #include <vector>
31 #include <mutex>
32 #include <future>
33 #include <atomic>
34 #include <deque>
35 
41 {
42 private:
46  int m_N;
47 
51  int m_M;
52 
56  int m_L;
57 
61  std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> m_irBuffers;
62 
66  std::vector<fftwf_complex*> m_threadAccBuffers;
67 
71  std::vector<std::unique_ptr<FFTConvolver>> m_fftConvolvers;
72 
76  int m_numThreads;
77 
81  std::shared_ptr<ThreadPool> m_threadPool;
82 
86  std::vector<std::future<bool>> m_futures;
87 
91  std::mutex m_sumMutex;
92 
96  std::atomic_bool m_resetFlag;
97 
101  fftwf_complex* m_accBuffer;
102 
106  std::deque<fftwf_complex*> m_delayLine;
107 
111  int m_irLength;
112 
116  int m_tailCounter;
117 
121  bool m_eos;
122 
123  // delete copy constructor and operator=
124  Convolver(const Convolver&) = delete;
125  Convolver& operator=(const Convolver&) = delete;
126 
127 public:
128 
136  Convolver(std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> ir, int irLength, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan);
137 
138  virtual ~Convolver();
139 
149  void getNext(sample_t* inBuffer, sample_t* outBuffer, int& length, bool& eos);
150 
154  void reset();
155 
160  std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> getImpulseResponse();
161 
166  void setImpulseResponse(std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> ir);
167 
168 private:
169 
174  bool threadFunction(int id);
175 };
176 
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
The ThreadPool class.
The FFTConvolver class.
#define AUD_API
Used for exporting symbols in the shared library.
Definition: Audaspace.h:93
This class allows to convolve a sound with a very large impulse response.
Definition: Convolver.h:40
float sample_t
Sample type.(float samples)
Definition: Audaspace.h:126
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition: Audaspace.h:119
The FFTPlan class.