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_GRAPH_AMBISONIC_BINAURAL_DECODER_NODE_H_
18#define RESONANCE_AUDIO_GRAPH_AMBISONIC_BINAURAL_DECODER_NODE_H_
19
20#include <memory>
21#include <string>
22
23#include "ambisonics/ambisonic_binaural_decoder.h"
24#include "base/audio_buffer.h"
25#include "dsp/fft_manager.h"
26#include "dsp/resampler.h"
27#include "graph/system_settings.h"
28#include "node/processing_node.h"
29#include "utils/buffer_crossfader.h"
30
31namespace vraudio {
32
33// Node that takes an ambisonic soundfield as input and renders a binaural
34// stereo buffer as output.
35class AmbisonicBinauralDecoderNode : public ProcessingNode {
36 public:
37 // Initializes AmbisonicBinauralDecoderNode class.
38 //
39 // @param system_settings Global system configuration.
40 // @param ambisonic_order Ambisonic order.
41 // @param sh_hrir_filename Filename to load the HRIR data from.
42 // @param fft_manager Pointer to a manager to perform FFT transformations.
43 // @resampler Pointer to a resampler used to convert HRIRs to the system rate.
44 AmbisonicBinauralDecoderNode(const SystemSettings& system_settings,
45 int ambisonic_order,
46 const std::string& sh_hrir_filename,
47 FftManager* fft_manager, Resampler* resampler);
48
49 ~AmbisonicBinauralDecoderNode() override;
50
51 protected:
52 // Implements ProcessingNode.
53 const AudioBuffer* AudioProcess(const NodeInput& input) override;
54
55 private:
56 const SystemSettings& system_settings_;
57
58 // Number of Ambisonic channels.
59 const size_t num_ambisonic_channels_;
60
61 // Denotes if the stereo speaker mode is enabled.
62 bool is_stereo_speaker_mode_;
63
64 // Ambisonic decoder used to render binaural output.
65 std::unique_ptr<AmbisonicBinauralDecoder> ambisonic_binaural_decoder_;
66
67 size_t num_frames_processed_on_empty_input_;
68
69 // Stereo output buffer.
70 AudioBuffer stereo_output_buffer_;
71
72 // Silence mono buffer to render reverb tails.
73 AudioBuffer silence_input_buffer_;
74
75 // Buffer crossfader to apply linear crossfade when the stereo speaker mode is
76 // changed.
77 BufferCrossfader crossfader_;
78
79 // Stereo output buffer to store the crossfaded decode output when necessary.
80 AudioBuffer crossfaded_output_buffer_;
81
82 // Temporary crossfade buffer to store the intermediate stereo output.
83 AudioBuffer temp_crossfade_buffer_;
84};
85
86} // namespace vraudio
87
88#endif // RESONANCE_AUDIO_GRAPH_AMBISONIC_BINAURAL_DECODER_NODE_H_
89

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.h