Skip to content

Commit

Permalink
ambisonic-decoder needs independent channel layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Feb 14, 2024
1 parent 0950c6c commit 0b50c22
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/modules/spatialaudio/filter_ambisonic-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SpatialAudio
if (!error) {
CBFormat bformat;
bformat.Configure(1, true, samples);
for (unsigned i = 0; i < 4; ++i)
for (unsigned i = 0; i < AMBISONICS_1_CHANNELS; ++i)
bformat.InsertStream(&buffer[samples * i], i, samples);

mlt_position position = mlt_filter_get_position(filter(), frame);
Expand Down Expand Up @@ -142,8 +142,20 @@ static int get_audio(mlt_frame frame,
if (*channels > 1) {
*format = mlt_audio_float;
int requestChannels = MAX(AMBISONICS_1_CHANNELS, *channels);
auto properties = MLT_FRAME_PROPERTIES(frame);
auto channel_layout = mlt_audio_channel_layout_id(
mlt_properties_get(properties, "consumer.channel_layout"));
mlt_properties_set(MLT_FRAME_PROPERTIES(frame),
"consumer.channel_layout",
mlt_audio_channel_layout_name(mlt_channel_independent));

error = mlt_frame_get_audio(frame, buffer, format, frequency, &requestChannels, samples);

// Restore the saved channel layout
mlt_properties_set(properties,
"consumer.channel_layout",
mlt_audio_channel_layout_name(channel_layout));

if (!error && requestChannels >= AMBISONICS_1_CHANNELS) {
auto spatial = static_cast<SpatialAudio *>(filter->child);
error = spatial->getAudio(frame, static_cast<float *>(*buffer), *samples, *channels);
Expand Down

0 comments on commit 0b50c22

Please sign in to comment.