Overte C++ Documentation
AudioFOA.h
1 //
2 // AudioFOA.h
3 // libraries/audio/src
4 //
5 // Created by Ken Cooke on 10/28/16.
6 // Copyright 2016 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_AudioFOA_h
13 #define hifi_AudioFOA_h
14 
15 #include <stdint.h>
16 
17 static const int FOA_TAPS = 273; // FIR coefs
18 static const int FOA_NFFT = 512; // FFT length
19 static const int FOA_OVERLAP = FOA_TAPS - 1;
20 static const int FOA_TABLES = 25; // number of HRTF subjects
21 
22 static const int FOA_BLOCK = 240; // block processing size
23 
24 static const float FOA_GAIN = 1.0f; // FOA global gain adjustment
25 
26 static_assert((FOA_BLOCK + FOA_OVERLAP) == FOA_NFFT, "FFT convolution requires L+M-1 == NFFT");
27 
28 class AudioFOA {
29 
30 public:
31  AudioFOA() {};
32 
33  //
34  // input: interleaved First-Order Ambisonic source
35  // output: interleaved stereo mix buffer (accumulates into existing output)
36  // index: HRTF subject index
37  // qw, qx, qy, qz: normalized quaternion for orientation
38  // gain: gain factor for volume control
39  // numFrames: must be FOA_BLOCK in this version
40  //
41  void render(int16_t* input, float* output, int index, float qw, float qx, float qy, float qz, float gain, int numFrames);
42 
43 private:
44  AudioFOA(const AudioFOA&) = delete;
45  AudioFOA& operator=(const AudioFOA&) = delete;
46 
47  // For best cache utilization when processing thousands of instances, only
48  // the minimum persistant state is stored here. No coefs or work buffers.
49 
50  // input history, for overlap-save
51  float _fftState[4][FOA_OVERLAP] = {};
52 
53  // orientation and gain history
54  float _rotationState[4][4] = {};
55 
56  bool _resetState = true;
57 };
58 
59 #endif // AudioFOA_h