| 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 | #include "graph/graph_manager.h" |
| 6 | |
| 7 | namespace vraudio |
| 8 | { |
| 9 | |
| 10 | ResonanceAudio::ResonanceAudio(size_t num_channels, size_t frames_per_buffer, int sample_rate_hz) |
| 11 | { |
| 12 | api = CreateResonanceAudioApi(num_channels, frames_per_buffer, sample_rate_hz); |
| 13 | impl = static_cast<ResonanceAudioApiImpl *>(api); |
| 14 | } |
| 15 | |
| 16 | ResonanceAudio::~ResonanceAudio() |
| 17 | { |
| 18 | delete api; |
| 19 | } |
| 20 | |
| 21 | int ResonanceAudio::getAmbisonicOutput(const float *buffers[], const float *reverb[], int nChannels) |
| 22 | { |
| 23 | impl->ProcessNextBuffer(); |
| 24 | auto *buffer = impl->GetAmbisonicOutputBuffer(); |
| 25 | if (!buffer || nChannels != buffer->num_channels()) |
| 26 | return -1; |
| 27 | |
| 28 | for (int i = 0; i < nChannels; ++i) { |
| 29 | buffers[i] = buffer->begin()[i].begin(); |
| 30 | } |
| 31 | |
| 32 | if (roomEffectsEnabled) { |
| 33 | const vraudio::AudioBuffer *reverbBuffer = impl->GetReverbBuffer(); |
| 34 | for (int i = 0; i < 2; ++i) { |
| 35 | reverb[i] = reverbBuffer->begin()[i].begin(); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return buffer->num_frames(); |
| 40 | } |
| 41 | |
| 42 | } |
| 43 |
