1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_AMBISONICS_AMBISONIC_BINAURAL_DECODER_H_
18#define RESONANCE_AUDIO_AMBISONICS_AMBISONIC_BINAURAL_DECODER_H_
19
20#include <vector>
21
22#include "base/audio_buffer.h"
23#include "dsp/fft_manager.h"
24#include "dsp/partitioned_fft_filter.h"
25
26namespace vraudio {
27
28// Decodes an Ambisonic sound field, of an arbitrary order, to binaural stereo,
29// by performing convolution in the spherical harmonics domain. The order (hence
30// the number of channels) of the input must match the order (hence the number
31// of channels) of the spherical harmonic-encoded Head Related Impulse Responses
32// (HRIRs). Assumes that HRIRs are symmetric with respect to the sagittal plane.
33class AmbisonicBinauralDecoder {
34 public:
35 // Constructs an |AmbisonicBinauralDecoder| from an |AudioBuffer| containing
36 // spherical harmonic representation of HRIRs. The order of spherical
37 // harmonic-encoded HRIRs (hence the number of channels) must match the order
38 // of the Ambisonic sound field input.
39 //
40 // @param sh_hrirs |AudioBuffer| containing time-domain spherical harmonic
41 // encoded symmetric HRIRs.
42 // @param frames_per_buffer Number of frames in each input/output buffer.
43 // @param fft_manager Pointer to a manager to perform FFT transformations.
44 AmbisonicBinauralDecoder(const AudioBuffer& sh_hrirs,
45 size_t frames_per_buffer, FftManager* fft_manager);
46
47 // Processes an Ambisonic sound field input and outputs a binaurally decoded
48 // stereo buffer.
49 //
50 // @param input Input buffer to be processed.
51 // @param output Pointer to a stereo output buffer.
52 void Process(const AudioBuffer& input, AudioBuffer* output);
53
54 private:
55 // Manager for all FFT related functionality (not owned).
56 FftManager* const fft_manager_;
57
58 // Spherical Harmonic HRIR filter kernels.
59 std::vector<std::unique_ptr<PartitionedFftFilter>> sh_hrir_filters_;
60
61 // Frequency domain representation of the input signal.
62 PartitionedFftFilter::FreqDomainBuffer freq_input_;
63
64 // Temporary audio buffer to store the convolution output for asymmetric or
65 // symmetric spherical harmonic HRIR.
66 AudioBuffer filtered_input_;
67};
68
69} // namespace vraudio
70
71#endif // RESONANCE_AUDIO_AMBISONICS_AMBISONIC_BINAURAL_DECODER_H_
72

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.h