Skip to content

Commit 60cecd8

Browse files
Copilotddennedy
andauthored
Update spatialaudio module for libspatialaudio 0.4.0 API
- Require libspatialaudio >= 0.4.0 in pkg_check_modules - Add 'using namespace spaudio' for the new namespace - Rename class prefixes: CAmbisonicX -> AmbisonicX, CBFormat -> BFormat - Update AmbisonicDecoder::Configure to include sampleRate parameter - Update AmbisonicEncoder::Configure signature (sampleRate, fadeTime) - Update AmbisonicZoomer::Configure to pass sampleRate - Replace PolarPoint with PolarPosition<float> and update field names - Use Orientation constructor instead of aggregate initialization - Use scoped enum Amblib_SpeakerSetUps for speaker layout constants - Remove gain parameter from AmbisonicEncoder::SetPosition Agent-Logs-Url: https://github.com/mltframework/mlt/sessions/c98c5021-60b6-49ce-bc41-77f91e8cfce0 Co-authored-by: ddennedy <1146683+ddennedy@users.noreply.github.com>
1 parent 4736abc commit 60cecd8

3 files changed

Lines changed: 35 additions & 26 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ if(MOD_SOX)
384384
endif()
385385

386386
if(MOD_SPATIALAUDIO)
387-
pkg_check_modules(spatialaudio REQUIRED IMPORTED_TARGET spatialaudio)
387+
pkg_check_modules(spatialaudio REQUIRED IMPORTED_TARGET spatialaudio>=0.4.0)
388388
list(APPEND MLT_SUPPORTED_COMPONENTS spatialaudio)
389389
endif()
390390

src/modules/spatialaudio/filter_ambisonic-decoder.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* filter_ambisonic-decoder.cpp -- decode ambisonic audio to speaker channels
3-
* Copyright (C) 2024 Meltytech, LLC
3+
* Copyright (C) 2024-2026 Meltytech, LLC
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,8 @@
2020
#include <framework/mlt.h>
2121
#include <spatialaudio/Ambisonics.h>
2222

