Audaspace  1.3.0
A high level audio library.
BinauralReader.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 "IReader.h"
26 #include "ISound.h"
27 #include "Convolver.h"
28 #include "HRTF.h"
29 #include "Source.h"
30 #include "util/FFTPlan.h"
31 #include "util/ThreadPool.h"
32 
33 #include <memory>
34 #include <vector>
35 #include <future>
36 
38 
43 {
44 private:
48  int m_position;
49 
53  std::shared_ptr<IReader> m_reader;
54 
58  std::shared_ptr<HRTF> m_hrtfs;
59 
63  std::shared_ptr<Source> m_source;
64 
68  float m_Azimuth;
69 
73  float m_Elevation;
74 
78  float m_RealAzimuth;
79 
83  float m_RealElevation;
84 
88  int m_N;
89 
93  int m_M;
94 
98  int m_L;
99 
103  std::vector<std::unique_ptr<Convolver>> m_convolvers;
104 
108  bool m_transition;
109 
113  int m_transPos;
114 
118  sample_t* m_outBuffer;
119 
123  sample_t* m_inBuffer;
124 
128  int m_outBufferPos;
129 
133  int m_outBufLen;
134 
138  int m_eOutBufLen;
139 
143  bool m_eosReader;
144 
148  bool m_eosTail;
149 
153  std::vector<sample_t*> m_vecOut;
154 
158  std::shared_ptr<ThreadPool> m_threadPool;
159 
163  int m_lastLengthIn;
164 
168  std::vector<std::future<int>> m_futures;
169 
170  // delete copy constructor and operator=
171  BinauralReader(const BinauralReader&) = delete;
172  BinauralReader& operator=(const BinauralReader&) = delete;
173 
174 public:
184  BinauralReader(std::shared_ptr<IReader> reader, std::shared_ptr<HRTF> hrtfs, std::shared_ptr<Source> source, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan);
185  virtual ~BinauralReader();
186 
187  virtual bool isSeekable() const;
188  virtual void seek(int position);
189  virtual int getLength() const;
190  virtual int getPosition() const;
191  virtual Specs getSpecs() const;
192  virtual void read(int& length, bool& eos, sample_t* buffer);
193 
194 private:
202  void joinByChannel(int start, int len, int nConvolvers);
203 
208  void loadBuffer(int nConvolvers);
209 
218  int threadFunction(int id, bool input);
219 
220  bool checkSource();
221 };
222 
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition: Audaspace.h:119
float sample_t
Sample type.(float samples)
Definition: Audaspace.h:126
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
#define AUD_API
Used for exporting symbols in the shared library.
Definition: Audaspace.h:93
The Convolver class.
The FFTPlan class.
The HRTF class.
The IReader interface.
The ISound interface.
The Source class.
The ThreadPool class.
This class represents a reader for a sound that can sound different depending on its realtive positio...
Definition: BinauralReader.h:43
BinauralReader(std::shared_ptr< IReader > reader, std::shared_ptr< HRTF > hrtfs, std::shared_ptr< Source > source, std::shared_ptr< ThreadPool > threadPool, std::shared_ptr< FFTPlan > plan)
Creates a new convolver reader.
virtual bool isSeekable() const
Tells whether the source provides seeking functionality or not.
virtual Specs getSpecs() const
Returns the specification of the reader.
virtual int getPosition() const
Returns the position of the source as a sample count value.
virtual void seek(int position)
Seeks to a specific position in the source.
virtual int getLength() const
Returns an approximated length of the source in samples.
virtual void read(int &length, bool &eos, sample_t *buffer)
Request to read the next length samples out of the source.
This class represents a sound source as stream or as buffer which can be read for example by another ...
Definition: IReader.h:35
Specification of a sound source.
Definition: Specification.h:110