Support speaker layouts up to 9.1.6 and deliver their channel masks
This commit is contained in:
1 parent
2ed87d1dce
commit
0b9f3321fd
10 files changed
+646
-57
No files matched your search
+97
-12
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
@@ -196,6 +197,54 @@ void read_local_tags(file::ptr const& source, file_info& info, abort_callback& a
|
||||
}
|
||||
}
|
||||
|
||||
// What the host is told about the delivered stream, and the order the renderer's
|
||||
// channels have to be arranged in to match. The layout table says both; the
|
||||
// engine's own channel count decides, because a mask must have exactly one bit per
|
||||
// channel. A disagreement is logged and left unmasked rather than declared with a
|
||||
// mask that does not describe the data.
|
||||
joc_decode::LayoutDelivery delivery_for(const joc_decode::Settings& settings,
|
||||
unsigned channels) {
|
||||
constexpr unsigned kMaxChannels = joc_decode::kMaxLayoutChannels;
|
||||
joc_decode::LayoutDelivery delivery;
|
||||
delivery.channels = channels;
|
||||
if (channels > kMaxChannels) {
|
||||
for (unsigned channel = 0; channel < kMaxChannels; ++channel) {
|
||||
delivery.order[channel] = channel;
|
||||
}
|
||||
joc_log::line("decoder: %u channel(s) is more than a layout is described for; "
|
||||
"delivering unmasked",
|
||||
channels);
|
||||
return delivery;
|
||||
}
|
||||
if (settings.output == joc_decode::Output::kBinaural) {
|
||||
delivery.mask = (channels == 2) ? (joc_decode::kSpeakerFrontLeft |
|
||||
joc_decode::kSpeakerFrontRight)
|
||||
: 0u;
|
||||
for (unsigned channel = 0; channel < channels; ++channel) {
|
||||
delivery.order[channel] = channel;
|
||||
}
|
||||
return delivery;
|
||||
}
|
||||
joc_decode::LayoutDelivery table;
|
||||
if (joc_decode::layout_delivery(settings.speaker_layout, &table) &&
|
||||
table.channels == channels) {
|
||||
return table;
|
||||
}
|
||||
for (unsigned channel = 0; channel < channels; ++channel) {
|
||||
delivery.order[channel] = channel;
|
||||
}
|
||||
joc_log::line("decoder: layout %s and the %u rendered channel(s) disagree; "
|
||||
"delivering unmasked",
|
||||
settings.speaker_layout.c_str(), channels);
|
||||
return delivery;
|
||||
}
|
||||
|
||||
std::string mask_text(unsigned mask) {
|
||||
char text[16] = {};
|
||||
std::snprintf(text, sizeof(text), "0x%X", mask);
|
||||
return text;
|
||||
}
|
||||
|
||||
class input_joc : public input_stubs {
|
||||
public:
|
||||
void open(service_ptr_t<file> hint, const char* path, t_input_open_reason reason,
|
||||
@@ -345,6 +394,7 @@ public:
|
||||
: ((duration > 0.0) ? static_cast<std::uint64_t>(duration * 48000.0 / 1536.0) : 0);
|
||||
|
||||
unsigned channels = 2;
|
||||
unsigned mask = joc_decode::kSpeakerFrontLeft | joc_decode::kSpeakerFrontRight;
|
||||
std::string render;
|
||||
if (settings.output == joc_decode::Output::kBinaural) {
|
||||
channels = 2;
|
||||
@@ -353,6 +403,9 @@ public:
|
||||
const unsigned layout_channels = joc_decode::speaker_channels(settings.speaker_layout);
|
||||
channels = layout_channels != 0 ? layout_channels : 6;
|
||||
render = "speaker " + settings.speaker_layout;
|
||||
joc_decode::LayoutDelivery delivery;
|
||||
mask = joc_decode::layout_delivery(settings.speaker_layout, &delivery) ? delivery.mask
|
||||
: 0u;
|
||||
}
|
||||
// The custom field and the log line state the delivery format, because it
|
||||
// is the one thing about the output that a listener cannot hear.
|
||||
@@ -362,7 +415,11 @@ public:
|
||||
info.info_set("codec_long", "E-AC-3 JOC (Dolby Atmos)");
|
||||
info.info_set("encoding", "lossy");
|
||||
info.info_set_int("samplerate", kSampleRate);
|
||||
info.info_set_int("channels", channels);
|
||||
// Channel count and mask together: a layout wider than stereo says which
|
||||
// speaker each channel is, and the host keeps that as the file's
|
||||
// WAVEFORMATEXTENSIBLE channel mask. The mask the decoder delivers is the
|
||||
// same one, so what Properties says and what the output receives agree.
|
||||
info.info_set_channels_ex(channels, mask);
|
||||
// What the component hands over, which is what the host keeps if it writes a
|
||||
// file from this stream: float32 by default, int24 when forced. This is also
|
||||
// what foobar2000's own lossless-conversion warning reads
|
||||
@@ -424,8 +481,10 @@ public:
|
||||
read_local_tags(m_file, info, abort);
|
||||
}
|
||||
|
||||
joc_log::line("decoder: get_info duration=%.3f s frames=%llu channels=%u render=%s%s",
|
||||
duration, static_cast<unsigned long long>(frames), channels, render.c_str(),
|
||||
joc_log::line("decoder: get_info duration=%.3f s frames=%llu channels=%u mask=%s "
|
||||
"render=%s%s",
|
||||
duration, static_cast<unsigned long long>(frames), channels,
|
||||
mask_text(mask).c_str(), render.c_str(),
|
||||
container ? " (container)" : "");
|
||||
}
|
||||
|
||||
@@ -459,7 +518,14 @@ public:
|
||||
}
|
||||
m_channels = m_engine.channels();
|
||||
if (m_channels == 0) m_channels = 2;
|
||||
// The mask and the channel order come from the layout the file is being
|
||||
// rendered to; binaural is plain stereo and needs neither.
|
||||
m_delivery = delivery_for(m_settings, m_channels);
|
||||
m_channel_config = m_delivery.mask != 0
|
||||
? m_delivery.mask
|
||||
: audio_chunk::g_guess_channel_config(m_channels);
|
||||
m_buffer.resize(kRunFrames * m_channels);
|
||||
if (m_delivery.reordered) m_delivery_buffer.resize(kRunFrames * m_channels);
|
||||
m_frames_delivered = 0;
|
||||
m_reported = false;
|
||||
m_delivery_mismatches = 0;
|
||||
@@ -468,10 +534,12 @@ public:
|
||||
// about everything this component handed over.
|
||||
m_clipped_samples = 0;
|
||||
m_clip_reported = false;
|
||||
joc_log::line("decoder: engine ready, %u output channel(s), %u frames per read, "
|
||||
"delivery=%s",
|
||||
m_channels, static_cast<unsigned>(kRunFrames),
|
||||
m_settings.force_int24 ? "int24" : "float32");
|
||||
joc_log::line("decoder: engine ready, %u output channel(s), mask=%s%s, %u frames per "
|
||||
"read, delivery=%s",
|
||||
m_channels, mask_text(m_channel_config).c_str(),
|
||||
m_delivery.reordered ? " (channels permuted into mask order)" : "",
|
||||
static_cast<unsigned>(kRunFrames),
|
||||
m_settings.force_int24 ? "int24" : "float32");
|
||||
}
|
||||
|
||||
bool decode_run(audio_chunk& chunk, abort_callback& abort) {
|
||||
@@ -504,11 +572,22 @@ public:
|
||||
// the pipeline sees is the 24-bit grid rather than the renderer's float -- which
|
||||
// is the whole point of the option. The quantisation happens here and nowhere
|
||||
// else, so a sample is rounded once.
|
||||
//
|
||||
// 9.1.4 and 9.1.6 arrive in the renderer's order and have to be handed over in
|
||||
// the order their channel mask implies; every other layout is already in that
|
||||
// order, and then this is just the renderer's own buffer.
|
||||
const float* samples = m_buffer.data();
|
||||
if (m_delivery.reordered) {
|
||||
joc_decode::apply_delivery_order(m_delivery, m_buffer.data(), frames,
|
||||
m_delivery_buffer.data());
|
||||
samples = m_delivery_buffer.data();
|
||||
}
|
||||
|
||||
double expected_delivered_peak = 0.0;
|
||||
if (m_settings.force_int24) {
|
||||
m_int24.resize(frames * m_channels * 3);
|
||||
const joc_decode::Int24Block block = joc_decode::pack_int24(
|
||||
m_buffer.data(), frames * m_channels, m_int24.data());
|
||||
samples, frames * m_channels, m_int24.data());
|
||||
m_clipped_samples += block.clipped;
|
||||
if (block.clipped != 0 && !m_clip_reported) {
|
||||
m_clip_reported = true;
|
||||
@@ -518,13 +597,13 @@ public:
|
||||
static_cast<unsigned long long>(block.clipped));
|
||||
}
|
||||
chunk.set_data_fixedpoint_signed(m_int24.data(), m_int24.size(), kSampleRate,
|
||||
m_channels, 24,
|
||||
audio_chunk::g_guess_channel_config(m_channels));
|
||||
m_channels, 24, m_channel_config);
|
||||
expected_delivered_peak =
|
||||
static_cast<double>(block.peak) / joc_decode::kInt24ImportScale;
|
||||
} else {
|
||||
chunk.set_data_32(m_buffer.data(), frames, m_channels, kSampleRate);
|
||||
expected_delivered_peak = peak_of(m_buffer.data(), frames * m_channels);
|
||||
chunk.set_data_32(samples, frames,
|
||||
audio_chunk::makeSpec(kSampleRate, m_channels, m_channel_config));
|
||||
expected_delivered_peak = peak_of(samples, frames * m_channels);
|
||||
}
|
||||
|
||||
m_frames_delivered += frames;
|
||||
@@ -652,6 +731,12 @@ private:
|
||||
unsigned m_audio_index = 0;
|
||||
joc_container::Result m_container;
|
||||
std::vector<float> m_buffer;
|
||||
// What the host is told about the stream (channel mask) and how the renderer's
|
||||
// channels have to be arranged to match it; see joc_decode.h.
|
||||
joc_decode::LayoutDelivery m_delivery;
|
||||
unsigned m_channel_config = 0;
|
||||
// Only used by the layouts whose renderer order differs from mask order.
|
||||
std::vector<float> m_delivery_buffer;
|
||||
// int24 delivery: the packed bytes handed to the host, and what the clip caught.
|
||||
std::vector<std::uint8_t> m_int24;
|
||||
std::uint64_t m_clipped_samples = 0;
|
||||
|
||||
+128
-9
@@ -301,10 +301,91 @@ private:
|
||||
HANDLE handle_ = INVALID_HANDLE_VALUE;
|
||||
};
|
||||
|
||||
const char* const kLayouts[] = {"2.0", "3.0", "3.1", "4.0", "5.0", "5.1", "5.1.2",
|
||||
"5.1.4", "6.1", "7.0", "7.1", "7.1.2", "7.1.4", "9.1.4",
|
||||
"9.1.6", "22.2"};
|
||||
const unsigned kLayoutChannels[] = {2, 3, 4, 4, 5, 6, 8, 10, 7, 7, 8, 10, 12, 14, 16, 24};
|
||||
// The layouts the core accepts, in the core's own channel order. `speakers` are
|
||||
// the reference table's names for the channels the renderer emits, `flags` are the
|
||||
// WAVE speaker positions those channels are delivered as. The two lists are per
|
||||
// channel, so a wrong entry shows up as a speaker name that does not belong to the
|
||||
// flag next to it (tests/layout_table_test.cpp checks them against the kernel).
|
||||
//
|
||||
// Where a name has two WAVE equivalents the reference table's own layout decides:
|
||||
// the surround pair of 5.1 sits behind the listener (BL/BR, which is also what
|
||||
// "5.1" means to ffmpeg), while 5.1.2 and up use the side pair (SL/SR). The wide
|
||||
// pair of 9.1.x has one home only: FCL/FCR (ffmpeg spells the same two FLC/FRC).
|
||||
//
|
||||
// 9.1.6 is the one layout WAVE cannot describe completely: it has three height
|
||||
// pairs, and the mask has positions for two (TFL/TFR, TBL/TBR) plus single centre
|
||||
// positions. The top-middle pair -- ffmpeg's TSL/TSR, above a 32-bit mask -- is
|
||||
// therefore delivered as the top front/back centre positions. Every mask here has
|
||||
// exactly as many bits as the layout has channels, which is what the host and the
|
||||
// converter require; the order the channels actually arrive in is the flags' own
|
||||
// ascending order, see layout_delivery().
|
||||
const LayoutSpec kLayouts[] = {
|
||||
{"2.0", 2, {"L", "R"}, {kSpeakerFrontLeft, kSpeakerFrontRight}},
|
||||
{"3.1",
|
||||
4,
|
||||
{"L", "R", "C", "LFE"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe}},
|
||||
{"5.1",
|
||||
6,
|
||||
{"L", "R", "C", "LFE", "Ls", "Rs"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerBackLeft, kSpeakerBackRight}},
|
||||
{"7.1",
|
||||
8,
|
||||
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight}},
|
||||
{"5.1.2",
|
||||
8,
|
||||
{"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerSideLeft, kSpeakerSideRight, kSpeakerTopFrontLeft, kSpeakerTopFrontRight}},
|
||||
{"5.1.4",
|
||||
10,
|
||||
{"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerSideLeft, kSpeakerSideRight, kSpeakerTopFrontLeft, kSpeakerTopFrontRight,
|
||||
kSpeakerTopBackLeft, kSpeakerTopBackRight}},
|
||||
{"7.1.2",
|
||||
10,
|
||||
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltm", "Rtm"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
|
||||
kSpeakerTopFrontLeft, kSpeakerTopFrontRight}},
|
||||
{"7.1.4",
|
||||
12,
|
||||
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
|
||||
kSpeakerTopFrontLeft, kSpeakerTopFrontRight, kSpeakerTopBackLeft,
|
||||
kSpeakerTopBackRight}},
|
||||
{"9.1.4",
|
||||
14,
|
||||
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr", "Lw",
|
||||
"Rw"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
|
||||
kSpeakerTopFrontLeft, kSpeakerTopFrontRight, kSpeakerTopBackLeft,
|
||||
kSpeakerTopBackRight, kSpeakerFrontCenterLeft, kSpeakerFrontCenterRight}},
|
||||
{"9.1.6",
|
||||
16,
|
||||
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr", "Ltm",
|
||||
"Rtm", "Lw", "Rw"},
|
||||
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
|
||||
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
|
||||
kSpeakerTopFrontLeft, kSpeakerTopFrontRight, kSpeakerTopBackLeft,
|
||||
kSpeakerTopBackRight, kSpeakerTopFrontCenter, kSpeakerTopBackCenter,
|
||||
kSpeakerFrontCenterLeft, kSpeakerFrontCenterRight}},
|
||||
};
|
||||
|
||||
constexpr std::size_t kLayoutCount = sizeof(kLayouts) / sizeof(kLayouts[0]);
|
||||
|
||||
const LayoutSpec* find_layout(const std::string& name) {
|
||||
for (std::size_t i = 0; i < kLayoutCount; ++i) {
|
||||
if (name == kLayouts[i].name) return &kLayouts[i];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Every ffmpeg child writes its diagnostics next to the component rather than into
|
||||
// whatever working directory the host process happens to have; separate files so
|
||||
@@ -343,16 +424,54 @@ std::int64_t sample_of_seconds(double seconds) {
|
||||
|
||||
} // namespace
|
||||
|
||||
const char* const* speaker_layouts(std::size_t* count) {
|
||||
if (count != nullptr) *count = sizeof(kLayouts) / sizeof(kLayouts[0]);
|
||||
const LayoutSpec* layout_table(std::size_t* count) {
|
||||
if (count != nullptr) *count = kLayoutCount;
|
||||
return kLayouts;
|
||||
}
|
||||
|
||||
unsigned speaker_channels(const std::string& layout) {
|
||||
for (std::size_t i = 0; i < sizeof(kLayouts) / sizeof(kLayouts[0]); ++i) {
|
||||
if (layout == kLayouts[i]) return kLayoutChannels[i];
|
||||
const LayoutSpec* spec = find_layout(layout);
|
||||
return spec != nullptr ? spec->channels : 0;
|
||||
}
|
||||
|
||||
bool layout_delivery(const std::string& layout, LayoutDelivery* out) {
|
||||
const LayoutSpec* spec = find_layout(layout);
|
||||
if (spec == nullptr || out == nullptr || spec->channels == 0 ||
|
||||
spec->channels > kMaxLayoutChannels) {
|
||||
return false;
|
||||
}
|
||||
LayoutDelivery delivery;
|
||||
delivery.channels = spec->channels;
|
||||
bool taken[kMaxLayoutChannels] = {};
|
||||
for (unsigned channel = 0; channel < delivery.channels; ++channel) {
|
||||
delivery.mask |= spec->flags[channel];
|
||||
// The host reads the channels in the ascending order of their flags, so
|
||||
// the channel delivered at position i is the i-th smallest flag.
|
||||
unsigned best = delivery.channels;
|
||||
for (unsigned candidate = 0; candidate < delivery.channels; ++candidate) {
|
||||
if (taken[candidate]) continue;
|
||||
if (best == delivery.channels || spec->flags[candidate] < spec->flags[best]) {
|
||||
best = candidate;
|
||||
}
|
||||
}
|
||||
delivery.order[channel] = best;
|
||||
taken[best] = true;
|
||||
if (best != channel) delivery.reordered = true;
|
||||
}
|
||||
*out = delivery;
|
||||
return true;
|
||||
}
|
||||
|
||||
void apply_delivery_order(const LayoutDelivery& delivery, const float* source,
|
||||
std::size_t frames, float* target) {
|
||||
const std::size_t channels = delivery.channels;
|
||||
for (std::size_t frame = 0; frame < frames; ++frame) {
|
||||
const float* in = source + frame * channels;
|
||||
float* out = target + frame * channels;
|
||||
for (std::size_t channel = 0; channel < channels; ++channel) {
|
||||
out[channel] = in[delivery.order[channel]];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
+67
-3
@@ -104,10 +104,77 @@ struct Settings {
|
||||
bool force_int24 = false;
|
||||
};
|
||||
|
||||
// ---- speaker delivery ------------------------------------------------------
|
||||
//
|
||||
// The renderer emits a layout in the reference table's own channel order. What
|
||||
// foobar2000 receives has to be ordered by its channel mask instead, because the
|
||||
// host defines the interleaved channel order as the ascending order of the mask's
|
||||
// speaker flags (SDK audio_chunk.h: "order of interleaved channel data in the
|
||||
// stream is same as order of these flags"). For most layouts both orders agree;
|
||||
// 9.1.4 and 9.1.6 are the ones where they do not, and the channels are permuted
|
||||
// here rather than declaring a mask that says the wrong thing about them.
|
||||
//
|
||||
// The flag values are the WAVE speaker positions, which is also what
|
||||
// audio_chunk's channel map uses, so a mask can be handed to the host unchanged.
|
||||
enum SpeakerFlag : unsigned {
|
||||
kSpeakerFrontLeft = 0x1,
|
||||
kSpeakerFrontRight = 0x2,
|
||||
kSpeakerFrontCenter = 0x4,
|
||||
kSpeakerLfe = 0x8,
|
||||
kSpeakerBackLeft = 0x10,
|
||||
kSpeakerBackRight = 0x20,
|
||||
kSpeakerFrontCenterLeft = 0x40, // the wide pair of 9.1.x
|
||||
kSpeakerFrontCenterRight = 0x80,
|
||||
kSpeakerBackCenter = 0x100,
|
||||
kSpeakerSideLeft = 0x200,
|
||||
kSpeakerSideRight = 0x400,
|
||||
kSpeakerTopCenter = 0x800,
|
||||
kSpeakerTopFrontLeft = 0x1000,
|
||||
kSpeakerTopFrontCenter = 0x2000,
|
||||
kSpeakerTopFrontRight = 0x4000,
|
||||
kSpeakerTopBackLeft = 0x8000,
|
||||
kSpeakerTopBackCenter = 0x10000,
|
||||
kSpeakerTopBackRight = 0x20000,
|
||||
};
|
||||
|
||||
// The widest layout the core renders; the channel arrays below are sized for it.
|
||||
inline constexpr unsigned kMaxLayoutChannels = 16;
|
||||
|
||||
// A layout the core accepts, with its channels in the order the renderer emits
|
||||
// them. The names are the reference table's speaker names; the flags are the
|
||||
// WAVE positions they are delivered as. Both are listed for the same channel, so
|
||||
// the correspondence can be checked against the reference renderer's table.
|
||||
struct LayoutSpec {
|
||||
const char* name;
|
||||
unsigned channels;
|
||||
const char* speakers[kMaxLayoutChannels];
|
||||
unsigned flags[kMaxLayoutChannels];
|
||||
};
|
||||
|
||||
// Every layout the core accepts, in the order a settings page should list them.
|
||||
const LayoutSpec* layout_table(std::size_t* count);
|
||||
|
||||
// Channel count of a named layout, or 0 when the layout is not one of the
|
||||
// layouts the core accepts.
|
||||
unsigned speaker_channels(const std::string& layout);
|
||||
|
||||
// What the host has to be told about a layout, and how the renderer's channels
|
||||
// have to be arranged to match: delivered channel i is renderer channel order[i].
|
||||
struct LayoutDelivery {
|
||||
unsigned channels = 0;
|
||||
unsigned mask = 0;
|
||||
unsigned order[kMaxLayoutChannels] = {};
|
||||
bool reordered = false;
|
||||
};
|
||||
|
||||
// Fills *out for a layout the core accepts; returns false for anything else.
|
||||
bool layout_delivery(const std::string& layout, LayoutDelivery* out);
|
||||
|
||||
// One interleaved block, renderer order -> delivery order. `source` and
|
||||
// `target` may be the same buffer only when the layout needs no permutation.
|
||||
void apply_delivery_order(const LayoutDelivery& delivery, const float* source,
|
||||
std::size_t frames, float* target);
|
||||
|
||||
// Directory this component's DLL was loaded from. The default HRTF folder is
|
||||
// <that directory>\HRTF, the same place the reference CLI looks next to its exe.
|
||||
std::string component_directory();
|
||||
@@ -117,9 +184,6 @@ std::string component_directory();
|
||||
// component directory cannot be determined.
|
||||
std::string resolve_hrtf_file(const Settings& settings);
|
||||
|
||||
// Every layout the core accepts, in the order a settings page should list them.
|
||||
const char* const* speaker_layouts(std::size_t* count);
|
||||
|
||||
// Result of examining a file without rendering anything.
|
||||
struct FileProbe {
|
||||
bool readable = false;
|
||||
|
||||
+2
-2
@@ -12,12 +12,12 @@
|
||||
|
||||
// Kept in one place: the string reported to foobar2000 and written to the log
|
||||
// must not drift apart.
|
||||
#define JOC_VERSION "0.4.0"
|
||||
#define JOC_VERSION "0.5.0"
|
||||
|
||||
DECLARE_COMPONENT_VERSION("JOC decoder (E-AC-3 JOC)", JOC_VERSION,
|
||||
"Plays E-AC-3 JOC (Dolby Atmos) files: the JOC objects are "
|
||||
"rendered to binaural (SOFA or Rosella HRTF) or to a speaker "
|
||||
"layout up to 7.1.");
|
||||
"layout up to 9.1.6.");
|
||||
|
||||
// Refuses to run when the file has been renamed; the troubleshooter relies on it.
|
||||
VALIDATE_COMPONENT_FILENAME("foo_input_joc.dll");
|
||||
|
||||
+29
-20
@@ -60,17 +60,18 @@ void set_text(HWND control, const std::string& text) {
|
||||
SetWindowTextW(control, wide(text).c_str());
|
||||
}
|
||||
|
||||
// Layouts are offered up to 7.1 on purpose: output chains handle eight channels
|
||||
// comfortably, and wider layouts are only meaningful when writing a file.
|
||||
struct LayoutChoice {
|
||||
const char* name;
|
||||
const char* label;
|
||||
};
|
||||
const LayoutChoice kLayoutChoices[] = {
|
||||
{"2.0", "2.0 (立体声)"}, {"3.0", "3.0"}, {"3.1", "3.1"}, {"4.0", "4.0"},
|
||||
{"5.0", "5.0"}, {"5.1", "5.1"}, {"6.1", "6.1"}, {"7.0", "7.0"},
|
||||
{"7.1", "7.1"},
|
||||
};
|
||||
// The layouts the page offers come from the core-facing table (layout_table()), so
|
||||
// it cannot offer one the decoder rejects. Offering them is not a promise that
|
||||
// every output can play them: foobar2000's shared and exclusive outputs follow the
|
||||
// Windows speaker configuration, while an ASIO output passes any channel count and
|
||||
// any layout through.
|
||||
//
|
||||
// The speaker configurations Windows itself has are 2.0, 5.1 and 7.1. Anything
|
||||
// else -- a height channel, the wide pair, more than eight channels -- is not
|
||||
// carried by a shared or exclusive output, so the status line points at ASIO.
|
||||
bool windows_speaker_config(unsigned mask) {
|
||||
return mask == 0x3u || mask == 0x3Fu || mask == 0x63Fu;
|
||||
}
|
||||
|
||||
const char* const kModeNames[] = {"near", "far", "mid"};
|
||||
const char* const kModeLabels[] = {"near(近场)", "far(远场)", "mid(默认)"};
|
||||
@@ -270,11 +271,13 @@ private:
|
||||
|
||||
HWND layout = GetDlgItem(m_hwnd, IDC_COMBO_LAYOUT);
|
||||
SendMessageW(layout, CB_RESETCONTENT, 0, 0);
|
||||
std::size_t layout_count = 0;
|
||||
const joc_decode::LayoutSpec* layouts = joc_decode::layout_table(&layout_count);
|
||||
int selected = 0;
|
||||
for (unsigned i = 0; i < sizeof(kLayoutChoices) / sizeof(kLayoutChoices[0]); ++i) {
|
||||
for (std::size_t i = 0; i < layout_count; ++i) {
|
||||
SendMessageW(layout, CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(wide(kLayoutChoices[i].label).c_str()));
|
||||
if (values.speaker_layout == kLayoutChoices[i].name) selected = static_cast<int>(i);
|
||||
reinterpret_cast<LPARAM>(wide(layouts[i].name).c_str()));
|
||||
if (values.speaker_layout == layouts[i].name) selected = static_cast<int>(i);
|
||||
}
|
||||
SendMessageW(layout, CB_SETCURSEL, selected, 0);
|
||||
|
||||
@@ -312,9 +315,10 @@ private:
|
||||
|
||||
const int layout_index =
|
||||
static_cast<int>(SendDlgItemMessageW(m_hwnd, IDC_COMBO_LAYOUT, CB_GETCURSEL, 0, 0));
|
||||
if (layout_index >= 0 &&
|
||||
layout_index < static_cast<int>(sizeof(kLayoutChoices) / sizeof(kLayoutChoices[0]))) {
|
||||
values.speaker_layout = kLayoutChoices[layout_index].name;
|
||||
std::size_t layout_count = 0;
|
||||
const joc_decode::LayoutSpec* layouts = joc_decode::layout_table(&layout_count);
|
||||
if (layout_index >= 0 && static_cast<std::size_t>(layout_index) < layout_count) {
|
||||
values.speaker_layout = layouts[layout_index].name;
|
||||
}
|
||||
const int mode_sel =
|
||||
static_cast<int>(SendDlgItemMessageW(m_hwnd, IDC_COMBO_MODE, CB_GETCURSEL, 0, 0));
|
||||
@@ -350,10 +354,15 @@ private:
|
||||
const joc_settings::Values values = read_controls();
|
||||
std::string output_status;
|
||||
if (values.output != 0) {
|
||||
char text[96] = {};
|
||||
char text[160] = {};
|
||||
const unsigned channels = joc_decode::speaker_channels(values.speaker_layout);
|
||||
std::snprintf(text, sizeof(text), "扬声器布局 %s(%u 声道)",
|
||||
values.speaker_layout.c_str(), channels);
|
||||
joc_decode::LayoutDelivery delivery;
|
||||
const bool plain =
|
||||
joc_decode::layout_delivery(values.speaker_layout, &delivery) &&
|
||||
windows_speaker_config(delivery.mask);
|
||||
std::snprintf(text, sizeof(text), "扬声器布局 %s(%u 声道%s)",
|
||||
values.speaker_layout.c_str(), channels,
|
||||
plain ? "" : ",需要 ASIO 输出");
|
||||
output_status = text;
|
||||
}
|
||||
set_text(GetDlgItem(m_hwnd, IDC_LABEL_OUTPUT_STATUS), output_status);
|
||||
|
||||
+14
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -115,7 +116,19 @@ Values read() {
|
||||
Values values;
|
||||
values.output = static_cast<int>(static_cast<unsigned>(g_output));
|
||||
values.speaker_layout = g_layout.get_ptr();
|
||||
if (values.speaker_layout.empty()) values.speaker_layout = "7.1";
|
||||
// A layout the core does not accept (an old build offered several it never
|
||||
// accepted) would fail when the renderer is created, and the page cannot show it
|
||||
// either, because its list is the core's own table. Falling back here makes the
|
||||
// stored value usable again and the page show what will actually be rendered.
|
||||
if (joc_decode::speaker_channels(values.speaker_layout) == 0) {
|
||||
static std::atomic<bool> warned{false};
|
||||
if (!warned.exchange(true, std::memory_order_relaxed)) {
|
||||
joc_log::line("settings: stored speaker layout \"%s\" is not one the core "
|
||||
"accepts; using 7.1",
|
||||
values.speaker_layout.c_str());
|
||||
}
|
||||
values.speaker_layout = "7.1";
|
||||
}
|
||||
const unsigned source = static_cast<unsigned>(g_hrtf_source);
|
||||
values.hrtf_source = (source == 1u) ? HrtfSource::kRosella : HrtfSource::kSofa;
|
||||
values.hrtf_file = g_hrtf_file.get_ptr();
|
||||
|
||||
Reference in new issue
Block a user