Add ffmpeg PCM and non-JOC E-AC-3/TrueHD takeover
- Add the take_over_pcm preference, persistence and input registration. - Decode takeover sources with ffmpeg to 48 kHz float32 and feed the kernel PCM_LAYOUT stream for binaural output. - Keep JOC priority: bare E-AC-3/EC3 and MP4/Matroska/WebM are probed first, then non-JOC audio falls back to ffmpeg. - Cover AC3, DTS/DTS-HD, WavPack, APE, TTA, MPC, AU/SND/CAF and TrueHD/MLP; TrueHD in containers follows the same fallback. - Sync the kernel to 1.3.3 with the virtual_speaker module and fix the PCM gain path. - Update the preferences UI, HRTF hint and README.
This commit is contained in:
1 parent
5c0f9ea2ff
commit
b0751d82b6
21 files changed
+933
-25
No files matched your search
@@ -40,7 +40,8 @@ typedef struct joc_stream joc_stream;
|
||||
typedef enum joc_stream_input {
|
||||
JOC_STREAM_IN_EAC3 = 0, /* bare E-AC-3 syncframes (the metadata stream) */
|
||||
JOC_STREAM_IN_PCM_OBJECTS16 = 1, /* objects16 frames, planar [16][1536] each */
|
||||
JOC_STREAM_IN_CORE_PCM = 3 /* the 5.1 core PCM of the pushed E-AC-3 frames */
|
||||
JOC_STREAM_IN_CORE_PCM = 3, /* the 5.1 core PCM of the pushed E-AC-3 frames */
|
||||
JOC_STREAM_IN_PCM_LAYOUT = 4 /* interleaved 48k f32, mapped by pcm_layout */
|
||||
} joc_stream_input;
|
||||
|
||||
typedef enum joc_stream_output {
|
||||
@@ -68,6 +69,8 @@ typedef struct joc_stream_config {
|
||||
* .jochrtf field (hrtf_path) or a Rosella .personalized_headphone model. */
|
||||
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
||||
uint32_t jochrtf_room; /* non-zero enables the project room */
|
||||
/* PCM_LAYOUT input: "2.0", "5.1", "7.1", or NULL/"" to infer by channels. */
|
||||
const char* pcm_layout;
|
||||
} joc_stream_config;
|
||||
|
||||
typedef struct joc_stream_buffer {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#define JOC_VERSION_MAJOR 1
|
||||
#define JOC_VERSION_MINOR 3
|
||||
#define JOC_VERSION_PATCH 1
|
||||
#define JOC_VERSION_STRING "1.3.1"
|
||||
#define JOC_VERSION_PATCH 3
|
||||
#define JOC_VERSION_STRING "1.3.3"
|
||||
|
||||
#endif /* JOC_VERSION_H */
|
||||
@@ -185,6 +185,7 @@
|
||||
<ClCompile Include="src\speaker\speaker_step.cpp" />
|
||||
<ClCompile Include="src\speaker\speaker_trim.cpp" />
|
||||
<ClCompile Include="src\stream\stream.cpp" />
|
||||
<ClCompile Include="src\virtual_speaker\virtual_speaker.cpp" />
|
||||
<ClCompile Include="src\task\task.cpp" />
|
||||
<ClCompile Include="src\telemetry\event_bus.cpp" />
|
||||
<ClCompile Include="src\timeline\position_timeline.cpp" />
|
||||
|
||||
@@ -46,6 +46,7 @@ joc::stream::Config to_config(const joc_stream_config& config) {
|
||||
if (config.rosella_filterbank != 0u) {
|
||||
out.rosella_filterbank = config.rosella_filterbank;
|
||||
}
|
||||
if (config.pcm_layout != nullptr) { out.pcm_layout = config.pcm_layout; }
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -95,6 +96,19 @@ joc_error JOC_CALL joc_stream_push(joc_stream* stream, const joc_stream_buffer*
|
||||
}
|
||||
return pushed;
|
||||
}
|
||||
if (input->kind == JOC_STREAM_IN_PCM_LAYOUT) {
|
||||
if (input->sample_rate != 0u && input->sample_rate != 48000u) {
|
||||
return joc::Status::fail(JOC_ERR_INVALID_ARGUMENT, joc::stage::kRender,
|
||||
"PCM layout input must be 48 kHz");
|
||||
}
|
||||
std::size_t consumed = 0;
|
||||
const joc::Status pushed = stream->instance.push_pcm_layout(
|
||||
input->pcm, input->sample_count, input->channels, &consumed);
|
||||
if (consumed_samples != nullptr) {
|
||||
*consumed_samples = static_cast<std::uint32_t>(consumed);
|
||||
}
|
||||
return pushed;
|
||||
}
|
||||
std::size_t consumed = 0;
|
||||
const std::uint32_t channels = input->channels != 0u ? input->channels : 6u;
|
||||
const joc::Status pushed =
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "adm/adm_metadata.h"
|
||||
#include "foundation/status.h"
|
||||
#include "virtual_speaker/virtual_speaker.h"
|
||||
#include "hrtf/jochrtf.h"
|
||||
#include "hrtf/rosella_model.h"
|
||||
#include "joc_bitstream/bed_layout_map.h"
|
||||
@@ -45,6 +46,7 @@ void Stream::reset_state() {
|
||||
bed_pending_.clear();
|
||||
bed_read_offset_ = 0;
|
||||
objects16_.clear();
|
||||
pcm_input_.reset();
|
||||
objects_pending_.clear();
|
||||
objects_read_offset_ = 0;
|
||||
output_.clear();
|
||||
@@ -77,7 +79,7 @@ Status Stream::create(const Config& config) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "stream already created");
|
||||
}
|
||||
config_ = config;
|
||||
if (config_.input > JOC_STREAM_IN_PCM_OBJECTS16 ||
|
||||
if (config_.input > JOC_STREAM_IN_PCM_LAYOUT ||
|
||||
config_.output > JOC_STREAM_OUT_BINAURAL) {
|
||||
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender, "unknown stream kind");
|
||||
}
|
||||
@@ -87,6 +89,20 @@ Status Stream::create(const Config& config) {
|
||||
"objects16 input with objects16 output would do nothing");
|
||||
}
|
||||
gain_ = static_cast<float>(std::pow(10.0, config_.gain_db / 20.0));
|
||||
if (config_.input == JOC_STREAM_IN_PCM_LAYOUT && !config_.pcm_layout.empty() &&
|
||||
config_.pcm_layout != "auto") {
|
||||
const virtual_speaker::Layout* layout =
|
||||
virtual_speaker::find_layout(config_.pcm_layout);
|
||||
if (layout == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender,
|
||||
"unknown PCM layout: " + config_.pcm_layout);
|
||||
}
|
||||
const Status configured =
|
||||
pcm_input_.configure(config_.pcm_layout, layout->channels, config_.gain_db);
|
||||
if (!configured.ok()) {
|
||||
return configured;
|
||||
}
|
||||
}
|
||||
|
||||
if (config_.input == JOC_STREAM_IN_EAC3) {
|
||||
rebuilder_ = ejoc_renderer_create();
|
||||
@@ -453,6 +469,47 @@ Status Stream::push_objects16(const float* planar16, std::size_t samples, std::s
|
||||
return process_objects16_frames(false);
|
||||
}
|
||||
|
||||
Status Stream::push_pcm_layout(const float* interleaved, std::size_t samples,
|
||||
std::uint32_t channels, std::size_t* consumed) {
|
||||
if (consumed != nullptr) {
|
||||
*consumed = 0;
|
||||
}
|
||||
if (interleaved == nullptr || samples == 0u) {
|
||||
return Status::success();
|
||||
}
|
||||
if (pcm_input_.layout() == nullptr) {
|
||||
const Status configured = pcm_input_.configure(config_.pcm_layout,
|
||||
static_cast<int>(channels),
|
||||
config_.gain_db);
|
||||
if (!configured.ok()) {
|
||||
return configured;
|
||||
}
|
||||
} else if (pcm_input_.channels() != static_cast<int>(channels)) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"PCM channel count changed mid-stream");
|
||||
}
|
||||
Status status = pcm_input_.append(interleaved, samples);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::size_t processed = 0;
|
||||
while (pcm_input_.frame_ready()) {
|
||||
status = pcm_input_.take_frame(&objects_frame_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = push_objects16(objects_frame_.data(), kFrameSamples, nullptr);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
processed += kFrameSamples;
|
||||
}
|
||||
if (consumed != nullptr) {
|
||||
*consumed = processed;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status Stream::process_objects16_frames(bool drain_all) {
|
||||
constexpr std::size_t kFrameValues =
|
||||
static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * kFrameSamples;
|
||||
@@ -590,9 +647,11 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
||||
if (speaker_enabled_) {
|
||||
std::string error;
|
||||
const Status stepped =
|
||||
speaker::step(&speaker_, objects16, pending_metadata_.has_update
|
||||
? &pending_metadata_.update
|
||||
: nullptr,
|
||||
speaker::step(&speaker_, objects16,
|
||||
pending_metadata_.has_update
|
||||
? &pending_metadata_.update
|
||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update()
|
||||
: nullptr),
|
||||
&error);
|
||||
if (!stepped.ok()) {
|
||||
return Status::fail(stepped.code(), stage::kRender, error);
|
||||
@@ -611,7 +670,8 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
||||
|
||||
const Status submitted =
|
||||
binaural_.submit_frame(objects16.data(),
|
||||
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
|
||||
pending_metadata_.has_update ? &pending_metadata_.update
|
||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
|
||||
static_cast<std::int64_t>(info_.frames_out),
|
||||
pending_metadata_.outer_offset,
|
||||
static_cast<std::int64_t>(config_.object_delay_samples));
|
||||
@@ -638,7 +698,8 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
||||
Status Stream::render_rosella_objects16(const std::vector<float>& objects16) {
|
||||
const Status submitted =
|
||||
rosella_.submit_frame(objects16.data(),
|
||||
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
|
||||
pending_metadata_.has_update ? &pending_metadata_.update
|
||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
|
||||
static_cast<std::int64_t>(info_.frames_out),
|
||||
pending_metadata_.outer_offset,
|
||||
static_cast<std::int64_t>(config_.object_delay_samples));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "joc_stream.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_step.h"
|
||||
#include "virtual_speaker/virtual_speaker.h"
|
||||
|
||||
namespace joc::stream {
|
||||
|
||||
@@ -34,6 +35,7 @@ struct Config {
|
||||
// (.jochrtf).
|
||||
std::string personalized_headphone_path;
|
||||
std::uint32_t jochrtf_room = 1;
|
||||
std::string pcm_layout;
|
||||
// Filterbank of the Rosella path; the other binaural inputs ignore it.
|
||||
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
||||
};
|
||||
@@ -99,6 +101,8 @@ public:
|
||||
Status push_bed(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
||||
std::size_t* consumed);
|
||||
Status push_objects16(const float* planar16, std::size_t samples, std::size_t* consumed);
|
||||
Status push_pcm_layout(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
||||
std::size_t* consumed);
|
||||
Status pull(float* destination, std::size_t capacity_samples, std::size_t* produced);
|
||||
Status flush();
|
||||
Status reset();
|
||||
@@ -160,6 +164,9 @@ private:
|
||||
std::size_t bed_read_offset_ = 0;
|
||||
std::vector<float> bed5_;
|
||||
std::vector<float> lfe_;
|
||||
virtual_speaker::Input pcm_input_;
|
||||
oamd::OamdUpdate fixed_update_{};
|
||||
bool has_fixed_update_ = false;
|
||||
std::vector<float> objects_pending_;
|
||||
std::size_t objects_read_offset_ = 0;
|
||||
std::vector<float> objects_frame_;
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
#include "virtual_speaker/virtual_speaker.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#include "joc_core.h"
|
||||
|
||||
namespace joc::virtual_speaker {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::size_t kFrameSamples = JOC_FRAME_SAMPLES;
|
||||
constexpr std::size_t kSourceChannels = JOC_OUTPUT_CHANNELS;
|
||||
|
||||
// WAV order follows the ffmpeg layouts: 5.1 = L R C LFE BL BR,
|
||||
// 7.1 = L R C LFE BL BR SL SR.
|
||||
constexpr Layout kLayouts[] = {
|
||||
{"2.0",
|
||||
2,
|
||||
{{false, -1.0, 1.0, 0.0},
|
||||
{false, 1.0, 1.0, 0.0}}},
|
||||
{"5.1",
|
||||
6,
|
||||
{{false, -1.0, 1.0, 0.0},
|
||||
{false, 1.0, 1.0, 0.0},
|
||||
{false, 0.0, 1.0, 0.0},
|
||||
{true, 0.0, 1.0, 0.0},
|
||||
{false, -1.0, -1.0, 0.0},
|
||||
{false, 1.0, -1.0, 0.0}}},
|
||||
{"7.1",
|
||||
8,
|
||||
{{false, -1.0, 1.0, 0.0},
|
||||
{false, 1.0, 1.0, 0.0},
|
||||
{false, 0.0, 1.0, 0.0},
|
||||
{true, 0.0, 1.0, 0.0},
|
||||
{false, -1.0, -1.0, 0.0},
|
||||
{false, 1.0, -1.0, 0.0},
|
||||
{false, -1.0, 0.0, 0.0},
|
||||
{false, 1.0, 0.0, 0.0}}},
|
||||
};
|
||||
|
||||
std::int16_t q_for_axis(double value) {
|
||||
if (value <= -0.999) {
|
||||
return 0;
|
||||
}
|
||||
if (value >= 0.999) {
|
||||
return 32767;
|
||||
}
|
||||
return 16384;
|
||||
}
|
||||
|
||||
void fill_fixed_positions(const Layout& layout, oamd::OamdUpdate* update) {
|
||||
update->object_count = static_cast<std::uint32_t>(kSourceChannels);
|
||||
update->block_offset_samples = 0;
|
||||
update->ramp_duration_samples = 0;
|
||||
int slot = 1;
|
||||
for (int channel = 0; channel < layout.channels; ++channel) {
|
||||
const ChannelSpec& spec = layout.channel_specs[channel];
|
||||
const int destination = spec.lfe ? 0 : slot++;
|
||||
update->slots[destination].q1 = q_for_axis(spec.x);
|
||||
update->slots[destination].q2 = q_for_axis(-spec.y);
|
||||
update->slots[destination].q3 = q_for_axis(spec.z);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const Layout* find_layout(const std::string& name) {
|
||||
for (const Layout& layout : kLayouts) {
|
||||
if (name == layout.name) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Layout* detect_layout(int channels) {
|
||||
for (const Layout& layout : kLayouts) {
|
||||
if (layout.channels == channels) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Status Input::configure(const std::string& layout_name, int channels, double gain_db) {
|
||||
const Layout* layout =
|
||||
(layout_name.empty() || layout_name == "auto")
|
||||
? detect_layout(channels)
|
||||
: find_layout(layout_name);
|
||||
if (layout == nullptr || layout->channels != channels) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"PCM layout does not match the channel count");
|
||||
}
|
||||
layout_ = layout;
|
||||
channels_ = channels;
|
||||
gain_ = static_cast<double>(std::pow(10.0, gain_db / 20.0));
|
||||
pending_.clear();
|
||||
read_offset_ = 0;
|
||||
fill_fixed_positions(*layout_, &fixed_update_);
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
void Input::reset() {
|
||||
pending_.clear();
|
||||
read_offset_ = 0;
|
||||
}
|
||||
|
||||
Status Input::append(const float* interleaved, std::size_t frames) {
|
||||
if (interleaved == nullptr || frames == 0u) {
|
||||
return Status::success();
|
||||
}
|
||||
if (layout_ == nullptr || channels_ <= 0) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender,
|
||||
"virtual speaker input is not configured");
|
||||
}
|
||||
pending_.insert(pending_.end(), interleaved,
|
||||
interleaved + frames * static_cast<std::size_t>(channels_));
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
bool Input::frame_ready() const {
|
||||
return layout_ != nullptr &&
|
||||
pending_.size() - read_offset_ >=
|
||||
kFrameSamples * static_cast<std::size_t>(channels_);
|
||||
}
|
||||
|
||||
Status Input::take_frame(std::vector<float>* objects16) {
|
||||
if (objects16 == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"objects16 output is null");
|
||||
}
|
||||
if (!frame_ready()) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender,
|
||||
"no complete PCM frame is buffered");
|
||||
}
|
||||
objects16->assign(kSourceChannels * kFrameSamples, 0.0f);
|
||||
const float* source = pending_.data() + read_offset_;
|
||||
int slot = 1;
|
||||
for (int channel = 0; channel < layout_->channels; ++channel) {
|
||||
const int destination = layout_->channel_specs[channel].lfe ? 0 : slot++;
|
||||
for (std::size_t sample = 0; sample < kFrameSamples; ++sample) {
|
||||
(*objects16)[static_cast<std::size_t>(destination) * kFrameSamples + sample] =
|
||||
source[sample * static_cast<std::size_t>(channels_) + channel] *
|
||||
static_cast<float>(gain_);
|
||||
}
|
||||
}
|
||||
read_offset_ += kFrameSamples * static_cast<std::size_t>(channels_);
|
||||
if (read_offset_ == pending_.size()) {
|
||||
pending_.clear();
|
||||
read_offset_ = 0;
|
||||
} else if (read_offset_ >= (1u << 20)) {
|
||||
pending_.erase(pending_.begin(),
|
||||
pending_.begin() + static_cast<std::ptrdiff_t>(read_offset_));
|
||||
read_offset_ = 0;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::virtual_speaker
|
||||
@@ -0,0 +1,57 @@
|
||||
// Virtual speaker input: ordinary multichannel PCM as fixed-direction JOC
|
||||
// objects. It owns only the layout mapping and the PCM-to-objects16 shape;
|
||||
// decoding, speaker rendering and binaural rendering stay in their own modules.
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
namespace joc::virtual_speaker {
|
||||
|
||||
struct ChannelSpec {
|
||||
bool lfe;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
|
||||
struct Layout {
|
||||
const char* name;
|
||||
int channels;
|
||||
ChannelSpec channel_specs[8];
|
||||
};
|
||||
|
||||
const Layout* find_layout(const std::string& name);
|
||||
const Layout* detect_layout(int channels);
|
||||
|
||||
class Input {
|
||||
public:
|
||||
// gain_db is the module's master attenuation; it is applied to every
|
||||
// mapped channel once, before the objects16 frame leaves the module.
|
||||
Status configure(const std::string& layout_name, int channels, double gain_db = 0.0);
|
||||
void reset();
|
||||
|
||||
const oamd::OamdUpdate& fixed_update() const { return fixed_update_; }
|
||||
int channels() const { return channels_; }
|
||||
const Layout* layout() const { return layout_; }
|
||||
|
||||
// Appends interleaved frames; take_frame() emits whole 1536-frame blocks.
|
||||
Status append(const float* interleaved, std::size_t frames);
|
||||
bool frame_ready() const;
|
||||
Status take_frame(std::vector<float>* objects16);
|
||||
|
||||
private:
|
||||
const Layout* layout_ = nullptr;
|
||||
int channels_ = 0;
|
||||
double gain_ = 1.0;
|
||||
oamd::OamdUpdate fixed_update_{};
|
||||
std::vector<float> pending_;
|
||||
std::size_t read_offset_ = 0;
|
||||
};
|
||||
|
||||
} // namespace joc::virtual_speaker
|
||||
Reference in new issue
Block a user