23+
using namespace spaudio;
24+
2325
static const auto MAX_CHANNELS = 6;
2426
static const auto AMBISONICS_BLOCK_SIZE = 1024;
2527
static const auto AMBISONICS_ORDER = 1;
@@ -34,11 +36,11 @@ class SpatialAudio
3436
{
3537
private:
3638
mlt_filter m_filter;
37-
CAmbisonicBinauralizer binauralizer;
39+
AmbisonicBinauralizer binauralizer;
3840
unsigned tailLength;
39-
CAmbisonicDecoder decoder;
40-
CAmbisonicProcessor processor;
41-
CAmbisonicZoomer zoomer;
41+
AmbisonicDecoder decoder;
42+
AmbisonicProcessor processor;
43+
AmbisonicZoomer zoomer;
4244
float *speakers[MAX_CHANNELS];
4345

4446
public:
@@ -72,15 +74,15 @@ class SpatialAudio
7274
{
7375
bool error = false;
7476
bool binaural = channels >= 2 && mlt_properties_get_int(properties(), "binaural");
77+
int sampleRate = mlt_properties_get_int(MLT_FRAME_PROPERTIES(frame), "audio_frequency");
7578

7679
// First time setup
7780
if (binaural && !binauralizer.GetChannelCount()) {
7881
mlt_log_verbose(MLT_FILTER_SERVICE(filter()),
7982
"configuring spatial audio binauralizer\n");
8083
error = !binauralizer.Configure(AMBISONICS_ORDER,
8184
true,
82-
mlt_properties_get_int(MLT_FRAME_PROPERTIES(frame),
83-
"audio_frequency"),
85+
sampleRate,
8486
samples,
8587
tailLength);
8688
if (!error) {
@@ -96,10 +98,11 @@ class SpatialAudio
9698
error = !decoder.Configure(AMBISONICS_ORDER,
9799
true,
98100
AMBISONICS_BLOCK_SIZE,
99-
channels == 6 ? kAmblib_51
100-
: channels == 2 ? kAmblib_Stereo
101-
: channels == 4 ? kAmblib_Quad
102-
: kAmblib_CustomSpeakerSetUp,
101+
sampleRate,
102+
channels == 6 ? Amblib_SpeakerSetUps::kAmblib_51
103+
: channels == 2 ? Amblib_SpeakerSetUps::kAmblib_Stereo
104+
: channels == 4 ? Amblib_SpeakerSetUps::kAmblib_Quad
105+
: Amblib_SpeakerSetUps::kAmblib_CustomSpeakerSetUp,
103106
channels);
104107
if (!error) {
105108
mlt_log_verbose(MLT_FILTER_SERVICE(filter()),
@@ -108,7 +111,10 @@ class SpatialAudio
108111
if (!error) {
109112
mlt_log_verbose(MLT_FILTER_SERVICE(filter()),
110113
"configuring spatial audio zoomer\n");
111-
error = !zoomer.Configure(AMBISONICS_ORDER, true, AMBISONICS_BLOCK_SIZE, 0);
114+
error = !zoomer.Configure(AMBISONICS_ORDER,
115+
true,
116+
AMBISONICS_BLOCK_SIZE,
117+
sampleRate);
112118
if (error) {
113119
mlt_log_error(MLT_FILTER_SERVICE(filter()),
114120
"failed to configure spatial audio zoomer\n");
@@ -125,17 +131,17 @@ class SpatialAudio
125131

126132
// Processing
127133
if (!error) {
128-
CBFormat bformat;
134+
BFormat bformat;
129135
bformat.Configure(AMBISONICS_ORDER, true, samples);
130136
for (unsigned i = 0; i < AMBISONICS_1_CHANNELS; ++i)
131137
bformat.InsertStream(&buffer[samples * i], i, samples);
132138

133139
if (!binaural) {
134140
mlt_position position = mlt_filter_get_position(filter(), frame);
135141
mlt_position length = mlt_filter_get_length2(filter(), frame);
136-
processor.SetOrientation({-DegreesToRadians(getDouble("yaw", position, length)),
137-
DegreesToRadians(getDouble("pitch", position, length)),
138-
DegreesToRadians(getDouble("roll", position, length))});
142+
processor.SetOrientation(Orientation(-DegreesToRadians(getDouble("yaw", position, length)),
143+
DegreesToRadians(getDouble("pitch", position, length)),
144+
DegreesToRadians(getDouble("roll", position, length))));
139145
processor.Refresh();
140146
processor.Process(&bformat, samples);
141147
zoomer.SetZoom(getDouble("zoom", position, length));

src/modules/spatialaudio/filter_ambisonic-encoder.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* filter_ambisonic-encoder.cpp -- position mono and stero sound in ambisonic space
3-
* Copyright (C) 2024 Meltytech, LLC
3+
* Copyright (C) 2024-2026 Meltytech, LLC
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,8 @@
2020
#include <framework/mlt.h>
2121
#include <spatialaudio/Ambisonics.h>
2222

23+
using namespace spaudio;
24+
2325
// static const auto MAX_CHANNELS = 6;
2426
static const auto AMBISONICS_ORDER = 1;
2527
static const auto AMBISONICS_1_CHANNELS = 4;
@@ -33,7 +35,7 @@ class SpatialAudioEncoder
3335
{
3436
private:
3537
mlt_filter m_filter;
36-
CAmbisonicEncoder encoder;
38+
AmbisonicEncoder encoder;
3739

3840
public:
3941
SpatialAudioEncoder()
@@ -69,7 +71,8 @@ class SpatialAudioEncoder
6971
// First time setup
7072
if (!encoder.GetOrder()) {
7173
mlt_log_verbose(MLT_FILTER_SERVICE(filter()), "configuring spatial audio encoder\n");
72-
error = !encoder.Configure(AMBISONICS_ORDER, true, 0);
74+
int sampleRate = mlt_properties_get_int(MLT_FRAME_PROPERTIES(frame), "audio_frequency");
75+
error = !encoder.Configure(AMBISONICS_ORDER, true, sampleRate, 0.f);
7376
if (error) {
7477
mlt_log_error(MLT_FILTER_SERVICE(filter()),
7578
"failed to configure spatial audio encoder\n");
@@ -78,16 +81,16 @@ class SpatialAudioEncoder
7881

7982
// Processing
8083
if (!error) {
81-
CBFormat bformat;
82-
PolarPoint polar;
84+
BFormat bformat;
85+
PolarPosition<float> polar;
8386
mlt_position position = mlt_filter_get_position(filter(), frame);
8487
mlt_position length = mlt_filter_get_length2(filter(), frame);
8588

8689
bformat.Configure(AMBISONICS_ORDER, true, samples);
87-
polar.fAzimuth = -DegreesToRadians(getDouble("azimuth", position, length));
88-
polar.fElevation = DegreesToRadians(getDouble("elevation", position, length));
89-
polar.fDistance = getDouble("distance", position, length);
90-
encoder.SetPosition(polar, 1.f);
90+
polar.azimuth = -DegreesToRadians(getDouble("azimuth", position, length));
91+
polar.elevation = DegreesToRadians(getDouble("elevation", position, length));
92+
polar.distance = getDouble("distance", position, length);
93+
encoder.SetPosition(polar);
9194
encoder.Refresh();
9295
encoder.Process(buffer, samples, &bformat);
9396
for (int i = 0; i < AMBISONICS_1_CHANNELS; ++i)

0 commit comments

Comments
 (0)