28 mInBuf(1, blockSize * 2),
29 mTmpBuf(1, blockSize * 2 + 8),
30 mOutBuf(2, blockSize * 2),
32 unsigned hrtfLength, winSize;
76 unsigned numFrames = outputBuffer.mNumFrames;
77 unsigned tmpBufPtr, tmpHRTFPtr = 0;
78 unsigned hrtfLength = hrtfDatabase->
hrtfLength();
79 unsigned hrtf2Use = hrtfLength /
LEN_DOWNS;
82 logMsg(
"BinauralPanner::nextBuffer");
84 if (outputBuffer.mNumChannels != 2) {
88 if (numFrames != mFramesPerBlock) {
90 "BinauralPanner::nextBuffer # frames %d wrong for HRTF size %d (use a block resizer).",
91 numFrames, mFramesPerBlock);
94 outputBuffer.zeroBuffers();
96 for (
unsigned i = 0; i < mSources.size(); i++) {
101 mInBuf.mNumFrames = winSize;
102 mInBuf.zeroBuffers();
103 mInBuf.mNumFrames = numFrames;
116 mInBuf.mNumFrames = winSize;
118 mInFFT.nextBuffer(mInBuf, mTmpBuf);
122 tcache->
mHRTF[mBlockInd] = tcache->
mHRTF[mBlockInd - 1];
124 tcache->
mHRTF[mBlockInd] = tcache->
mHRTF[mNumBlocks - 1];
128 tcache->
mHRTF[mBlockInd] = hrtfIndex;
139 tmpBufPtr = mBlockInd;
142 for (
unsigned j = 0; j < hrtf2Use; j++) {
148 cmac(in1j, inLj, outLj);
149 cmac(in1j, inRj, outRj);
154 if (++tmpBufPtr >= mNumBlocksToSum)
156 if (++tmpHRTFPtr >= mNumBlocksToSum)
158 }
while (tmpBufPtr != mBlockInd);
164 mTmpBuf.mNumFrames = winSize;
166 mOutBuf.setBuffer(0, mIFFTOutL);
168 mOutFFT.nextBuffer(mTmpBuf, mOutBuf);
171 mOutBuf.setBuffer(0, mIFFTOutR);
173 mOutFFT.nextBuffer(mTmpBuf, mOutBuf);
182 sample scale = 1.0f / (float) numFrames;
187 for (
unsigned j = 0; j < numFrames; j++) {
188 *outL++ += ((*ifftL++ + *cacheL++) * scale);
189 *outR++ += ((*ifftR++ + *cacheR++) * scale);
192 memcpy(tcache->
mPrevOutL, mIFFTOutL + numFrames, numFrames *
sizeof(
sample));
193 memcpy(tcache->
mPrevOutR, mIFFTOutR + numFrames, numFrames *
sizeof(
sample));
198 mBlockInd = mNumBlocksToSum;
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
void logMsg(const char *format,...)
These are the public logging messages.
SampleComplex * SampleComplexVector
complex vector
SampleComplexVector * mHrtfR
2 arrays of arrays of mNumFFTBlocks * complex[513]: the HRTF data in blocks of complex # for stereo ...
static HRTFDatabase * Database()
accessor for the singleton instance (lazy init)
SampleComplexVector * mInSpect
complex spectra of mNumBlocks past inputs
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
unsigned numBlocks()
The length (in windows) of the impulse responses loaded.
SampleBuffer mIFFTOutR
outputs of the IFFT
unsigned hrtfLength()
The length (in samples) of the Transfer Function buffer.
BinauralSourceCache(BinauralPanner *parent)
BinauralPanner(unsigned blockSize=HRTF_BLOCK_SIZE)
#define ComplexPtr
shorthand
void nextBuffer(Buffer &outputBuffer)
work-horse method reads & transforms input, sums previous data, and takes the IFFT for each of multip...
unsigned mNumBlocks
size of caches (16)
SampleBuffer mPrevOutR
previous sample window from the IFFT
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
unsigned windowSize()
The size of the analysis window (in samples).
#define cmac(in1, in2, out)
CPoint * position(unsigned channelNum=0)
Returns the distance from the center.
Base class for all panners. Handles source management and holds a speaker layout. ...
#define SUM_DOWNS
Binaural.h – Specification of the HRTF-based binaural spatializer. This is the CSL 5 version that us...
unsigned mNumBlocksToSum
blocks to include in sum per HRTF
HRTFDatabase: has a vector of HRTFs and can access them by position – hrtfAt(CPoint) – or by index ...
Temp Spatial Sound Source.
float sample
(could be changed to int, or double)
void * cache()
Returns an instance of its cache data per sound source.
BufferContentType mType
Data type flag set the internal size variables (no buffer allocation takes place) ...
HRTF: holds the data that corresponds to an HRTF for a single position. It has a list of complex buff...
virtual bool isActive()
query whether I'm currently active (Envelopes can go inactive)
BinauralSourceCache: used for caching previous state of spatial sources. This has the history of inpu...
unsigned mNumBlocks
blocks per HRTF
SampleComplexVector * mHrtfL
virtual bool positionChanged()
Returns whether the sound source position changed since last block call.
unsigned hrtfAt(CPoint srcPos)
answer the index of the HRTF nearest the given point
unsigned mFramesPerBlock
frames per block
void setCopyPolicy(BufferCopyPolicy ch)
get/set the receiver's buffer copy policy
FFT complex spectral frames.
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
ignore extra buffer channels
void allocateBuffers()
fcn to malloc storage buffers
SampleComplexVector mHOutR
buffers for the mixed HRTF & input data pre-IFFT
unsigned * mHRTF
list of block IDs of the "split" hrtf
void setNumChannels(unsigned ch)
get/set the receiver's number of outputs
SampleComplexVector mHOutL
sample SampleComplex[2]
array-of-2 complex # type (like FFTW)
#define SAFE_MALLOC(ptr, type, len)
Useful Macros.
Base class of CSL exceptions (written upper-case). Has a string message.