CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Binaural.h
Go to the documentation of this file.
1 ///
2 /// Binaural.h -- Specification of the HRTF-based binaural spatializer.
3 /// This is the CSL 5 version that uses the FFT wrapper framework
4 ///
5 /// Classes
6 /// BinauralPanner: place sources in 3D using block-wise convolution with an HRTF;
7 /// best heard over headphones. Supports multiple moving sources and does cached
8 /// multi-block FFT/IFFT convolution.
9 ///
10 /// BinauralSourceCache: used for caching previous state of spatial sources.
11 ///
12 /// The companion file has the classes
13 /// HRTF: holds the data that corresponds to an HRTF for a single position.
14 /// HRTFDatabase: vector of HRTFs; implemented as a Singleton because it's large.
15 ///
16 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
17 /// Created by Jorge Castellanos on 7/19/06.
18 /// Inspired by and partially based on the VST HRTF Plug-in written by Ryan Avery.
19 /// Rewritten for FFT wrappers and pluggable sound file APIs in 8/09 by STP.
20 ///
21 /// @todo HRTFs should be equalized, currently they are being loaded and used raw.
22 /// @todo Interpolation of HRTFs. Currently the closest HRTF is being used.
23 ///
24
25 #ifndef CSL_BINAURAL_H
26 #define CSL_BINAURAL_H
27
28 #include "BinauralDB.h"
29
30 #ifdef IPHONE
31 #define SUM_DOWNS 1 // scale # blocks to sum (16 / SUM_DOWNS)
32 #define FFT_DOWNS 2 // scale IFFT len (FFT_DOWNS * blockSize)
33 #define LEN_DOWNS 1 // scale sum len (513 / LEN_DOWNS)
34 #else
35 #define SUM_DOWNS 1 // scale # blocks to sum (16 / SUM_DOWNS)
36 #define FFT_DOWNS 2 // scale IFFT len (FFT_DOWNS * blockSize)
37 #define LEN_DOWNS 1 // scale sum len (513 / LEN_DOWNS)
38 #endif
39
40 namespace csl {
41
42 class BinauralSourceCache; ///< forward declaration
43
44 /// BinauralPanner: place sources in 3D using block-wise convolution with an HRTF.
45 /// The HRIRs (Head Related Impulse Responses) are loaded by the HRTFDatabase.
46 /// The binaural panner uses these HRTFs and processes the incoming audio by
47 /// frequency domain convolution in blocks of 512 samples.
48
49 class BinauralPanner : public SpatialPanner {
50
51 public:
52 BinauralPanner(unsigned blockSize = HRTF_BLOCK_SIZE);
53 ~BinauralPanner();
54 /// work-horse method reads & transforms input,
55 /// sums previous data, and takes the IFFT for
56 /// each of multiple sources
57 void nextBuffer(Buffer &outputBuffer) throw (CException);
58
59 unsigned mNumBlocks; ///< # blocks per HRTF
60 unsigned mNumBlocksToSum; ///< # blocks to include in sum per HRTF
61 unsigned mFramesPerBlock; ///< # frames per block
62
63 protected:
64 FFTWrapper mInFFT; ///< FFT Wrappers for in and out processing
65 FFTWrapper mOutFFT;
66
67 Buffer mInBuf, mTmpBuf, mOutBuf; ///< temp buffers for input and FFT wrappers
68
69 SampleComplexVector mHOutL, mHOutR; ///< buffers for the mixed HRTF & input data pre-IFFT
70 SampleBuffer mIFFTOutL, mIFFTOutR; ///< outputs of the IFFT
71
72 unsigned mBlockInd; ///< block index
73 void * cache(); ///< Returns an instance of its cache data per sound source
74 };
75
76
77 /// BinauralSourceCache: used for caching previous state of spatial sources.
78 /// This has the history of input FFTs and the last output sample block for OLA
79
80 class BinauralSourceCache {
81 public:
82 BinauralSourceCache(BinauralPanner *parent);
83 ~BinauralSourceCache();
84
85 SampleComplexVector *mInSpect; ///< complex spectra of mNumBlocks past inputs
86 SampleBuffer mPrevOutL, mPrevOutR; ///< previous sample window from the IFFT
87 unsigned *mHRTF; ///< list of block IDs of the "split" hrtf
88 unsigned mNumBlocks; ///< size of caches (16)
89 };
90
91 } // end namespace
92
93 #endif