CSL  6.0
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);
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  FFT_Wrapper mInFFT; ///< FFT Wrappers for in and out processing
65  FFT_Wrapper 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 
81 public:
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
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
SampleComplex * SampleComplexVector
complex vector
Definition: CSL_Types.h:202
SampleComplexVector * mInSpect
complex spectra of mNumBlocks past inputs
Definition: Binaural.h:85
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
SampleBuffer mIFFTOutR
outputs of the IFFT
Definition: Binaural.h:70
forward declaration
Definition: Binaural.h:49
#define HRTF_BLOCK_SIZE
BinauralDB.h – Specification of the HRTF file format and database This is the CSL 5 version that use...
Definition: BinauralDB.h:65
BinauralSourceCache(BinauralPanner *parent)
Definition: Binaural.cpp:205
SampleBuffer mIFFTOutL
Definition: Binaural.h:70
BinauralPanner(unsigned blockSize=HRTF_BLOCK_SIZE)
Definition: Binaural.cpp:23
SampleBuffer mPrevOutL
Definition: Binaural.h:86
void nextBuffer(Buffer &outputBuffer)
work-horse method reads & transforms input, sums previous data, and takes the IFFT for each of multip...
Definition: Binaural.cpp:73
unsigned mNumBlocks
size of caches (16)
Definition: Binaural.h:88
SampleBuffer mPrevOutR
previous sample window from the IFFT
Definition: Binaural.h:86
unsigned mBlockInd
block index
Definition: Binaural.h:72
Base class for all panners. Handles source management and holds a speaker layout. ...
Definition: SpatialPanner.h:22
unsigned mNumBlocksToSum
blocks to include in sum per HRTF
Definition: Binaural.h:60
void * cache()
Returns an instance of its cache data per sound source.
Definition: Binaural.cpp:65
BinauralSourceCache: used for caching previous state of spatial sources. This has the history of inpu...
Definition: Binaural.h:80
unsigned mNumBlocks
blocks per HRTF
Definition: Binaural.h:59
unsigned mFramesPerBlock
frames per block
Definition: Binaural.h:61
FFT_Wrapper mInFFT
FFT Wrappers for in and out processing.
Definition: Binaural.h:64
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
FFT_Wrapper mOutFFT
Definition: Binaural.h:65
SampleComplexVector mHOutR
buffers for the mixed HRTF & input data pre-IFFT
Definition: Binaural.h:69
unsigned * mHRTF
list of block IDs of the "split" hrtf
Definition: Binaural.h:87
SampleComplexVector mHOutL
Definition: Binaural.h:69
Buffer mOutBuf
temp buffers for input and FFT wrappers
Definition: Binaural.h:67
Base class of CSL exceptions (written upper-case). Has a string message.