| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only |
| 3 | #include "resonance_audio.h" |
| 4 | #include "graph/resonance_audio_api_impl.h" |
| 5 | |
| 6 | namespace vraudio |
| 7 | { |
| 8 | |
| 9 | ResonanceAudio::ResonanceAudio(size_t num_channels, size_t frames_per_buffer, int sample_rate_hz) |
| 10 | : api{ |
| 11 | CreateResonanceAudioApi(num_channels, frames_per_buffer, sample_rate_hz), |
| 12 | } |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | int ResonanceAudio::getAmbisonicOutput(const float *buffers[], const float *reverb[], int nChannels) |
| 17 | { |
| 18 | auto impl = static_cast<ResonanceAudioApiImpl *>(api.get()); |
| 19 | impl->ProcessNextBuffer(); |
| 20 | auto *buffer = impl->GetAmbisonicOutputBuffer(); |
| 21 | if (!buffer || nChannels != buffer->num_channels()) |
| 22 | return -1; |
| 23 | |
| 24 | for (int i = 0; i < nChannels; ++i) { |
| 25 | buffers[i] = buffer->begin()[i].begin(); |
| 26 | } |
| 27 | |
| 28 | if (roomEffectsEnabled) { |
| 29 | const vraudio::AudioBuffer *reverbBuffer = impl->GetReverbBuffer(); |
| 30 | for (int i = 0; i < 2; ++i) { |
| 31 | reverb[i] = reverbBuffer->begin()[i].begin(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return buffer->num_frames(); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 |
