Sync the kernel copy and drop the SOFA source choice
The kernel copy follows the new kernel: the SOFA reader, its compile cache and the field fit are gone, the compiled-field renderer is jochrtf_renderer.cpp with jochrtf_runtime.*, and joc_kernel.vcxproj lists the new translation units. With the Rosella model as the only user-facing input, the preferences page loses its SOFA radio and the settings drop HrtfSource, hrtf_source, hrtf_cache_policy, hrtf_cache_dir and hrtf_radius_m. Decoding always sets personalized_headphone_path, the default lookup is HRTF\binaural.personalized_headphone, and the page hint names that file alone. The compiled .jochrtf stays internal: the page names a model file, never a cache. Builds Release-Static|x64 (foo_input_joc.dll and joc_kernel.lib).
This commit is contained in:
1 parent
b566c364df
commit
5d6c6bc45c
25 files changed
+134
-2886
No files matched your search
@@ -188,19 +188,19 @@ per-object whole-QMF-slot delay histories, six first-order image-source early
|
|||||||
reflections, the shared unitary-FDN late room, the 120-180 Hz LFE low-pass and
|
reflections, the shared unitary-FDN late room, the 120-180 Hz LFE low-pass and
|
||||||
the 961-sample latency compensation. The caller configures the filterbank
|
the 961-sample latency compensation. The caller configures the filterbank
|
||||||
tables, the compiled HRTF field and the room constants once, then per 512-sample
|
tables, the compiled HRTF field and the room constants once, then per 512-sample
|
||||||
block updates every source with ejoc_sofa_binaural_set_source() and calls
|
block updates every source with ejoc_jochrtf_set_source() and calls
|
||||||
ejoc_sofa_binaural_process(). Process returns the number of trimmed stereo
|
ejoc_jochrtf_process(). Process returns the number of trimmed stereo
|
||||||
samples written; the first 961 processed samples across calls are discarded.
|
samples written; the first 961 processed samples across calls are discarded.
|
||||||
*/
|
*/
|
||||||
typedef void* ejoc_sofa_binaural_handle;
|
typedef void* ejoc_jochrtf_handle;
|
||||||
|
|
||||||
EJOC_API ejoc_sofa_binaural_handle EJOC_CALL ejoc_sofa_binaural_create(void);
|
EJOC_API ejoc_jochrtf_handle EJOC_CALL ejoc_jochrtf_create(void);
|
||||||
EJOC_API void EJOC_CALL ejoc_sofa_binaural_destroy(ejoc_sofa_binaural_handle handle);
|
EJOC_API void EJOC_CALL ejoc_jochrtf_destroy(ejoc_jochrtf_handle handle);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_reset(ejoc_sofa_binaural_handle handle);
|
EJOC_API int EJOC_CALL ejoc_jochrtf_reset(ejoc_jochrtf_handle handle);
|
||||||
EJOC_API const char* EJOC_CALL ejoc_sofa_binaural_last_error(
|
EJOC_API const char* EJOC_CALL ejoc_jochrtf_last_error(
|
||||||
ejoc_sofa_binaural_handle handle);
|
ejoc_jochrtf_handle handle);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
EJOC_API int EJOC_CALL ejoc_jochrtf_configure_kernels(
|
||||||
ejoc_sofa_binaural_handle handle,
|
ejoc_jochrtf_handle handle,
|
||||||
const double* qmf_analysis,
|
const double* qmf_analysis,
|
||||||
const double* hybrid_low,
|
const double* hybrid_low,
|
||||||
const int16_t* hybrid_indices,
|
const int16_t* hybrid_indices,
|
||||||
@@ -208,15 +208,15 @@ EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
|||||||
uint32_t hybrid_count,
|
uint32_t hybrid_count,
|
||||||
const double* qmf_basis,
|
const double* qmf_basis,
|
||||||
const double* qmf_taps);
|
const double* qmf_taps);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_field(
|
EJOC_API int EJOC_CALL ejoc_jochrtf_configure_field(
|
||||||
ejoc_sofa_binaural_handle handle,
|
ejoc_jochrtf_handle handle,
|
||||||
const double* coefficients,
|
const double* coefficients,
|
||||||
const double* delay_coefficients,
|
const double* delay_coefficients,
|
||||||
const double* delay_bounds,
|
const double* delay_bounds,
|
||||||
const double* band_centers,
|
const double* band_centers,
|
||||||
double measurement_radius_m);
|
double measurement_radius_m);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
EJOC_API int EJOC_CALL ejoc_jochrtf_configure_room(
|
||||||
ejoc_sofa_binaural_handle handle,
|
ejoc_jochrtf_handle handle,
|
||||||
const double* room_dims,
|
const double* room_dims,
|
||||||
const double* listener_pos,
|
const double* listener_pos,
|
||||||
const double* wall_gains,
|
const double* wall_gains,
|
||||||
@@ -229,8 +229,8 @@ EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
|||||||
const double* allpass_gains,
|
const double* allpass_gains,
|
||||||
uint32_t enable_early_reflections,
|
uint32_t enable_early_reflections,
|
||||||
uint32_t enable_late_room);
|
uint32_t enable_late_room);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_set_source(
|
EJOC_API int EJOC_CALL ejoc_jochrtf_set_source(
|
||||||
ejoc_sofa_binaural_handle handle,
|
ejoc_jochrtf_handle handle,
|
||||||
uint32_t source,
|
uint32_t source,
|
||||||
const double* position_adm,
|
const double* position_adm,
|
||||||
uint32_t profile,
|
uint32_t profile,
|
||||||
@@ -238,14 +238,14 @@ EJOC_API int EJOC_CALL ejoc_sofa_binaural_set_source(
|
|||||||
uint32_t enabled,
|
uint32_t enabled,
|
||||||
uint32_t special_lfe,
|
uint32_t special_lfe,
|
||||||
uint32_t fade);
|
uint32_t fade);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_process(
|
EJOC_API int EJOC_CALL ejoc_jochrtf_process(
|
||||||
ejoc_sofa_binaural_handle handle,
|
ejoc_jochrtf_handle handle,
|
||||||
const double* input16_interleaved,
|
const double* input16_interleaved,
|
||||||
uint32_t sample_count,
|
uint32_t sample_count,
|
||||||
double output_gain,
|
double output_gain,
|
||||||
double* output_stereo_interleaved);
|
double* output_stereo_interleaved);
|
||||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_finish(
|
EJOC_API int EJOC_CALL ejoc_jochrtf_finish(
|
||||||
ejoc_sofa_binaural_handle handle,
|
ejoc_jochrtf_handle handle,
|
||||||
uint32_t flush_samples,
|
uint32_t flush_samples,
|
||||||
double* output_stereo_interleaved,
|
double* output_stereo_interleaved,
|
||||||
uint32_t capacity);
|
uint32_t capacity);
|
||||||
|
|||||||
@@ -358,14 +358,6 @@ typedef enum joc_clip_action {
|
|||||||
JOC_CLIP_ABORT = 3 /* fail the task */
|
JOC_CLIP_ABORT = 3 /* fail the task */
|
||||||
} joc_clip_action;
|
} joc_clip_action;
|
||||||
|
|
||||||
/* Compiled-HRTF cache policy for a SOFA input; the .jochrtf itself is an
|
|
||||||
* internal artifact of the compile step. */
|
|
||||||
typedef enum joc_hrtf_cache_policy {
|
|
||||||
JOC_HRTF_CACHE_NONE = 0, /* compile and discard */
|
|
||||||
JOC_HRTF_CACHE_MEMORY = 1, /* compile and keep in this process (default) */
|
|
||||||
JOC_HRTF_CACHE_DISK = 2 /* compile, reuse and write <cache_dir>/<name>.jochrtf */
|
|
||||||
} joc_hrtf_cache_policy;
|
|
||||||
|
|
||||||
/* Which 64-QMF / 77-hybrid filterbank the Rosella .personalized_headphone path
|
/* Which 64-QMF / 77-hybrid filterbank the Rosella .personalized_headphone path
|
||||||
* renders through. The two banks differ in coefficients, hybrid tap count,
|
* renders through. The two banks differ in coefficients, hybrid tap count,
|
||||||
* high-band slot delay and total latency, so they are not interchangeable; the
|
* high-band slot delay and total latency, so they are not interchangeable; the
|
||||||
@@ -424,16 +416,11 @@ typedef struct joc_task_config {
|
|||||||
|
|
||||||
joc_cancel_token* cancel; /* optional */
|
joc_cancel_token* cancel; /* optional */
|
||||||
|
|
||||||
/* Binaural HRTF input (config version 2): when hrtf_sofa_path is set the
|
/* Binaural input (config version 2): a compiled .jochrtf field (hrtf_path)
|
||||||
* library compiles it with hrtf_cache_policy / hrtf_cache_dir / hrtf_radius_m
|
* or a Rosella .personalized_headphone model. */
|
||||||
* and hrtf_path is unused. hrtf_path stays the advanced override that reads
|
|
||||||
* a .jochrtf directly. */
|
|
||||||
const char* hrtf_sofa_path; /* SOFA SimpleFreeFieldHRIR input */
|
|
||||||
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
||||||
const char* hrtf_cache_dir; /* disk policy directory */
|
|
||||||
uint32_t hrtf_cache_policy; /* joc_hrtf_cache_policy */
|
|
||||||
uint32_t rosella_filterbank; /* joc_rosella_filterbank; 0 = PUBLIC */
|
uint32_t rosella_filterbank; /* joc_rosella_filterbank; 0 = PUBLIC */
|
||||||
double hrtf_radius_m; /* SOFA measurement-radius shell */
|
uint32_t jochrtf_room; /* non-zero enables the project room */
|
||||||
} joc_task_config;
|
} joc_task_config;
|
||||||
|
|
||||||
typedef enum joc_task_status {
|
typedef enum joc_task_status {
|
||||||
|
|||||||
@@ -64,16 +64,10 @@ typedef struct joc_stream_config {
|
|||||||
double gain_db; /* default 0 */
|
double gain_db; /* default 0 */
|
||||||
uint32_t native_threads;
|
uint32_t native_threads;
|
||||||
uint32_t rosella_filterbank; /* joc_rosella_filterbank; Rosella input, 0 = PUBLIC */
|
uint32_t rosella_filterbank; /* joc_rosella_filterbank; Rosella input, 0 = PUBLIC */
|
||||||
/* Binaural HRTF input, the same three shapes joc_task_config accepts: when
|
/* Binaural input, the same shapes joc_task_config accepts: a compiled
|
||||||
* hrtf_sofa_path is set the library compiles it with hrtf_cache_policy /
|
* .jochrtf field (hrtf_path) or a Rosella .personalized_headphone model. */
|
||||||
* hrtf_cache_dir / hrtf_radius_m and hrtf_path is unused; when
|
|
||||||
* personalized_headphone_path is set the Rosella runtime renders instead.
|
|
||||||
* hrtf_path stays the fallback/advanced input that reads a .jochrtf directly. */
|
|
||||||
const char* hrtf_sofa_path; /* SOFA SimpleFreeFieldHRIR input */
|
|
||||||
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
||||||
const char* hrtf_cache_dir; /* disk cache directory for SOFA compilation */
|
uint32_t jochrtf_room; /* non-zero enables the project room */
|
||||||
uint32_t hrtf_cache_policy; /* joc_hrtf_cache_policy: 0 none, 1 memory, 2 disk */
|
|
||||||
double hrtf_radius_m; /* SOFA measurement-radius shell, default 1.0 */
|
|
||||||
} joc_stream_config;
|
} joc_stream_config;
|
||||||
|
|
||||||
typedef struct joc_stream_buffer {
|
typedef struct joc_stream_buffer {
|
||||||
|
|||||||
@@ -149,8 +149,8 @@
|
|||||||
<!-- Engine internals (JOC_INTERNAL_SOURCES). -->
|
<!-- Engine internals (JOC_INTERNAL_SOURCES). -->
|
||||||
<ClCompile Include="src\adm\adm_metadata.cpp" />
|
<ClCompile Include="src\adm\adm_metadata.cpp" />
|
||||||
<ClCompile Include="src\adm\adm_tracks.cpp" />
|
<ClCompile Include="src\adm\adm_tracks.cpp" />
|
||||||
<ClCompile Include="src\binaural\binaural_runtime.cpp" />
|
<ClCompile Include="src\binaural\jochrtf_runtime.cpp" />
|
||||||
<ClCompile Include="src\binaural\sofa_binaural_renderer.cpp" />
|
<ClCompile Include="src\binaural\jochrtf_renderer.cpp" />
|
||||||
<ClCompile Include="src\eac3_transport\eac3_reader.cpp" />
|
<ClCompile Include="src\eac3_transport\eac3_reader.cpp" />
|
||||||
<ClCompile Include="src\emdf\emdf_parser.cpp" />
|
<ClCompile Include="src\emdf\emdf_parser.cpp" />
|
||||||
<ClCompile Include="src\foundation\bit_reader.cpp" />
|
<ClCompile Include="src\foundation\bit_reader.cpp" />
|
||||||
@@ -166,9 +166,6 @@
|
|||||||
<ClCompile Include="src\hrtf\rosella_model.cpp" />
|
<ClCompile Include="src\hrtf\rosella_model.cpp" />
|
||||||
<ClCompile Include="src\hrtf\rosella_renderer.cpp" />
|
<ClCompile Include="src\hrtf\rosella_renderer.cpp" />
|
||||||
<ClCompile Include="src\hrtf\kernel_tables.cpp" />
|
<ClCompile Include="src\hrtf\kernel_tables.cpp" />
|
||||||
<ClCompile Include="src\hrtf\sofa.cpp" />
|
|
||||||
<ClCompile Include="src\hrtf\sofa_cache.cpp" />
|
|
||||||
<ClCompile Include="src\hrtf\sofa_field.cpp" />
|
|
||||||
<ClCompile Include="src\io\adm_writer.cpp" />
|
<ClCompile Include="src\io\adm_writer.cpp" />
|
||||||
<ClCompile Include="src\io\hdf5.cpp" />
|
<ClCompile Include="src\io\hdf5.cpp" />
|
||||||
<ClCompile Include="src\io\inflate.cpp" />
|
<ClCompile Include="src\io\inflate.cpp" />
|
||||||
@@ -226,7 +223,7 @@
|
|||||||
<ClInclude Include="include\joc_version.h" />
|
<ClInclude Include="include\joc_version.h" />
|
||||||
<ClInclude Include="src\adm\adm_metadata.h" />
|
<ClInclude Include="src\adm\adm_metadata.h" />
|
||||||
<ClInclude Include="src\adm\adm_tracks.h" />
|
<ClInclude Include="src\adm\adm_tracks.h" />
|
||||||
<ClInclude Include="src\binaural\binaural_runtime.h" />
|
<ClInclude Include="src\binaural\jochrtf_runtime.h" />
|
||||||
<ClInclude Include="src\eac3_transport\eac3_reader.h" />
|
<ClInclude Include="src\eac3_transport\eac3_reader.h" />
|
||||||
<ClInclude Include="src\emdf\emdf_parser.h" />
|
<ClInclude Include="src\emdf\emdf_parser.h" />
|
||||||
<ClInclude Include="src\foundation\bit_reader.h" />
|
<ClInclude Include="src\foundation\bit_reader.h" />
|
||||||
@@ -245,9 +242,6 @@
|
|||||||
<ClInclude Include="src\hrtf\rosella_filterbank_tables.h" />
|
<ClInclude Include="src\hrtf\rosella_filterbank_tables.h" />
|
||||||
<ClInclude Include="src\hrtf\rosella_model.h" />
|
<ClInclude Include="src\hrtf\rosella_model.h" />
|
||||||
<ClInclude Include="src\hrtf\rosella_renderer.h" />
|
<ClInclude Include="src\hrtf\rosella_renderer.h" />
|
||||||
<ClInclude Include="src\hrtf\sofa.h" />
|
|
||||||
<ClInclude Include="src\hrtf\sofa_cache.h" />
|
|
||||||
<ClInclude Include="src\hrtf\sofa_field.h" />
|
|
||||||
<ClInclude Include="src\io\adm_writer.h" />
|
<ClInclude Include="src\io\adm_writer.h" />
|
||||||
<ClInclude Include="src\io\hdf5.h" />
|
<ClInclude Include="src\io\hdf5.h" />
|
||||||
<ClInclude Include="src\io\inflate.h" />
|
<ClInclude Include="src\io\inflate.h" />
|
||||||
|
|||||||
@@ -36,16 +36,11 @@ joc::stream::Config to_config(const joc_stream_config& config) {
|
|||||||
}
|
}
|
||||||
out.gain_db = config.gain_db;
|
out.gain_db = config.gain_db;
|
||||||
out.native_threads = config.native_threads;
|
out.native_threads = config.native_threads;
|
||||||
// The binaural HRTF inputs of joc_task_config, copied with the same defaults:
|
|
||||||
// the policy is taken verbatim (0 is "none", a real choice, not "unset") and
|
|
||||||
// the radius keeps its documented default of 1.0 when the field is not set.
|
|
||||||
if (config.hrtf_sofa_path != nullptr) { out.hrtf_sofa_path = config.hrtf_sofa_path; }
|
|
||||||
if (config.personalized_headphone_path != nullptr) {
|
if (config.personalized_headphone_path != nullptr) {
|
||||||
out.personalized_headphone_path = config.personalized_headphone_path;
|
out.personalized_headphone_path = config.personalized_headphone_path;
|
||||||
}
|
}
|
||||||
if (config.hrtf_cache_dir != nullptr) { out.hrtf_cache_dir = config.hrtf_cache_dir; }
|
// 0 is the documented "off" spelling for the room switch.
|
||||||
out.hrtf_cache_policy = config.hrtf_cache_policy;
|
out.jochrtf_room = config.jochrtf_room;
|
||||||
if (config.hrtf_radius_m > 0.0) { out.hrtf_radius_m = config.hrtf_radius_m; }
|
|
||||||
// 0 is "unset" here as well: the Rosella path defaults to the public bank.
|
// 0 is "unset" here as well: the Rosella path defaults to the public bank.
|
||||||
if (config.rosella_filterbank != 0u) {
|
if (config.rosella_filterbank != 0u) {
|
||||||
out.rosella_filterbank = config.rosella_filterbank;
|
out.rosella_filterbank = config.rosella_filterbank;
|
||||||
|
|||||||
+18
-18
@@ -1,7 +1,7 @@
|
|||||||
// Derived from the upstream native/src/sofa_binaural_renderer.cpp (JustOneCacophony
|
// Derived from the upstream native/src/sofa_binaural_renderer.cpp (JustOneCacophony
|
||||||
// @ 6bc2c2885666bb151bb66af93472199af9a99b81, sha256 81b485e4c71907672ab308ddc38228
|
// @ 6bc2c2885666bb151bb66af93472199af9a99b81, sha256 81b485e4c71907672ab308ddc38228
|
||||||
// 4acf29161cee93d7906785a4cce58941c7) and a drop-in replacement for it: the same
|
// 4acf29161cee93d7906785a4cce58941c7) and a drop-in replacement for it: the same
|
||||||
// ejoc_sofa_binaural_* C ABI. The changes are table hoisting, result memoisation,
|
// ejoc_jochrtf_* C ABI. The changes are table hoisting, result memoisation,
|
||||||
// input validation and a dispatched SIMD cascade -- no arithmetic is reordered,
|
// input validation and a dispatched SIMD cascade -- no arithmetic is reordered,
|
||||||
// reassociated or contracted, so the output is bit-identical to the upstream
|
// reassociated or contracted, so the output is bit-identical to the upstream
|
||||||
// implementation (verified: identical FNV-1a over the exact output bit patterns at
|
// implementation (verified: identical FNV-1a over the exact output bit patterns at
|
||||||
@@ -1378,7 +1378,7 @@ using ejoc::sofa_binaural::Renderer;
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
ejoc_sofa_binaural_handle EJOC_CALL ejoc_sofa_binaural_create(void) {
|
ejoc_jochrtf_handle EJOC_CALL ejoc_jochrtf_create(void) {
|
||||||
try {
|
try {
|
||||||
return new (std::nothrow) Renderer();
|
return new (std::nothrow) Renderer();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@@ -1386,21 +1386,21 @@ ejoc_sofa_binaural_handle EJOC_CALL ejoc_sofa_binaural_create(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EJOC_CALL ejoc_sofa_binaural_destroy(ejoc_sofa_binaural_handle handle) {
|
void EJOC_CALL ejoc_jochrtf_destroy(ejoc_jochrtf_handle handle) {
|
||||||
delete static_cast<Renderer*>(handle);
|
delete static_cast<Renderer*>(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_reset(ejoc_sofa_binaural_handle handle) {
|
int EJOC_CALL ejoc_jochrtf_reset(ejoc_jochrtf_handle handle) {
|
||||||
return handle ? static_cast<Renderer*>(handle)->reset() : -1;
|
return handle ? static_cast<Renderer*>(handle)->reset() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* EJOC_CALL ejoc_sofa_binaural_last_error(
|
const char* EJOC_CALL ejoc_jochrtf_last_error(
|
||||||
ejoc_sofa_binaural_handle handle) {
|
ejoc_jochrtf_handle handle) {
|
||||||
return handle ? static_cast<Renderer*>(handle)->error() : "null handle";
|
return handle ? static_cast<Renderer*>(handle)->error() : "null handle";
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
int EJOC_CALL ejoc_jochrtf_configure_kernels(
|
||||||
ejoc_sofa_binaural_handle handle, const double* qmf_analysis,
|
ejoc_jochrtf_handle handle, const double* qmf_analysis,
|
||||||
const double* hybrid_low, const int16_t* hybrid_indices,
|
const double* hybrid_low, const int16_t* hybrid_indices,
|
||||||
const double* hybrid_values, uint32_t hybrid_count, const double* qmf_basis,
|
const double* hybrid_values, uint32_t hybrid_count, const double* qmf_basis,
|
||||||
const double* qmf_taps) {
|
const double* qmf_taps) {
|
||||||
@@ -1409,8 +1409,8 @@ int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
|||||||
qmf_basis, qmf_taps) : -1;
|
qmf_basis, qmf_taps) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_configure_field(
|
int EJOC_CALL ejoc_jochrtf_configure_field(
|
||||||
ejoc_sofa_binaural_handle handle, const double* coefficients,
|
ejoc_jochrtf_handle handle, const double* coefficients,
|
||||||
const double* delay_coefficients, const double* delay_bounds,
|
const double* delay_coefficients, const double* delay_bounds,
|
||||||
const double* band_centers, double measurement_radius_m) {
|
const double* band_centers, double measurement_radius_m) {
|
||||||
return handle ? static_cast<Renderer*>(handle)->configure_field(
|
return handle ? static_cast<Renderer*>(handle)->configure_field(
|
||||||
@@ -1418,8 +1418,8 @@ int EJOC_CALL ejoc_sofa_binaural_configure_field(
|
|||||||
measurement_radius_m) : -1;
|
measurement_radius_m) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
int EJOC_CALL ejoc_jochrtf_configure_room(
|
||||||
ejoc_sofa_binaural_handle handle, const double* room_dims,
|
ejoc_jochrtf_handle handle, const double* room_dims,
|
||||||
const double* listener_pos, const double* wall_gains, double speed_of_sound,
|
const double* listener_pos, const double* wall_gains, double speed_of_sound,
|
||||||
const uint32_t* fdn_delays, const double* fdn_feedback, double damping,
|
const uint32_t* fdn_delays, const double* fdn_feedback, double damping,
|
||||||
double fdn_output_gain, const uint32_t* allpass_delays,
|
double fdn_output_gain, const uint32_t* allpass_delays,
|
||||||
@@ -1430,24 +1430,24 @@ int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
|||||||
enable_early, enable_late) : -1;
|
enable_early, enable_late) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_set_source(
|
int EJOC_CALL ejoc_jochrtf_set_source(
|
||||||
ejoc_sofa_binaural_handle handle, uint32_t source, const double* position_adm,
|
ejoc_jochrtf_handle handle, uint32_t source, const double* position_adm,
|
||||||
uint32_t profile, double gain, uint32_t enabled, uint32_t special_lfe,
|
uint32_t profile, double gain, uint32_t enabled, uint32_t special_lfe,
|
||||||
uint32_t fade) {
|
uint32_t fade) {
|
||||||
return handle ? static_cast<Renderer*>(handle)->set_source(
|
return handle ? static_cast<Renderer*>(handle)->set_source(
|
||||||
source, position_adm, profile, gain, enabled, special_lfe, fade) : -1;
|
source, position_adm, profile, gain, enabled, special_lfe, fade) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_process(
|
int EJOC_CALL ejoc_jochrtf_process(
|
||||||
ejoc_sofa_binaural_handle handle, const double* input16_interleaved,
|
ejoc_jochrtf_handle handle, const double* input16_interleaved,
|
||||||
uint32_t sample_count, double output_gain, double* output_stereo_interleaved) {
|
uint32_t sample_count, double output_gain, double* output_stereo_interleaved) {
|
||||||
return handle ? static_cast<Renderer*>(handle)->process(
|
return handle ? static_cast<Renderer*>(handle)->process(
|
||||||
input16_interleaved, sample_count, output_gain, output_stereo_interleaved)
|
input16_interleaved, sample_count, output_gain, output_stereo_interleaved)
|
||||||
: -1;
|
: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EJOC_CALL ejoc_sofa_binaural_finish(
|
int EJOC_CALL ejoc_jochrtf_finish(
|
||||||
ejoc_sofa_binaural_handle handle, uint32_t flush_samples,
|
ejoc_jochrtf_handle handle, uint32_t flush_samples,
|
||||||
double* output_stereo_interleaved, uint32_t capacity) {
|
double* output_stereo_interleaved, uint32_t capacity) {
|
||||||
return handle ? static_cast<Renderer*>(handle)->finish(
|
return handle ? static_cast<Renderer*>(handle)->finish(
|
||||||
flush_samples, output_stereo_interleaved, capacity) : -1;
|
flush_samples, output_stereo_interleaved, capacity) : -1;
|
||||||
+26
-26
@@ -1,4 +1,4 @@
|
|||||||
#include "binaural/binaural_runtime.h"
|
#include "binaural/jochrtf_runtime.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -29,14 +29,14 @@ bool profile_from_name(const char* name, Profile* out) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SofaBinauralRuntime::~SofaBinauralRuntime() {
|
JochrtfRuntime::~JochrtfRuntime() {
|
||||||
if (handle_ != nullptr) {
|
if (handle_ != nullptr) {
|
||||||
ejoc_sofa_binaural_destroy(handle_);
|
ejoc_jochrtf_destroy(handle_);
|
||||||
handle_ = nullptr;
|
handle_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Status SofaBinauralRuntime::open(const hrtf::Field& field, const hrtf::Kernels& kernels,
|
Status JochrtfRuntime::open(const hrtf::Field& field, const hrtf::Kernels& kernels,
|
||||||
Profile profile, const RoomConstants& room) {
|
Profile profile, const RoomConstants& room) {
|
||||||
if (handle_ != nullptr) {
|
if (handle_ != nullptr) {
|
||||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime already open");
|
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime already open");
|
||||||
@@ -47,36 +47,36 @@ Status SofaBinauralRuntime::open(const hrtf::Field& field, const hrtf::Kernels&
|
|||||||
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
||||||
"compiled HRTF field has unexpected array sizes");
|
"compiled HRTF field has unexpected array sizes");
|
||||||
}
|
}
|
||||||
handle_ = ejoc_sofa_binaural_create();
|
handle_ = ejoc_jochrtf_create();
|
||||||
if (handle_ == nullptr) {
|
if (handle_ == nullptr) {
|
||||||
return Status::fail(JOC_ERR_OUT_OF_MEMORY, stage::kRender,
|
return Status::fail(JOC_ERR_OUT_OF_MEMORY, stage::kRender,
|
||||||
"ejoc_sofa_binaural_create failed");
|
"ejoc_jochrtf_create failed");
|
||||||
}
|
}
|
||||||
profile_ = profile;
|
profile_ = profile;
|
||||||
|
|
||||||
if (ejoc_sofa_binaural_configure_kernels(
|
if (ejoc_jochrtf_configure_kernels(
|
||||||
handle_, kernels.qmf_analysis.data(), kernels.hybrid_low.data(),
|
handle_, kernels.qmf_analysis.data(), kernels.hybrid_low.data(),
|
||||||
kernels.hybrid_indices.data(), kernels.hybrid_values.data(), kernels.hybrid_count,
|
kernels.hybrid_indices.data(), kernels.hybrid_values.data(), kernels.hybrid_count,
|
||||||
kernels.qmf_basis.data(), kernels.qmf_taps.data()) != 0) {
|
kernels.qmf_basis.data(), kernels.qmf_taps.data()) != 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
||||||
std::string("configure_kernels failed: ") +
|
std::string("configure_kernels failed: ") +
|
||||||
(message != nullptr ? message : "unknown"));
|
(message != nullptr ? message : "unknown"));
|
||||||
}
|
}
|
||||||
if (ejoc_sofa_binaural_configure_field(handle_, field.coefficients.data(),
|
if (ejoc_jochrtf_configure_field(handle_, field.coefficients.data(),
|
||||||
field.delay_coefficients.data(),
|
field.delay_coefficients.data(),
|
||||||
field.delay_bounds.data(), field.band_centers_hz.data(),
|
field.delay_bounds.data(), field.band_centers_hz.data(),
|
||||||
field.measurement_radius_m) != 0) {
|
field.measurement_radius_m) != 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
||||||
std::string("configure_field failed: ") +
|
std::string("configure_field failed: ") +
|
||||||
(message != nullptr ? message : "unknown"));
|
(message != nullptr ? message : "unknown"));
|
||||||
}
|
}
|
||||||
if (ejoc_sofa_binaural_configure_room(
|
if (ejoc_jochrtf_configure_room(
|
||||||
handle_, room.dims, room.listener, room.walls, room.speed_of_sound, room.fdn_delays,
|
handle_, room.dims, room.listener, room.walls, room.speed_of_sound, room.fdn_delays,
|
||||||
room.fdn_feedback, room.damping, room.fdn_output_gain, room.allpass_delays,
|
room.fdn_feedback, room.damping, room.fdn_output_gain, room.allpass_delays,
|
||||||
room.allpass_gains, room.enable_early_reflections, room.enable_late_room) != 0) {
|
room.allpass_gains, room.enable_early_reflections, room.enable_late_room) != 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||||
std::string("configure_room failed: ") +
|
std::string("configure_room failed: ") +
|
||||||
(message != nullptr ? message : "unknown"));
|
(message != nullptr ? message : "unknown"));
|
||||||
@@ -95,7 +95,7 @@ Status SofaBinauralRuntime::open(const hrtf::Field& field, const hrtf::Kernels&
|
|||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status SofaBinauralRuntime::process_block() {
|
Status JochrtfRuntime::process_block() {
|
||||||
double positions[timeline::kTimelineObjects][3] = {};
|
double positions[timeline::kTimelineObjects][3] = {};
|
||||||
const Status queried = timeline_.positions_at(static_cast<std::int64_t>(processed_samples_),
|
const Status queried = timeline_.positions_at(static_cast<std::int64_t>(processed_samples_),
|
||||||
positions);
|
positions);
|
||||||
@@ -106,28 +106,28 @@ Status SofaBinauralRuntime::process_block() {
|
|||||||
// backend default (fade enabled) applies - the per-object path crossfade is
|
// backend default (fade enabled) applies - the per-object path crossfade is
|
||||||
// part of the reference behaviour, not an optional extra.
|
// part of the reference behaviour, not an optional extra.
|
||||||
constexpr std::uint32_t kFade = 1u;
|
constexpr std::uint32_t kFade = 1u;
|
||||||
if (ejoc_sofa_binaural_set_source(handle_, 0u, kLfePosition,
|
if (ejoc_jochrtf_set_source(handle_, 0u, kLfePosition,
|
||||||
static_cast<std::uint32_t>(profile_), 1.0, 1u, 1u,
|
static_cast<std::uint32_t>(profile_), 1.0, 1u, 1u,
|
||||||
kFade) != 0) {
|
kFade) != 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||||
std::string("set_source(LFE) failed: ") +
|
std::string("set_source(LFE) failed: ") +
|
||||||
(message != nullptr ? message : "unknown"));
|
(message != nullptr ? message : "unknown"));
|
||||||
}
|
}
|
||||||
for (std::uint32_t source = 0; source < timeline::kTimelineObjects; ++source) {
|
for (std::uint32_t source = 0; source < timeline::kTimelineObjects; ++source) {
|
||||||
if (ejoc_sofa_binaural_set_source(handle_, source + 1u, positions[source],
|
if (ejoc_jochrtf_set_source(handle_, source + 1u, positions[source],
|
||||||
static_cast<std::uint32_t>(profile_), 1.0, 1u, 0u,
|
static_cast<std::uint32_t>(profile_), 1.0, 1u, 0u,
|
||||||
kFade) != 0) {
|
kFade) != 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||||
std::string("set_source(object ") + std::to_string(source + 1u) +
|
std::string("set_source(object ") + std::to_string(source + 1u) +
|
||||||
") failed: " + (message != nullptr ? message : "unknown"));
|
") failed: " + (message != nullptr ? message : "unknown"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const int trimmed = ejoc_sofa_binaural_process(handle_, staging_.data(), kBlockSamples, 1.0,
|
const int trimmed = ejoc_jochrtf_process(handle_, staging_.data(), kBlockSamples, 1.0,
|
||||||
block_output_.data());
|
block_output_.data());
|
||||||
if (trimmed < 0) {
|
if (trimmed < 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||||
std::string("sofa process failed: ") +
|
std::string("sofa process failed: ") +
|
||||||
(message != nullptr ? message : "unknown"));
|
(message != nullptr ? message : "unknown"));
|
||||||
@@ -142,7 +142,7 @@ Status SofaBinauralRuntime::process_block() {
|
|||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status SofaBinauralRuntime::submit_frame(const float* objects16_planar,
|
Status JochrtfRuntime::submit_frame(const float* objects16_planar,
|
||||||
const oamd::OamdUpdate* update, std::int64_t frame_index,
|
const oamd::OamdUpdate* update, std::int64_t frame_index,
|
||||||
std::int64_t outer_sample_offset,
|
std::int64_t outer_sample_offset,
|
||||||
std::int64_t object_delay_samples) {
|
std::int64_t object_delay_samples) {
|
||||||
@@ -186,7 +186,7 @@ Status SofaBinauralRuntime::submit_frame(const float* objects16_planar,
|
|||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t SofaBinauralRuntime::finish_capacity(double tail_seconds) const {
|
std::uint32_t JochrtfRuntime::finish_capacity(double tail_seconds) const {
|
||||||
std::int64_t requested = tail_samples_;
|
std::int64_t requested = tail_samples_;
|
||||||
if (tail_seconds >= 0.0) {
|
if (tail_seconds >= 0.0) {
|
||||||
requested = static_cast<std::int64_t>(std::ceil(tail_seconds * 48000.0 - 1e-9));
|
requested = static_cast<std::int64_t>(std::ceil(tail_seconds * 48000.0 - 1e-9));
|
||||||
@@ -198,11 +198,11 @@ std::uint32_t SofaBinauralRuntime::finish_capacity(double tail_seconds) const {
|
|||||||
return static_cast<std::uint32_t>(drain);
|
return static_cast<std::uint32_t>(drain);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status SofaBinauralRuntime::reset() {
|
Status JochrtfRuntime::reset() {
|
||||||
if (handle_ == nullptr) {
|
if (handle_ == nullptr) {
|
||||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime is not open");
|
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime is not open");
|
||||||
}
|
}
|
||||||
if (ejoc_sofa_binaural_reset(handle_) != 0) {
|
if (ejoc_jochrtf_reset(handle_) != 0) {
|
||||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender, "sofa reset failed");
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender, "sofa reset failed");
|
||||||
}
|
}
|
||||||
timeline_.reset();
|
timeline_.reset();
|
||||||
@@ -214,7 +214,7 @@ Status SofaBinauralRuntime::reset() {
|
|||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status SofaBinauralRuntime::finish(std::uint32_t flush_samples, std::vector<double>* out) {
|
Status JochrtfRuntime::finish(std::uint32_t flush_samples, std::vector<double>* out) {
|
||||||
if (handle_ == nullptr) {
|
if (handle_ == nullptr) {
|
||||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime is not open");
|
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime is not open");
|
||||||
}
|
}
|
||||||
@@ -230,9 +230,9 @@ Status SofaBinauralRuntime::finish(std::uint32_t flush_samples, std::vector<doub
|
|||||||
std::uint32_t remaining = flush_samples;
|
std::uint32_t remaining = flush_samples;
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
const std::uint32_t request = std::min<std::uint32_t>(remaining, kBlockSamples);
|
const std::uint32_t request = std::min<std::uint32_t>(remaining, kBlockSamples);
|
||||||
const int produced = ejoc_sofa_binaural_finish(handle_, request, chunk.data(), request);
|
const int produced = ejoc_jochrtf_finish(handle_, request, chunk.data(), request);
|
||||||
if (produced < 0) {
|
if (produced < 0) {
|
||||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||||
std::string("sofa finish failed: ") +
|
std::string("sofa finish failed: ") +
|
||||||
(message != nullptr ? message : "unknown"));
|
(message != nullptr ? message : "unknown"));
|
||||||
@@ -38,13 +38,13 @@ enum class Profile : std::uint32_t { Near = 0, Mid = 1, Far = 2 };
|
|||||||
|
|
||||||
bool profile_from_name(const char* name, Profile* out);
|
bool profile_from_name(const char* name, Profile* out);
|
||||||
|
|
||||||
class SofaBinauralRuntime {
|
class JochrtfRuntime {
|
||||||
public:
|
public:
|
||||||
SofaBinauralRuntime() = default;
|
JochrtfRuntime() = default;
|
||||||
~SofaBinauralRuntime();
|
~JochrtfRuntime();
|
||||||
|
|
||||||
SofaBinauralRuntime(const SofaBinauralRuntime&) = delete;
|
JochrtfRuntime(const JochrtfRuntime&) = delete;
|
||||||
SofaBinauralRuntime& operator=(const SofaBinauralRuntime&) = delete;
|
JochrtfRuntime& operator=(const JochrtfRuntime&) = delete;
|
||||||
|
|
||||||
Status open(const hrtf::Field& field, const hrtf::Kernels& kernels, Profile profile,
|
Status open(const hrtf::Field& field, const hrtf::Kernels& kernels, Profile profile,
|
||||||
const RoomConstants& room = RoomConstants{});
|
const RoomConstants& room = RoomConstants{});
|
||||||
@@ -83,7 +83,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Status process_block();
|
Status process_block();
|
||||||
|
|
||||||
ejoc_sofa_binaural_handle handle_ = nullptr;
|
ejoc_jochrtf_handle handle_ = nullptr;
|
||||||
Profile profile_ = Profile::Mid;
|
Profile profile_ = Profile::Mid;
|
||||||
timeline::OamdPositionTimeline timeline_;
|
timeline::OamdPositionTimeline timeline_;
|
||||||
std::vector<double> staging_;
|
std::vector<double> staging_;
|
||||||
+22
-97
@@ -4,7 +4,7 @@
|
|||||||
// choices and defaults, and the same default output naming under output/.
|
// choices and defaults, and the same default output naming under output/.
|
||||||
//
|
//
|
||||||
// Options that exist only because this build has no Python side or no Rosella
|
// Options that exist only because this build has no Python side or no Rosella
|
||||||
// import chain (--backend python, --sofa-hrtf, --personalized-headphone,
|
// import chain (--backend python, --personalized-headphone,
|
||||||
// metadata sidecars) fail with an explicit message instead of being ignored.
|
// metadata sidecars) fail with an explicit message instead of being ignored.
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -40,15 +40,12 @@ struct Options {
|
|||||||
std::string clip_action = "ask";
|
std::string clip_action = "ask";
|
||||||
int speaker_metadata_offset = 1473;
|
int speaker_metadata_offset = 1473;
|
||||||
std::string binaural_mode = "mid";
|
std::string binaural_mode = "mid";
|
||||||
std::string sofa_hrtf;
|
|
||||||
std::string compiled_hrtf_cache;
|
std::string compiled_hrtf_cache;
|
||||||
|
std::string jochrtf_room = "on";
|
||||||
std::string personalized_headphone;
|
std::string personalized_headphone;
|
||||||
bool personalized_headphone_used = false;
|
bool personalized_headphone_used = false;
|
||||||
int rosella_filterbank = 1;
|
int rosella_filterbank = 1;
|
||||||
bool rosella_filterbank_set = false;
|
bool rosella_filterbank_set = false;
|
||||||
std::string hrtf_cache_policy;
|
|
||||||
std::string hrtf_cache_dir;
|
|
||||||
double hrtf_radius_m = 1.0;
|
|
||||||
double binaural_tail_seconds = 5.0;
|
double binaural_tail_seconds = 5.0;
|
||||||
double binaural_tail_threshold = 1.0e-8;
|
double binaural_tail_threshold = 1.0e-8;
|
||||||
int binaural_chunk_frames = 64;
|
int binaural_chunk_frames = 64;
|
||||||
@@ -117,15 +114,12 @@ void print_usage() {
|
|||||||
" --speaker-metadata-offset N 扬声器渲染 metadata 相对帧偏移,默认 1473 samples\n"
|
" --speaker-metadata-offset N 扬声器渲染 metadata 相对帧偏移,默认 1473 samples\n"
|
||||||
" --binaural-mode M 双耳渲染模式 off|near|mid|far,默认 mid;\n"
|
" --binaural-mode M 双耳渲染模式 off|near|mid|far,默认 mid;\n"
|
||||||
" off 仅用于 ADM BWF(关闭 DBMD 双耳提示)\n"
|
" off 仅用于 ADM BWF(关闭 DBMD 双耳提示)\n"
|
||||||
" --sofa-hrtf PATH SOFA SimpleFreeFieldHRIR 输入;.jochrtf 由本工具内部编译\n"
|
|
||||||
" --personalized-headphone [PATH] Rosella 个性化模型,默认 "
|
" --personalized-headphone [PATH] Rosella 个性化模型,默认 "
|
||||||
"HRTF/binaural.personalized_headphone\n"
|
"HRTF/binaural.personalized_headphone\n"
|
||||||
" --rosella-filterbank N Rosella 模型滤波器组:1=13 taps/6 slots(默认),\n"
|
" --rosella-filterbank N Rosella 模型滤波器组:1=13 taps/6 slots(默认),\n"
|
||||||
" 2=11 taps/3 slots;仅作用于个性化模型\n"
|
" 2=11 taps/3 slots;仅作用于个性化模型\n"
|
||||||
" --compiled-hrtf-cache PATH 直接读取 .jochrtf(高级用法,跳过 SOFA 编译)\n"
|
" --compiled-hrtf-cache PATH 读取离线编译好的 .jochrtf\n"
|
||||||
" --hrtf-cache-policy P SOFA 编译缓存策略 none|memory|disk,默认 memory\n"
|
" --jochrtf-room on|off .jochrtf 的项目房间,默认 on;off 只输出直达声\n"
|
||||||
" --hrtf-cache-dir DIR disk cache 目录,默认 <exe>/output/hrtf-cache\n"
|
|
||||||
" --hrtf-radius-m R 选择最近的 SOFA measurement-radius shell,默认 1.0 m\n"
|
|
||||||
" --binaural-tail-seconds S 双耳 room/filterbank flush 上限,默认 5 秒\n"
|
" --binaural-tail-seconds S 双耳 room/filterbank flush 上限,默认 5 秒\n"
|
||||||
" --binaural-tail-threshold T 双耳尾声裁切阈值,默认 1e-8;主体至少保留原时长\n"
|
" --binaural-tail-threshold T 双耳尾声裁切阈值,默认 1e-8;主体至少保留原时长\n"
|
||||||
" --binaural-chunk-frames N 双耳内部批处理帧数,默认 64(本构建按 512 块渲染,\n"
|
" --binaural-chunk-frames N 双耳内部批处理帧数,默认 64(本构建按 512 块渲染,\n"
|
||||||
@@ -231,8 +225,8 @@ void parse_args(const std::vector<std::string>& arguments, Options* options) {
|
|||||||
to_int(require_value(arguments, &index), "--speaker-metadata-offset"));
|
to_int(require_value(arguments, &index), "--speaker-metadata-offset"));
|
||||||
}
|
}
|
||||||
else if (arg == "--binaural-mode") { options->binaural_mode = require_value(arguments, &index); }
|
else if (arg == "--binaural-mode") { options->binaural_mode = require_value(arguments, &index); }
|
||||||
else if (arg == "--sofa-hrtf") { options->sofa_hrtf = require_value(arguments, &index); }
|
|
||||||
else if (arg == "--compiled-hrtf-cache") { options->compiled_hrtf_cache = require_value(arguments, &index); }
|
else if (arg == "--compiled-hrtf-cache") { options->compiled_hrtf_cache = require_value(arguments, &index); }
|
||||||
|
else if (arg == "--jochrtf-room") { options->jochrtf_room = require_value(arguments, &index); }
|
||||||
else if (arg == "--personalized-headphone") {
|
else if (arg == "--personalized-headphone") {
|
||||||
options->personalized_headphone_used = true;
|
options->personalized_headphone_used = true;
|
||||||
// nargs="?": the path is optional, so the next token may be the input.
|
// nargs="?": the path is optional, so the next token may be the input.
|
||||||
@@ -247,9 +241,6 @@ void parse_args(const std::vector<std::string>& arguments, Options* options) {
|
|||||||
to_int(require_value(arguments, &index), "--rosella-filterbank"));
|
to_int(require_value(arguments, &index), "--rosella-filterbank"));
|
||||||
options->rosella_filterbank_set = true;
|
options->rosella_filterbank_set = true;
|
||||||
}
|
}
|
||||||
else if (arg == "--hrtf-cache-policy") { options->hrtf_cache_policy = require_value(arguments, &index); }
|
|
||||||
else if (arg == "--hrtf-cache-dir") { options->hrtf_cache_dir = require_value(arguments, &index); }
|
|
||||||
else if (arg == "--hrtf-radius-m") { options->hrtf_radius_m = to_double(require_value(arguments, &index), "--hrtf-radius-m"); }
|
|
||||||
else if (arg == "--binaural-tail-seconds") { options->binaural_tail_seconds = to_double(require_value(arguments, &index), "--binaural-tail-seconds"); }
|
else if (arg == "--binaural-tail-seconds") { options->binaural_tail_seconds = to_double(require_value(arguments, &index), "--binaural-tail-seconds"); }
|
||||||
else if (arg == "--binaural-tail-threshold") { options->binaural_tail_threshold = to_double(require_value(arguments, &index), "--binaural-tail-threshold"); }
|
else if (arg == "--binaural-tail-threshold") { options->binaural_tail_threshold = to_double(require_value(arguments, &index), "--binaural-tail-threshold"); }
|
||||||
else if (arg == "--binaural-chunk-frames") { options->binaural_chunk_frames = static_cast<int>(to_int(require_value(arguments, &index), "--binaural-chunk-frames")); }
|
else if (arg == "--binaural-chunk-frames") { options->binaural_chunk_frames = static_cast<int>(to_int(require_value(arguments, &index), "--binaural-chunk-frames")); }
|
||||||
@@ -345,16 +336,12 @@ std::string find_kernels(const Options& options, const std::string& argv0) {
|
|||||||
return options.kernels;
|
return options.kernels;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mirrors the reference binaural HRTF resolution (main.py:89-160): the SOFA file
|
// The binaural input is either an explicitly compiled .jochrtf field or a Rosella
|
||||||
// is the user-facing input and the .jochrtf is only its compiled cache. Paths
|
// .personalized_headphone model. Paths are anchored at the executable directory,
|
||||||
// are anchored at the executable directory, as the reference anchors them at the
|
// as the reference anchors them at the project directory.
|
||||||
// project directory.
|
|
||||||
struct HrtfInput {
|
struct HrtfInput {
|
||||||
std::string sofa_path; // compile this
|
std::string compiled_path; // read this .jochrtf
|
||||||
std::string compiled_path; // or read this .jochrtf directly
|
|
||||||
std::string cache_dir; // disk policy directory
|
|
||||||
std::string personalized_path; // Rosella .personalized_headphone
|
std::string personalized_path; // Rosella .personalized_headphone
|
||||||
bool disk = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string resolve_compiled_hrtf(const Options& options, const std::string& project_directory) {
|
std::string resolve_compiled_hrtf(const Options& options, const std::string& project_directory) {
|
||||||
@@ -362,9 +349,7 @@ std::string resolve_compiled_hrtf(const Options& options, const std::string& pro
|
|||||||
return options.compiled_hrtf_cache;
|
return options.compiled_hrtf_cache;
|
||||||
}
|
}
|
||||||
const std::string directory_utf8 =
|
const std::string directory_utf8 =
|
||||||
options.hrtf_cache_dir.empty()
|
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache");
|
||||||
? fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache")
|
|
||||||
: options.hrtf_cache_dir;
|
|
||||||
if (!fs_utf8::is_directory(directory_utf8)) {
|
if (!fs_utf8::is_directory(directory_utf8)) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
@@ -378,34 +363,18 @@ std::string resolve_compiled_hrtf(const Options& options, const std::string& pro
|
|||||||
std::sort(candidates.begin(), candidates.end());
|
std::sort(candidates.begin(), candidates.end());
|
||||||
if (candidates.size() > 1u) {
|
if (candidates.size() > 1u) {
|
||||||
fail(directory_utf8 +
|
fail(directory_utf8 +
|
||||||
" 下有多个 .jochrtf 缓存,无法自动选择;请用 --sofa-hrtf PATH 或 "
|
" 下有多个 .jochrtf 缓存,无法自动选择;请用 --compiled-hrtf-cache PATH 显式指定");
|
||||||
"--compiled-hrtf-cache PATH 显式指定");
|
|
||||||
}
|
}
|
||||||
return candidates.empty() ? std::string() : fs_utf8::from_path(candidates.front());
|
return candidates.empty() ? std::string() : fs_utf8::from_path(candidates.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_directory) {
|
HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_directory) {
|
||||||
HrtfInput input;
|
HrtfInput input;
|
||||||
const std::string default_sofa =
|
|
||||||
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "HRTF" / "binaural.sofa");
|
|
||||||
const std::string default_private = fs_utf8::from_path(
|
const std::string default_private = fs_utf8::from_path(
|
||||||
fs_utf8::to_path(project_directory) / "HRTF" / "binaural.personalized_headphone");
|
fs_utf8::to_path(project_directory) / "HRTF" / "binaural.personalized_headphone");
|
||||||
const std::string default_cache_dir =
|
const std::string default_cache_dir =
|
||||||
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache");
|
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache");
|
||||||
|
|
||||||
if (!options.compiled_hrtf_cache.empty() && !options.hrtf_cache_policy.empty()) {
|
|
||||||
fail("显式 .jochrtf 输入不能再指定 --hrtf-cache-policy");
|
|
||||||
}
|
|
||||||
if (!options.compiled_hrtf_cache.empty() && options.hrtf_radius_m != 1.0) {
|
|
||||||
fail("显式 .jochrtf 输入不能再选择 SOFA radius shell");
|
|
||||||
}
|
|
||||||
if (options.personalized_headphone_used &&
|
|
||||||
(!options.hrtf_cache_policy.empty() || !options.hrtf_cache_dir.empty() ||
|
|
||||||
options.hrtf_radius_m != 1.0)) {
|
|
||||||
fail("Rosella 模型输入不能使用 --hrtf-cache-policy/--hrtf-cache-dir/--hrtf-radius-m");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string sofa = options.sofa_hrtf;
|
|
||||||
std::string compiled = options.compiled_hrtf_cache;
|
std::string compiled = options.compiled_hrtf_cache;
|
||||||
std::string personalized =
|
std::string personalized =
|
||||||
options.personalized_headphone_used ? options.personalized_headphone : std::string();
|
options.personalized_headphone_used ? options.personalized_headphone : std::string();
|
||||||
@@ -413,18 +382,13 @@ HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_
|
|||||||
// "--personalized-headphone" without a path means the project default.
|
// "--personalized-headphone" without a path means the project default.
|
||||||
personalized = default_private;
|
personalized = default_private;
|
||||||
}
|
}
|
||||||
if (sofa.empty() && compiled.empty() && personalized.empty()) {
|
if (compiled.empty() && personalized.empty()) {
|
||||||
// The reference order: the SOFA file, then the unique compiled cache, then the
|
// The compiled cache, then the personalized model.
|
||||||
// personalized model.
|
|
||||||
if (fs_utf8::exists(default_sofa)) {
|
|
||||||
sofa = default_sofa;
|
|
||||||
} else {
|
|
||||||
compiled = resolve_compiled_hrtf(options, project_directory);
|
compiled = resolve_compiled_hrtf(options, project_directory);
|
||||||
if (compiled.empty() && fs_utf8::exists(default_private)) {
|
if (compiled.empty() && fs_utf8::exists(default_private)) {
|
||||||
personalized = default_private;
|
personalized = default_private;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!personalized.empty()) {
|
if (!personalized.empty()) {
|
||||||
if (!fs_utf8::exists(personalized)) {
|
if (!fs_utf8::exists(personalized)) {
|
||||||
fail("双耳模型不存在: " + personalized);
|
fail("双耳模型不存在: " + personalized);
|
||||||
@@ -432,36 +396,13 @@ HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_
|
|||||||
input.personalized_path = personalized;
|
input.personalized_path = personalized;
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
if (sofa.empty() && compiled.empty()) {
|
if (compiled.empty()) {
|
||||||
if (!options.hrtf_cache_policy.empty() || !options.hrtf_cache_dir.empty() ||
|
fail("--binaural 未找到 HRTF 输入:默认 " + default_private + " 与 " + default_cache_dir +
|
||||||
options.hrtf_radius_m != 1.0) {
|
" 下的 .jochrtf 都不存在,请用 --personalized-headphone PATH 或 "
|
||||||
fail("HRTF cache/radius 选项需要 --sofa-hrtf");
|
"--compiled-hrtf-cache PATH 指定");
|
||||||
}
|
}
|
||||||
fail("--binaural 未找到 HRTF 输入:默认 " + default_sofa + "、" + default_private +
|
|
||||||
" 或 " + default_cache_dir +
|
|
||||||
" 下的 .jochrtf 都不存在,请用 --sofa-hrtf PATH、--personalized-headphone PATH "
|
|
||||||
"或 --compiled-hrtf-cache PATH 指定");
|
|
||||||
}
|
|
||||||
if (sofa.empty() && (!options.hrtf_cache_policy.empty() || !options.hrtf_cache_dir.empty() ||
|
|
||||||
options.hrtf_radius_m != 1.0)) {
|
|
||||||
fail("HRTF cache/radius 选项需要 --sofa-hrtf");
|
|
||||||
}
|
|
||||||
if (sofa.empty()) {
|
|
||||||
input.compiled_path = compiled;
|
input.compiled_path = compiled;
|
||||||
return input;
|
return input;
|
||||||
}
|
|
||||||
const std::string effective_policy =
|
|
||||||
options.hrtf_cache_policy.empty() ? "memory" : options.hrtf_cache_policy;
|
|
||||||
if (!options.hrtf_cache_dir.empty() && effective_policy != "disk") {
|
|
||||||
fail("--hrtf-cache-dir 需要 SOFA 与 disk cache policy 一起使用");
|
|
||||||
}
|
|
||||||
input.sofa_path = sofa;
|
|
||||||
input.disk = effective_policy == "disk";
|
|
||||||
input.cache_dir = options.hrtf_cache_dir.empty() ? default_cache_dir : options.hrtf_cache_dir;
|
|
||||||
if (!fs_utf8::exists(input.sofa_path)) {
|
|
||||||
fail("SOFA HRTF 不存在: " + input.sofa_path);
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t binaural_mode_value(const std::string& name) {
|
std::uint32_t binaural_mode_value(const std::string& name) {
|
||||||
@@ -567,10 +508,6 @@ int main(int argc, char** argv) {
|
|||||||
check_choice(options.backend, "--backend", {"auto", "native", "python"});
|
check_choice(options.backend, "--backend", {"auto", "native", "python"});
|
||||||
check_choice(options.print_metadata, "--print-metadata", {"none", "summary", "frames"});
|
check_choice(options.print_metadata, "--print-metadata", {"none", "summary", "frames"});
|
||||||
check_choice(options.metadata_backend, "--metadata-backend", {"auto", "emdf", "sidecar"});
|
check_choice(options.metadata_backend, "--metadata-backend", {"auto", "emdf", "sidecar"});
|
||||||
if (!options.hrtf_cache_policy.empty()) {
|
|
||||||
check_choice(options.hrtf_cache_policy, "--hrtf-cache-policy",
|
|
||||||
{"none", "memory", "disk"});
|
|
||||||
}
|
|
||||||
if (options.rosella_filterbank != 1 && options.rosella_filterbank != 2) {
|
if (options.rosella_filterbank != 1 && options.rosella_filterbank != 2) {
|
||||||
fail("--rosella-filterbank: invalid choice: " +
|
fail("--rosella-filterbank: invalid choice: " +
|
||||||
std::to_string(options.rosella_filterbank) + " (choose from 1, 2)");
|
std::to_string(options.rosella_filterbank) + " (choose from 1, 2)");
|
||||||
@@ -602,10 +539,10 @@ int main(int argc, char** argv) {
|
|||||||
if (options.speaker_metadata_offset < 0) {
|
if (options.speaker_metadata_offset < 0) {
|
||||||
fail("speaker-metadata-offset 不能为负数");
|
fail("speaker-metadata-offset 不能为负数");
|
||||||
}
|
}
|
||||||
|
check_choice(options.jochrtf_room, "--jochrtf-room", {"on", "off"});
|
||||||
const bool hrtf_options_used =
|
const bool hrtf_options_used =
|
||||||
!options.sofa_hrtf.empty() || !options.compiled_hrtf_cache.empty() ||
|
!options.compiled_hrtf_cache.empty() || options.personalized_headphone_used ||
|
||||||
options.personalized_headphone_used || !options.hrtf_cache_policy.empty() ||
|
options.jochrtf_room != "on";
|
||||||
!options.hrtf_cache_dir.empty() || options.hrtf_radius_m != 1.0;
|
|
||||||
if (hrtf_options_used && !binaural_mode) {
|
if (hrtf_options_used && !binaural_mode) {
|
||||||
fail("SOFA/HRTF 选项仅与 --binaural 一起使用");
|
fail("SOFA/HRTF 选项仅与 --binaural 一起使用");
|
||||||
}
|
}
|
||||||
@@ -623,9 +560,6 @@ int main(int argc, char** argv) {
|
|||||||
if (options.binaural_chunk_frames <= 0) {
|
if (options.binaural_chunk_frames <= 0) {
|
||||||
fail("binaural-chunk-frames 必须大于 0");
|
fail("binaural-chunk-frames 必须大于 0");
|
||||||
}
|
}
|
||||||
if (!std::isfinite(options.hrtf_radius_m) || options.hrtf_radius_m <= 0.0) {
|
|
||||||
fail("hrtf-radius-m 必须是正有限值");
|
|
||||||
}
|
|
||||||
if (options.duration_set && options.duration <= 0.0) {
|
if (options.duration_set && options.duration <= 0.0) {
|
||||||
fail("duration 必须大于 0");
|
fail("duration 必须大于 0");
|
||||||
}
|
}
|
||||||
@@ -714,22 +648,18 @@ int main(int argc, char** argv) {
|
|||||||
if (options.quiet) { config.flags |= JOC_TASK_F_QUIET; }
|
if (options.quiet) { config.flags |= JOC_TASK_F_QUIET; }
|
||||||
|
|
||||||
std::string hrtf_path;
|
std::string hrtf_path;
|
||||||
std::string hrtf_sofa_path;
|
|
||||||
std::string hrtf_cache_dir;
|
|
||||||
std::string personalized_path;
|
std::string personalized_path;
|
||||||
std::string kernels_path;
|
std::string kernels_path;
|
||||||
if (binaural_mode) {
|
if (binaural_mode) {
|
||||||
try {
|
try {
|
||||||
const HrtfInput input = resolve_hrtf_input(options, project_directory);
|
const HrtfInput input = resolve_hrtf_input(options, project_directory);
|
||||||
hrtf_path = input.compiled_path;
|
hrtf_path = input.compiled_path;
|
||||||
hrtf_sofa_path = input.sofa_path;
|
|
||||||
hrtf_cache_dir = input.cache_dir;
|
|
||||||
personalized_path = input.personalized_path;
|
personalized_path = input.personalized_path;
|
||||||
kernels_path = find_kernels(options, arguments.empty() ? std::string()
|
kernels_path = find_kernels(options, arguments.empty() ? std::string()
|
||||||
: arguments.front());
|
: arguments.front());
|
||||||
if (options.rosella_filterbank_set && personalized_path.empty()) {
|
if (options.rosella_filterbank_set && personalized_path.empty()) {
|
||||||
fail("--rosella-filterbank 只作用于 Rosella .personalized_headphone 输入;"
|
fail("--rosella-filterbank 只作用于 Rosella .personalized_headphone 输入;"
|
||||||
"当前 SOFA/.jochrtf 路径不使用该滤波器组");
|
"当前 .jochrtf 路径不使用该滤波器组");
|
||||||
}
|
}
|
||||||
} catch (const std::exception& error) {
|
} catch (const std::exception& error) {
|
||||||
std::fprintf(stderr, "joc_cli: error: %s\n", error.what());
|
std::fprintf(stderr, "joc_cli: error: %s\n", error.what());
|
||||||
@@ -737,14 +667,9 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.hrtf_path = hrtf_path.empty() ? nullptr : hrtf_path.c_str();
|
config.hrtf_path = hrtf_path.empty() ? nullptr : hrtf_path.c_str();
|
||||||
config.hrtf_sofa_path = hrtf_sofa_path.empty() ? nullptr : hrtf_sofa_path.c_str();
|
|
||||||
config.hrtf_cache_dir = hrtf_cache_dir.empty() ? nullptr : hrtf_cache_dir.c_str();
|
|
||||||
config.personalized_headphone_path =
|
config.personalized_headphone_path =
|
||||||
personalized_path.empty() ? nullptr : personalized_path.c_str();
|
personalized_path.empty() ? nullptr : personalized_path.c_str();
|
||||||
config.hrtf_cache_policy = options.hrtf_cache_policy == "disk" ? JOC_HRTF_CACHE_DISK
|
config.jochrtf_room = options.jochrtf_room == "off" ? 0u : 1u;
|
||||||
: options.hrtf_cache_policy == "none" ? JOC_HRTF_CACHE_NONE
|
|
||||||
: JOC_HRTF_CACHE_MEMORY;
|
|
||||||
config.hrtf_radius_m = options.hrtf_radius_m;
|
|
||||||
config.kernels_path = kernels_path.empty() ? nullptr : kernels_path.c_str();
|
config.kernels_path = kernels_path.empty() ? nullptr : kernels_path.c_str();
|
||||||
|
|
||||||
joc_validation_issue issues[32];
|
joc_validation_issue issues[32];
|
||||||
|
|||||||
@@ -1343,7 +1343,7 @@ void RosellaRuntime::take_output(std::vector<double>* out) {
|
|||||||
if (out == nullptr) {
|
if (out == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Replace semantics, exactly like SofaBinauralRuntime::take_output: the caller's
|
// Replace semantics, exactly like JochrtfRuntime::take_output: the caller's
|
||||||
// previous contents are discarded, and the internal buffer is emptied afterwards
|
// previous contents are discarded, and the internal buffer is emptied afterwards
|
||||||
// because the swap leaves it holding whatever the caller had.
|
// because the swap leaves it holding whatever the caller had.
|
||||||
out->swap(impl_->output);
|
out->swap(impl_->output);
|
||||||
|
|||||||
@@ -1,255 +0,0 @@
|
|||||||
#include "hrtf/sofa.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cctype>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <fstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "foundation/fs_utf8.h"
|
|
||||||
#include "foundation/sha256.h"
|
|
||||||
#include "io/hdf5.h"
|
|
||||||
|
|
||||||
namespace joc::hrtf {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
Status sofa_fail(joc_error code, const std::string& message) {
|
|
||||||
return Status::fail(code, stage::kRender, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string format_number(double value) {
|
|
||||||
if (std::isfinite(value) && value == std::floor(value) && std::fabs(value) < 1.0e15) {
|
|
||||||
return std::to_string(static_cast<long long>(value));
|
|
||||||
}
|
|
||||||
char buffer[32];
|
|
||||||
std::snprintf(buffer, sizeof(buffer), "%.6g", value);
|
|
||||||
return std::string(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Every array is checked against the element count the convention prescribes, so
|
|
||||||
// a file whose shape disagrees with its metadata is rejected instead of silently
|
|
||||||
// producing a shifted impulse response.
|
|
||||||
Status read_doubles(const io::Hdf5File& file, const std::string& path, std::uint64_t expected,
|
|
||||||
std::vector<double>* out) {
|
|
||||||
if (!file.has_dataset(path)) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA file has no " + path + " dataset");
|
|
||||||
}
|
|
||||||
const Status status = file.read_dataset_double(path, out);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA dataset " + path + ": " + status.message());
|
|
||||||
}
|
|
||||||
if (out->size() != expected) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT,
|
|
||||||
"SOFA dataset " + path + " holds " + std::to_string(out->size()) +
|
|
||||||
" values, expected " + std::to_string(expected));
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
Status read_text(const io::Hdf5File& file, const std::string& name, bool required,
|
|
||||||
std::string* out) {
|
|
||||||
io::Hdf5Attribute attribute;
|
|
||||||
const Status status = file.attribute("", name, &attribute);
|
|
||||||
if (!status.ok()) {
|
|
||||||
if (required) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT,
|
|
||||||
"SOFA file has no root attribute " + name + ": " + status.message());
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
*out = attribute.text;
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
// SHA-256 of the whole file: the compiled-cache key is derived from it, so the
|
|
||||||
// digest is taken over the exact bytes the parse consumed.
|
|
||||||
std::string file_digest(const std::string& path) {
|
|
||||||
std::ifstream stream = fs_utf8::open_input(path);
|
|
||||||
if (!stream.good()) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
crypto::Sha256 hash;
|
|
||||||
std::vector<char> buffer(1u << 20);
|
|
||||||
while (stream.good()) {
|
|
||||||
stream.read(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
|
||||||
const std::streamsize count = stream.gcount();
|
|
||||||
if (count > 0) {
|
|
||||||
hash.update(buffer.data(), static_cast<std::size_t>(count));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hash.finish_hex();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The coordinate declaration of one dataset, when the file carries it.
|
|
||||||
void read_coordinates(const io::Hdf5File& file, const std::string& dataset,
|
|
||||||
SofaCoordinate* out) {
|
|
||||||
io::Hdf5Attribute attribute;
|
|
||||||
if (file.attribute(dataset, "Type", &attribute).ok()) {
|
|
||||||
out->type = attribute.text;
|
|
||||||
}
|
|
||||||
if (file.attribute(dataset, "Units", &attribute).ok()) {
|
|
||||||
out->units = attribute.text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
std::string SofaHrir::summary() const {
|
|
||||||
return "SOFA " + sofa_conventions + ", " + std::to_string(ir_count) + " IRs x " +
|
|
||||||
std::to_string(ir_length) + " taps @ " + format_number(sample_rate) + " Hz";
|
|
||||||
}
|
|
||||||
|
|
||||||
Status load_sofa(const std::string& path, SofaHrir* out) {
|
|
||||||
if (out == nullptr) {
|
|
||||||
return sofa_fail(JOC_ERR_INVALID_ARGUMENT, "null SOFA destination");
|
|
||||||
}
|
|
||||||
if (!fs_utf8::exists(path)) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_NOT_FOUND, "SOFA file not found: " + path);
|
|
||||||
}
|
|
||||||
io::Hdf5File file;
|
|
||||||
Status status = file.open(path);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA file " + path + ": " + status.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
SofaHrir sofa;
|
|
||||||
sofa.source_path = path;
|
|
||||||
sofa.source_sha256 = file_digest(path);
|
|
||||||
for (char& character : sofa.source_sha256) {
|
|
||||||
character = static_cast<char>(std::toupper(static_cast<unsigned char>(character)));
|
|
||||||
}
|
|
||||||
status = read_text(file, "Conventions", true, &sofa.conventions);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "SOFAConventions", true, &sofa.sofa_conventions);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (sofa.conventions != "SOFA" || sofa.sofa_conventions != "SimpleFreeFieldHRIR") {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_UNSUPPORTED_CONVENTION,
|
|
||||||
"SOFA conventions " + sofa.conventions + "/" + sofa.sofa_conventions +
|
|
||||||
" are not SimpleFreeFieldHRIR");
|
|
||||||
}
|
|
||||||
status = read_text(file, "SOFAConventionsVersion", false, &sofa.convention_version);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "Version", false, &sofa.version);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "DataType", false, &sofa.data_type);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "RoomType", false, &sofa.room_type);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "Title", false, &sofa.title);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "DatabaseName", false, &sofa.database_name);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "ListenerShortName", false, &sofa.listener_short_name);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = read_text(file, "Comment", false, &sofa.comment);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
io::Hdf5DatasetInfo info;
|
|
||||||
status = file.dataset_info("Data.IR", &info);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT,
|
|
||||||
"SOFA file has no usable Data.IR dataset: " + status.message());
|
|
||||||
}
|
|
||||||
if (info.shape.size() != 3u || info.shape[1] != 2u || info.shape[0] == 0u ||
|
|
||||||
info.shape[2] == 0u) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA Data.IR is not shaped (M, 2, N)");
|
|
||||||
}
|
|
||||||
if (info.shape[0] > 0xFFFFFFFFull || info.shape[2] > 0xFFFFFFFFull) {
|
|
||||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA Data.IR is larger than this reader accepts");
|
|
||||||
}
|
|
||||||
sofa.ir_count = static_cast<std::uint32_t>(info.shape[0]);
|
|
||||||
sofa.ir_length = static_cast<std::uint32_t>(info.shape[2]);
|
|
||||||
const std::uint64_t taps = static_cast<std::uint64_t>(sofa.ir_count) * 2u * sofa.ir_length;
|
|
||||||
status = read_doubles(file, "Data.IR", taps, &sofa.ir);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<double> scalar;
|
|
||||||
status = read_doubles(file, "Data.SamplingRate", 1u, &scalar);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
sofa.sample_rate = scalar[0];
|
|
||||||
io::Hdf5Attribute attribute;
|
|
||||||
if (file.attribute("Data.SamplingRate", "Units", &attribute).ok()) {
|
|
||||||
sofa.sampling_rate_units = attribute.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data.Delay is optional in the wild; absent means "no delay was measured".
|
|
||||||
if (file.has_dataset("Data.Delay")) {
|
|
||||||
std::vector<double> delay;
|
|
||||||
status = read_doubles(file, "Data.Delay", 2u, &delay);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
sofa.delay[0] = delay[0];
|
|
||||||
sofa.delay[1] = delay[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::uint64_t measurements = sofa.ir_count;
|
|
||||||
status = read_doubles(file, "SourcePosition", measurements * 3u, &sofa.source_position);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
read_coordinates(file, "SourcePosition", &sofa.source_position_coordinates);
|
|
||||||
|
|
||||||
std::vector<double> vector;
|
|
||||||
status = read_doubles(file, "ListenerPosition", 3u, &vector);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
std::copy(vector.begin(), vector.end(), sofa.listener_position);
|
|
||||||
read_coordinates(file, "ListenerPosition", &sofa.listener_position_coordinates);
|
|
||||||
status = read_doubles(file, "ListenerView", 3u, &vector);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
std::copy(vector.begin(), vector.end(), sofa.listener_view);
|
|
||||||
read_coordinates(file, "ListenerView", &sofa.listener_view_coordinates);
|
|
||||||
status = read_doubles(file, "ListenerUp", 3u, &vector);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
std::copy(vector.begin(), vector.end(), sofa.listener_up);
|
|
||||||
read_coordinates(file, "ListenerUp", &sofa.listener_up_coordinates);
|
|
||||||
status = read_doubles(file, "EmitterPosition", 3u, &vector);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
std::copy(vector.begin(), vector.end(), sofa.emitter_position);
|
|
||||||
read_coordinates(file, "EmitterPosition", &sofa.emitter_position_coordinates);
|
|
||||||
status = read_doubles(file, "ReceiverPosition", 6u, &vector);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
std::copy(vector.begin(), vector.end(), sofa.receiver_position);
|
|
||||||
read_coordinates(file, "ReceiverPosition", &sofa.receiver_position_coordinates);
|
|
||||||
|
|
||||||
*out = std::move(sofa);
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace joc::hrtf
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "foundation/status.h"
|
|
||||||
|
|
||||||
namespace joc::hrtf {
|
|
||||||
|
|
||||||
// Coordinate declaration of one SOFA variable: Type ("spherical"/"cartesian") and
|
|
||||||
// Units. Empty when the file does not declare them (ListenerUp inherits).
|
|
||||||
struct SofaCoordinate {
|
|
||||||
std::string type;
|
|
||||||
std::string units;
|
|
||||||
};
|
|
||||||
|
|
||||||
// SOFA SimpleFreeFieldHRIR as this project consumes it: the impulse responses,
|
|
||||||
// the measurement geometry and the metadata needed to report what was loaded.
|
|
||||||
// All angles are degrees, all distances metres, exactly as the file stores them.
|
|
||||||
struct SofaHrir {
|
|
||||||
double sample_rate = 0.0;
|
|
||||||
std::uint32_t ir_count = 0; // M: number of measurements
|
|
||||||
std::uint32_t ir_length = 0; // N: taps per impulse response
|
|
||||||
std::vector<double> ir; // C order [M][2][N]
|
|
||||||
double delay[2] = {0.0, 0.0};
|
|
||||||
std::vector<double> source_position; // M*3
|
|
||||||
double listener_position[3] = {0.0, 0.0, 0.0};
|
|
||||||
double listener_view[3] = {1.0, 0.0, 0.0};
|
|
||||||
double listener_up[3] = {0.0, 0.0, 1.0};
|
|
||||||
double emitter_position[3] = {0.0, 0.0, 0.0};
|
|
||||||
double receiver_position[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|
||||||
std::string conventions;
|
|
||||||
std::string sofa_conventions;
|
|
||||||
std::string convention_version;
|
|
||||||
std::string version;
|
|
||||||
std::string data_type;
|
|
||||||
std::string room_type;
|
|
||||||
std::string title;
|
|
||||||
std::string database_name;
|
|
||||||
std::string listener_short_name;
|
|
||||||
std::string comment;
|
|
||||||
std::string sampling_rate_units;
|
|
||||||
SofaCoordinate source_position_coordinates;
|
|
||||||
SofaCoordinate listener_position_coordinates;
|
|
||||||
SofaCoordinate listener_view_coordinates;
|
|
||||||
SofaCoordinate listener_up_coordinates;
|
|
||||||
SofaCoordinate emitter_position_coordinates;
|
|
||||||
SofaCoordinate receiver_position_coordinates;
|
|
||||||
// Identity of the file itself, needed for the compiled-cache key.
|
|
||||||
std::string source_path;
|
|
||||||
std::string source_sha256;
|
|
||||||
|
|
||||||
// One line for reports and logs:
|
|
||||||
// "SOFA SimpleFreeFieldHRIR, <M> IRs x <N> taps @ <rate> Hz".
|
|
||||||
std::string summary() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
Status load_sofa(const std::string& path, SofaHrir* out);
|
|
||||||
|
|
||||||
} // namespace joc::hrtf
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
#include "hrtf/sofa_cache.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <list>
|
|
||||||
#include <mutex>
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "foundation/fs_utf8.h"
|
|
||||||
#include "hrtf/sofa.h"
|
|
||||||
|
|
||||||
namespace joc::hrtf {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
|
|
||||||
// Small process-local cache: the reference keeps the last eight compiled fields.
|
|
||||||
constexpr std::size_t kMemoryCacheEntries = 8;
|
|
||||||
|
|
||||||
struct MemoryEntry {
|
|
||||||
std::string key;
|
|
||||||
Field field;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::mutex& memory_mutex() {
|
|
||||||
static std::mutex mutex;
|
|
||||||
return mutex;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<MemoryEntry>& memory_cache() {
|
|
||||||
static std::list<MemoryEntry> cache;
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool memory_cache_get(const std::string& key, Field* out) {
|
|
||||||
std::lock_guard<std::mutex> lock(memory_mutex());
|
|
||||||
std::list<MemoryEntry>& cache = memory_cache();
|
|
||||||
for (auto entry = cache.begin(); entry != cache.end(); ++entry) {
|
|
||||||
if (entry->key == key) {
|
|
||||||
*out = entry->field;
|
|
||||||
cache.splice(cache.begin(), cache, entry);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory_cache_put(const std::string& key, const Field& field) {
|
|
||||||
std::lock_guard<std::mutex> lock(memory_mutex());
|
|
||||||
std::list<MemoryEntry>& cache = memory_cache();
|
|
||||||
for (auto entry = cache.begin(); entry != cache.end(); ++entry) {
|
|
||||||
if (entry->key == key) {
|
|
||||||
entry->field = field;
|
|
||||||
cache.splice(cache.begin(), cache, entry);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache.push_front(MemoryEntry{key, field});
|
|
||||||
while (cache.size() > kMemoryCacheEntries) {
|
|
||||||
cache.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Status cache_fail(joc_error code, const std::string& message) {
|
|
||||||
return Status::fail(code, stage::kRender, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string upper(std::string text) {
|
|
||||||
std::transform(text.begin(), text.end(), text.begin(), [](unsigned char value) {
|
|
||||||
return static_cast<char>(std::toupper(value));
|
|
||||||
});
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Status parse_cache_policy(const std::string& text, CachePolicy* out) {
|
|
||||||
if (out == nullptr) {
|
|
||||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "null cache policy");
|
|
||||||
}
|
|
||||||
if (text == "none") {
|
|
||||||
*out = CachePolicy::None;
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
if (text == "memory") {
|
|
||||||
*out = CachePolicy::Memory;
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
if (text == "disk") {
|
|
||||||
*out = CachePolicy::Disk;
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
return cache_fail(JOC_ERR_INVALID_CONFIG, "cache_policy must be none, memory, or disk");
|
|
||||||
}
|
|
||||||
|
|
||||||
Status validate_jochrtf(const std::string& path, const std::string& source_sha256,
|
|
||||||
const std::string& cache_key, Field* out) {
|
|
||||||
Field field;
|
|
||||||
const Status status = load_jochrtf(path, &field);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (!source_sha256.empty() && field.source_sha256 != upper(source_sha256)) {
|
|
||||||
return cache_fail(JOC_ERR_HRTF_HASH, "compiled HRTF source hash mismatch");
|
|
||||||
}
|
|
||||||
if (!cache_key.empty() && field.cache_key != upper(cache_key)) {
|
|
||||||
return cache_fail(JOC_ERR_HRTF_HASH, "compiled HRTF configuration hash mismatch");
|
|
||||||
}
|
|
||||||
if (out != nullptr) {
|
|
||||||
*out = std::move(field);
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
Status save_jochrtf_atomic(const Field& field, const std::string& path) {
|
|
||||||
if (path.empty()) {
|
|
||||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "empty compiled HRTF cache path");
|
|
||||||
}
|
|
||||||
const fs::path target = fs_utf8::to_path(path);
|
|
||||||
std::error_code error;
|
|
||||||
if (target.has_parent_path()) {
|
|
||||||
fs::create_directories(target.parent_path(), error);
|
|
||||||
if (error) {
|
|
||||||
return cache_fail(JOC_ERR_OUTPUT_OPEN,
|
|
||||||
"cannot create " + fs_utf8::from_path(target.parent_path()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const std::string temporary = path + ".tmp";
|
|
||||||
Status status = write_jochrtf(field, temporary);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
// The rename is what makes a half-written cache impossible to observe.
|
|
||||||
fs::rename(fs_utf8::to_path(temporary), target, error);
|
|
||||||
if (error) {
|
|
||||||
fs::remove(fs_utf8::to_path(temporary), error);
|
|
||||||
return cache_fail(JOC_ERR_OUTPUT_WRITE, "cannot replace " + path);
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
Status load_or_compile_sofa_field(const SofaFieldRequest& request, Field* out,
|
|
||||||
std::string* cache_path) {
|
|
||||||
if (out == nullptr) {
|
|
||||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "null compiled HRTF destination");
|
|
||||||
}
|
|
||||||
if (request.sofa_path.empty()) {
|
|
||||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "no SOFA path for the compiled HRTF field");
|
|
||||||
}
|
|
||||||
if (request.policy == CachePolicy::Disk && request.cache_dir.empty()) {
|
|
||||||
return cache_fail(JOC_ERR_INVALID_CONFIG, "the disk cache policy needs a cache directory");
|
|
||||||
}
|
|
||||||
SofaHrir sofa;
|
|
||||||
Status status = load_sofa(request.sofa_path, &sofa);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
CanonicalHrtf canonical;
|
|
||||||
status = canonicalize_sofa(sofa, &canonical);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
// The key depends on the shell that the radius selects, exactly as upstream.
|
|
||||||
double actual_radius = request.options.shell_radius_m;
|
|
||||||
(void)canonical_shell_indices(canonical, request.options.shell_radius_m, &actual_radius);
|
|
||||||
const std::string key = compiled_hrtf_cache_key(
|
|
||||||
canonical.source_sha256, canonical.sample_rate_hz, actual_radius, request.options.order,
|
|
||||||
request.options.projection_ridge, request.options.sh_ridge);
|
|
||||||
if (cache_path != nullptr) {
|
|
||||||
cache_path->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string target;
|
|
||||||
if (request.policy == CachePolicy::Disk) {
|
|
||||||
target = request.cache_dir;
|
|
||||||
if (!target.empty() && target.back() != '/' && target.back() != '\\') {
|
|
||||||
target += "/";
|
|
||||||
}
|
|
||||||
target += cache_file_name(canonical.source_path.empty()
|
|
||||||
? std::string()
|
|
||||||
: canonical.source_path,
|
|
||||||
key);
|
|
||||||
if (fs_utf8::exists(target)) {
|
|
||||||
Field cached_field;
|
|
||||||
const Status cached =
|
|
||||||
validate_jochrtf(target, canonical.source_sha256, key, &cached_field);
|
|
||||||
if (cached.ok()) {
|
|
||||||
memory_cache_put(key, cached_field);
|
|
||||||
*out = std::move(cached_field);
|
|
||||||
if (cache_path != nullptr) {
|
|
||||||
*cache_path = target;
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Field field;
|
|
||||||
if (request.policy != CachePolicy::None && memory_cache_get(key, &field)) {
|
|
||||||
// A memory hit still materialises the disk cache the caller asked for.
|
|
||||||
if (request.policy == CachePolicy::Disk) {
|
|
||||||
status = save_jochrtf_atomic(field, target);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (cache_path != nullptr) {
|
|
||||||
*cache_path = target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*out = std::move(field);
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
status = compile_canonical_field(canonical, request.options, &field);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (field.cache_key != key) {
|
|
||||||
return cache_fail(JOC_ERR_INTERNAL, "internal compiled HRTF cache-key mismatch");
|
|
||||||
}
|
|
||||||
if (request.policy == CachePolicy::Disk) {
|
|
||||||
status = save_jochrtf_atomic(field, target);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (cache_path != nullptr) {
|
|
||||||
*cache_path = target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (request.policy != CachePolicy::None) {
|
|
||||||
memory_cache_put(key, field);
|
|
||||||
}
|
|
||||||
*out = std::move(field);
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace joc::hrtf
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "foundation/status.h"
|
|
||||||
#include "hrtf/jochrtf.h"
|
|
||||||
#include "hrtf/sofa_field.h"
|
|
||||||
|
|
||||||
// Compiled-field cache: the .jochrtf is an internal artifact, so the caller only
|
|
||||||
// names the SOFA file and the policy. "memory" keeps the compiled field in this
|
|
||||||
// process, "disk" additionally reuses (and writes) <cache_dir>/<name>.<key>.jochrtf.
|
|
||||||
namespace joc::hrtf {
|
|
||||||
|
|
||||||
enum class CachePolicy { None, Memory, Disk };
|
|
||||||
|
|
||||||
struct SofaFieldRequest {
|
|
||||||
std::string sofa_path;
|
|
||||||
CompileOptions options;
|
|
||||||
CachePolicy policy = CachePolicy::Memory;
|
|
||||||
std::string cache_dir; // required for the disk policy
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parses "none"/"memory"/"disk"; anything else is rejected.
|
|
||||||
Status parse_cache_policy(const std::string& text, CachePolicy* out);
|
|
||||||
|
|
||||||
// Returns the compiled field, reusing a valid cache when the policy allows it.
|
|
||||||
// `cache_path` (optional) receives the cache file that was read or written.
|
|
||||||
Status load_or_compile_sofa_field(const SofaFieldRequest& request, Field* out,
|
|
||||||
std::string* cache_path);
|
|
||||||
|
|
||||||
// Writes the field to `path` through a temporary file and an atomic rename.
|
|
||||||
Status save_jochrtf_atomic(const Field& field, const std::string& path);
|
|
||||||
|
|
||||||
// Verifies that a cache file belongs to `source_sha256` and `cache_key`.
|
|
||||||
Status validate_jochrtf(const std::string& path, const std::string& source_sha256,
|
|
||||||
const std::string& cache_key, Field* out);
|
|
||||||
|
|
||||||
} // namespace joc::hrtf
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,103 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "foundation/status.h"
|
|
||||||
#include "hrtf/jochrtf.h"
|
|
||||||
#include "hrtf/sofa.h"
|
|
||||||
|
|
||||||
// SOFA SimpleFreeFieldHRIR -> compiled directional field, ported from the
|
|
||||||
// reference chain (sofa_canonical.py + sofa_hrtf_field.py + the public
|
|
||||||
// filterbank): the measurement shell is selected, one delay representation is
|
|
||||||
// separated, the FIRs are projected onto the 64-QMF/77-hybrid filterbank and the
|
|
||||||
// result is fitted with fifth-order ACN/N3D real spherical harmonics.
|
|
||||||
namespace joc::hrtf {
|
|
||||||
|
|
||||||
inline constexpr int kFieldOrder = 5;
|
|
||||||
inline constexpr int kFieldTerms = 36;
|
|
||||||
inline constexpr double kFieldSampleRateHz = 48000.0;
|
|
||||||
inline constexpr double kDefaultShellRadiusM = 1.0;
|
|
||||||
inline constexpr double kDefaultProjectionRidge = 1.0e-3;
|
|
||||||
inline constexpr double kDefaultSphericalHarmonicRidge = 1.0e-5;
|
|
||||||
inline constexpr const char* kCompilerVersion = "joc-sofa-compiler-v1";
|
|
||||||
inline constexpr const char* kPhasePolicyVersion = "sofa-delay-exactly-once-v1";
|
|
||||||
inline constexpr const char* kShConvention = "ACN/N3D real";
|
|
||||||
inline constexpr const char* kFilterbankTableVersion = "joc-public-64qmf-77hybrid-v1";
|
|
||||||
// SHA-256 of the standard filterbank archive the embedded tables came from. It
|
|
||||||
// participates in the cache key, so it is part of the file-format contract.
|
|
||||||
inline constexpr const char* kFilterbankArchiveSha256 =
|
|
||||||
"C05BEF4D26E96ECBD4694E2572F05DA400255C777BA5047300B9D3B1F81081CD";
|
|
||||||
|
|
||||||
struct CompileOptions {
|
|
||||||
double shell_radius_m = kDefaultShellRadiusM;
|
|
||||||
int order = kFieldOrder;
|
|
||||||
double projection_ridge = kDefaultProjectionRidge;
|
|
||||||
double sh_ridge = kDefaultSphericalHarmonicRidge;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Canonical HRIR set: Data.IR and Data.Delay stay separate, the listener frame is
|
|
||||||
// applied to the source positions and the ears are ordered left/right.
|
|
||||||
struct CanonicalHrtf {
|
|
||||||
std::string source_path;
|
|
||||||
std::string source_sha256;
|
|
||||||
std::string convention;
|
|
||||||
std::string convention_version;
|
|
||||||
std::string processing_label;
|
|
||||||
double sample_rate_hz = 0.0;
|
|
||||||
std::uint32_t measurements = 0;
|
|
||||||
std::uint32_t taps = 0;
|
|
||||||
int left_receiver_index = 0;
|
|
||||||
int right_receiver_index = 1;
|
|
||||||
std::vector<double> source_position_cartesian_m; // [M,3] listener-local
|
|
||||||
std::vector<double> unit_directions; // [M,3]
|
|
||||||
std::vector<double> measurement_radius_m; // [M]
|
|
||||||
std::vector<double> hrir; // [M,2,N] canonical L/R
|
|
||||||
std::vector<double> delay_samples; // [M,2], not applied
|
|
||||||
};
|
|
||||||
|
|
||||||
// Port of load_simple_free_field_hrir(): strict SimpleFreeFieldHRIR import.
|
|
||||||
Status canonicalize_sofa(const SofaHrir& sofa, CanonicalHrtf* out);
|
|
||||||
|
|
||||||
// Compiles the canonical set into the runtime field (port of SofaHrtfField.fit).
|
|
||||||
Status compile_sofa_field(const SofaHrir& sofa, const CompileOptions& options, Field* out);
|
|
||||||
|
|
||||||
// The measurements on the shell nearest to radius_m; actual_radius_m receives the
|
|
||||||
// mean radius of that shell (upstream CanonicalHrtf.shell_indices).
|
|
||||||
std::vector<std::size_t> canonical_shell_indices(const CanonicalHrtf& canonical, double radius_m,
|
|
||||||
double* actual_radius_m);
|
|
||||||
|
|
||||||
// Compiles an already canonicalized set (used by tests and the cache layer).
|
|
||||||
Status compile_canonical_field(const CanonicalHrtf& canonical, const CompileOptions& options,
|
|
||||||
Field* out);
|
|
||||||
|
|
||||||
// Configuration hash that names the cache file (upstream compiled_hrtf_cache_key).
|
|
||||||
std::string compiled_hrtf_cache_key(const std::string& source_sha256, double sample_rate_hz,
|
|
||||||
double shell_radius_m, int order, double projection_ridge,
|
|
||||||
double sh_ridge);
|
|
||||||
|
|
||||||
// Payload hash over the four arrays (upstream _payload_sha256).
|
|
||||||
std::string field_payload_sha256(const Field& field);
|
|
||||||
|
|
||||||
// "<stem>.<first 20 key digits>.jochrtf", the upstream cache file name.
|
|
||||||
std::string cache_file_name(const std::string& display_name, const std::string& cache_key);
|
|
||||||
|
|
||||||
// Serializes the field as a .jochrtf cache the upstream loader also accepts.
|
|
||||||
Status write_jochrtf(const Field& field, const std::string& path);
|
|
||||||
|
|
||||||
// The analysis/gain/synthesis dictionary the projection solves against (dev check).
|
|
||||||
std::vector<double> hybrid_gain_synthesis_dictionary_for_check(std::size_t sample_count);
|
|
||||||
|
|
||||||
// Shell directions and their spherical Voronoi weights (dev check).
|
|
||||||
void shell_directions_and_weights_for_check(const SofaHrir& sofa, double radius_m,
|
|
||||||
std::vector<double>* directions,
|
|
||||||
std::vector<double>* weights);
|
|
||||||
|
|
||||||
// PublicAnalysis77 on a unit impulse, interleaved complex (dev check).
|
|
||||||
std::vector<double> analysis_impulse_for_check(std::size_t total_samples);
|
|
||||||
|
|
||||||
// The 77 hybrid-band centre frequencies at 48 kHz.
|
|
||||||
const std::vector<double>& hybrid_band_center_frequencies_hz();
|
|
||||||
|
|
||||||
} // namespace joc::hrtf
|
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "foundation/status.h"
|
#include "foundation/status.h"
|
||||||
#include "hrtf/jochrtf.h"
|
#include "hrtf/jochrtf.h"
|
||||||
#include "hrtf/rosella_model.h"
|
#include "hrtf/rosella_model.h"
|
||||||
#include "hrtf/sofa_cache.h"
|
|
||||||
#include "joc_bitstream/bed_layout_map.h"
|
#include "joc_bitstream/bed_layout_map.h"
|
||||||
#include "joc_bitstream/joc_parser.h"
|
#include "joc_bitstream/joc_parser.h"
|
||||||
#include "joc_core/objects16.h"
|
#include "joc_core/objects16.h"
|
||||||
@@ -143,26 +142,7 @@ Status Stream::create(const Config& config) {
|
|||||||
hrtf::Field field;
|
hrtf::Field field;
|
||||||
hrtf::Kernels kernels;
|
hrtf::Kernels kernels;
|
||||||
Status status = Status::success();
|
Status status = Status::success();
|
||||||
if (!config_.hrtf_sofa_path.empty()) {
|
|
||||||
// The .jochrtf is an internal cache: the SOFA is the user-facing input.
|
|
||||||
hrtf::SofaFieldRequest request;
|
|
||||||
request.sofa_path = config_.hrtf_sofa_path;
|
|
||||||
request.options.shell_radius_m = config_.hrtf_radius_m;
|
|
||||||
request.cache_dir = config_.hrtf_cache_dir;
|
|
||||||
switch (config_.hrtf_cache_policy) {
|
|
||||||
case JOC_HRTF_CACHE_NONE: request.policy = hrtf::CachePolicy::None; break;
|
|
||||||
case JOC_HRTF_CACHE_DISK: request.policy = hrtf::CachePolicy::Disk; break;
|
|
||||||
default: request.policy = hrtf::CachePolicy::Memory; break;
|
|
||||||
}
|
|
||||||
std::string cache_path;
|
|
||||||
status = hrtf::load_or_compile_sofa_field(request, &field, &cache_path);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return Status::fail(status.code(), stage::kRender,
|
|
||||||
"binaural setup failed: " + status.message());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status = hrtf::load_jochrtf(config_.hrtf_path, &field);
|
status = hrtf::load_jochrtf(config_.hrtf_path, &field);
|
||||||
}
|
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
status = config_.kernels_path.empty()
|
status = config_.kernels_path.empty()
|
||||||
? (kernels = hrtf::builtin_kernels(), Status::success())
|
? (kernels = hrtf::builtin_kernels(), Status::success())
|
||||||
@@ -175,7 +155,10 @@ Status Stream::create(const Config& config) {
|
|||||||
profile = binaural::Profile::Far;
|
profile = binaural::Profile::Far;
|
||||||
}
|
}
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
status = binaural_.open(field, kernels, profile);
|
binaural::RoomConstants room;
|
||||||
|
room.enable_early_reflections = config_.jochrtf_room ? 1u : 0u;
|
||||||
|
room.enable_late_room = room.enable_early_reflections;
|
||||||
|
status = binaural_.open(field, kernels, profile, room);
|
||||||
}
|
}
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "binaural/binaural_runtime.h"
|
#include "binaural/jochrtf_runtime.h"
|
||||||
#include "eac3_transport/eac3_reader.h"
|
#include "eac3_transport/eac3_reader.h"
|
||||||
#include "foundation/status.h"
|
#include "foundation/status.h"
|
||||||
#include "hrtf/rosella_renderer.h"
|
#include "hrtf/rosella_renderer.h"
|
||||||
@@ -30,13 +30,10 @@ struct Config {
|
|||||||
std::uint32_t object_delay_samples = 1473;
|
std::uint32_t object_delay_samples = 1473;
|
||||||
double gain_db = 0.0;
|
double gain_db = 0.0;
|
||||||
std::uint32_t native_threads = 0;
|
std::uint32_t native_threads = 0;
|
||||||
// The three HRTF shapes of joc_task_config, in its precedence order: a Rosella
|
// Binaural inputs of joc_task_config: a Rosella model wins over hrtf_path
|
||||||
// model wins over a SOFA, and hrtf_path (.jochrtf) is the fallback.
|
// (.jochrtf).
|
||||||
std::string hrtf_sofa_path;
|
|
||||||
std::string personalized_headphone_path;
|
std::string personalized_headphone_path;
|
||||||
std::string hrtf_cache_dir;
|
std::uint32_t jochrtf_room = 1;
|
||||||
std::uint32_t hrtf_cache_policy = JOC_HRTF_CACHE_MEMORY;
|
|
||||||
double hrtf_radius_m = 1.0;
|
|
||||||
// Filterbank of the Rosella path; the other binaural inputs ignore it.
|
// Filterbank of the Rosella path; the other binaural inputs ignore it.
|
||||||
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
||||||
};
|
};
|
||||||
@@ -170,7 +167,7 @@ private:
|
|||||||
|
|
||||||
ejoc_renderer_handle rebuilder_ = nullptr;
|
ejoc_renderer_handle rebuilder_ = nullptr;
|
||||||
speaker::SpeakerStep speaker_;
|
speaker::SpeakerStep speaker_;
|
||||||
binaural::SofaBinauralRuntime binaural_;
|
binaural::JochrtfRuntime binaural_;
|
||||||
hrtf::RosellaRuntime rosella_;
|
hrtf::RosellaRuntime rosella_;
|
||||||
std::vector<double> rosella_pending_;
|
std::vector<double> rosella_pending_;
|
||||||
std::size_t rosella_read_offset_ = 0;
|
std::size_t rosella_read_offset_ = 0;
|
||||||
|
|||||||
+11
-54
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include "adm/adm_metadata.h"
|
#include "adm/adm_metadata.h"
|
||||||
#include "adm/adm_tracks.h"
|
#include "adm/adm_tracks.h"
|
||||||
#include "binaural/binaural_runtime.h"
|
#include "binaural/jochrtf_runtime.h"
|
||||||
#include "eac3_transport/eac3_reader.h"
|
#include "eac3_transport/eac3_reader.h"
|
||||||
#include "emdf/emdf_parser.h"
|
#include "emdf/emdf_parser.h"
|
||||||
#include "foundation/mini_json.h"
|
#include "foundation/mini_json.h"
|
||||||
@@ -37,7 +37,6 @@
|
|||||||
#include "hrtf/rosella_bank.h"
|
#include "hrtf/rosella_bank.h"
|
||||||
#include "hrtf/rosella_model.h"
|
#include "hrtf/rosella_model.h"
|
||||||
#include "hrtf/rosella_renderer.h"
|
#include "hrtf/rosella_renderer.h"
|
||||||
#include "hrtf/sofa_cache.h"
|
|
||||||
#include "io/adm_writer.h"
|
#include "io/adm_writer.h"
|
||||||
#include "io/process.h"
|
#include "io/process.h"
|
||||||
#include "io/wav_writer.h"
|
#include "io/wav_writer.h"
|
||||||
@@ -94,11 +93,8 @@ struct Settings {
|
|||||||
std::string layout;
|
std::string layout;
|
||||||
std::string hrtf_path;
|
std::string hrtf_path;
|
||||||
std::string kernels_path;
|
std::string kernels_path;
|
||||||
std::string hrtf_sofa_path;
|
|
||||||
std::string personalized_headphone_path;
|
std::string personalized_headphone_path;
|
||||||
std::string hrtf_cache_dir;
|
std::uint32_t jochrtf_room = 1;
|
||||||
std::uint32_t hrtf_cache_policy = JOC_HRTF_CACHE_MEMORY;
|
|
||||||
double hrtf_radius_m = 1.0;
|
|
||||||
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
||||||
std::uint32_t operation = JOC_OP_ADM_BWF;
|
std::uint32_t operation = JOC_OP_ADM_BWF;
|
||||||
std::uint32_t output_format = JOC_FORMAT_FLOAT32;
|
std::uint32_t output_format = JOC_FORMAT_FLOAT32;
|
||||||
@@ -144,13 +140,10 @@ Settings normalise(const joc_task_config& raw) {
|
|||||||
if (raw.output_path != nullptr) { cfg.output_path = raw.output_path; }
|
if (raw.output_path != nullptr) { cfg.output_path = raw.output_path; }
|
||||||
if (raw.speaker_layout_name != nullptr) { cfg.layout = raw.speaker_layout_name; }
|
if (raw.speaker_layout_name != nullptr) { cfg.layout = raw.speaker_layout_name; }
|
||||||
if (raw.hrtf_path != nullptr) { cfg.hrtf_path = raw.hrtf_path; }
|
if (raw.hrtf_path != nullptr) { cfg.hrtf_path = raw.hrtf_path; }
|
||||||
if (raw.hrtf_sofa_path != nullptr) { cfg.hrtf_sofa_path = raw.hrtf_sofa_path; }
|
|
||||||
if (raw.personalized_headphone_path != nullptr) {
|
if (raw.personalized_headphone_path != nullptr) {
|
||||||
cfg.personalized_headphone_path = raw.personalized_headphone_path;
|
cfg.personalized_headphone_path = raw.personalized_headphone_path;
|
||||||
}
|
}
|
||||||
if (raw.hrtf_cache_dir != nullptr) { cfg.hrtf_cache_dir = raw.hrtf_cache_dir; }
|
cfg.jochrtf_room = raw.jochrtf_room;
|
||||||
cfg.hrtf_cache_policy = raw.hrtf_cache_policy;
|
|
||||||
cfg.hrtf_radius_m = raw.hrtf_radius_m;
|
|
||||||
// Kept verbatim so validate() can reject an out-of-range value; 0 is the
|
// Kept verbatim so validate() can reject an out-of-range value; 0 is the
|
||||||
// documented "unset" spelling of the public bank.
|
// documented "unset" spelling of the public bank.
|
||||||
cfg.rosella_filterbank = raw.rosella_filterbank;
|
cfg.rosella_filterbank = raw.rosella_filterbank;
|
||||||
@@ -1074,36 +1067,17 @@ Status validate(const joc_task_config& raw, std::vector<joc_validation_issue>* i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cfg.operation == JOC_OP_BINAURAL) {
|
if (cfg.operation == JOC_OP_BINAURAL) {
|
||||||
if (cfg.hrtf_path.empty() && cfg.hrtf_sofa_path.empty() &&
|
if (cfg.hrtf_path.empty() && cfg.personalized_headphone_path.empty()) {
|
||||||
cfg.personalized_headphone_path.empty()) {
|
|
||||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_path",
|
fail(JOC_ERR_INVALID_CONFIG, "hrtf_path",
|
||||||
"a SOFA input, a Rosella model or a compiled HRTF (.jochrtf) is required for the "
|
"a Rosella model or a compiled HRTF (.jochrtf) is required for the "
|
||||||
"binaural operation");
|
"binaural operation");
|
||||||
} else if (!cfg.personalized_headphone_path.empty() &&
|
} else if (!cfg.personalized_headphone_path.empty() &&
|
||||||
!fs_utf8::exists(cfg.personalized_headphone_path)) {
|
!fs_utf8::exists(cfg.personalized_headphone_path)) {
|
||||||
fail(JOC_ERR_HRTF_NOT_FOUND, "personalized_headphone_path",
|
fail(JOC_ERR_HRTF_NOT_FOUND, "personalized_headphone_path",
|
||||||
"personalized headphone model not found: " + cfg.personalized_headphone_path);
|
"personalized headphone model not found: " + cfg.personalized_headphone_path);
|
||||||
} else if (!cfg.hrtf_sofa_path.empty() && !fs_utf8::exists(cfg.hrtf_sofa_path)) {
|
} else if (cfg.personalized_headphone_path.empty() && !fs_utf8::exists(cfg.hrtf_path)) {
|
||||||
fail(JOC_ERR_HRTF_NOT_FOUND, "hrtf_sofa_path",
|
|
||||||
"SOFA HRTF not found: " + cfg.hrtf_sofa_path);
|
|
||||||
} else if (cfg.hrtf_sofa_path.empty() && cfg.personalized_headphone_path.empty() &&
|
|
||||||
!fs_utf8::exists(cfg.hrtf_path)) {
|
|
||||||
fail(JOC_ERR_HRTF_NOT_FOUND, "hrtf_path", "HRTF cache not found: " + cfg.hrtf_path);
|
fail(JOC_ERR_HRTF_NOT_FOUND, "hrtf_path", "HRTF cache not found: " + cfg.hrtf_path);
|
||||||
}
|
}
|
||||||
if (!cfg.hrtf_sofa_path.empty()) {
|
|
||||||
if (cfg.hrtf_cache_policy > JOC_HRTF_CACHE_DISK) {
|
|
||||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_cache_policy",
|
|
||||||
"hrtf_cache_policy must be none, memory or disk");
|
|
||||||
}
|
|
||||||
if (cfg.hrtf_cache_policy == JOC_HRTF_CACHE_DISK && cfg.hrtf_cache_dir.empty()) {
|
|
||||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_cache_dir",
|
|
||||||
"the disk cache policy needs a cache directory");
|
|
||||||
}
|
|
||||||
if (!std::isfinite(cfg.hrtf_radius_m) || cfg.hrtf_radius_m <= 0.0) {
|
|
||||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_radius_m",
|
|
||||||
"hrtf_radius_m must be positive and finite");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The filterbank tables are compiled in; a path is only a verification override.
|
// The filterbank tables are compiled in; a path is only a verification override.
|
||||||
if (!cfg.kernels_path.empty() && !fs_utf8::exists(cfg.kernels_path)) {
|
if (!cfg.kernels_path.empty() && !fs_utf8::exists(cfg.kernels_path)) {
|
||||||
fail(JOC_ERR_HRTF_NOT_FOUND, "kernels_path",
|
fail(JOC_ERR_HRTF_NOT_FOUND, "kernels_path",
|
||||||
@@ -1354,7 +1328,7 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
speaker.layout.channel_count));
|
speaker.layout.channel_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
::joc::binaural::SofaBinauralRuntime binaural;
|
::joc::binaural::JochrtfRuntime binaural;
|
||||||
::joc::hrtf::RosellaRuntime rosella;
|
::joc::hrtf::RosellaRuntime rosella;
|
||||||
const bool binaural_enabled = cfg.operation == JOC_OP_BINAURAL;
|
const bool binaural_enabled = cfg.operation == JOC_OP_BINAURAL;
|
||||||
const bool rosella_enabled = !cfg.personalized_headphone_path.empty();
|
const bool rosella_enabled = !cfg.personalized_headphone_path.empty();
|
||||||
@@ -1398,31 +1372,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
::joc::hrtf::Kernels kernels;
|
::joc::hrtf::Kernels kernels;
|
||||||
::joc::binaural::Profile profile = ::joc::binaural::Profile::Mid;
|
::joc::binaural::Profile profile = ::joc::binaural::Profile::Mid;
|
||||||
Status status = Status::success();
|
Status status = Status::success();
|
||||||
if (!cfg.hrtf_sofa_path.empty()) {
|
|
||||||
// The .jochrtf is an internal cache: the SOFA is the user-facing input.
|
|
||||||
::joc::hrtf::SofaFieldRequest request;
|
|
||||||
request.sofa_path = cfg.hrtf_sofa_path;
|
|
||||||
request.options.shell_radius_m = cfg.hrtf_radius_m;
|
|
||||||
request.cache_dir = cfg.hrtf_cache_dir;
|
|
||||||
switch (cfg.hrtf_cache_policy) {
|
|
||||||
case JOC_HRTF_CACHE_NONE: request.policy = ::joc::hrtf::CachePolicy::None; break;
|
|
||||||
case JOC_HRTF_CACHE_DISK: request.policy = ::joc::hrtf::CachePolicy::Disk; break;
|
|
||||||
default: request.policy = ::joc::hrtf::CachePolicy::Memory; break;
|
|
||||||
}
|
|
||||||
std::string cache_path;
|
|
||||||
status = ::joc::hrtf::load_or_compile_sofa_field(request, &field, &cache_path);
|
|
||||||
if (status.ok()) {
|
|
||||||
bus.emit(JOC_EV_HRTF_LOADED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
|
||||||
"SOFA HRTF compiled: " + field.source_sha256.substr(0, 16) +
|
|
||||||
(cache_path.empty() ? std::string() : " -> " + cache_path));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status = ::joc::hrtf::load_jochrtf(cfg.hrtf_path, &field);
|
status = ::joc::hrtf::load_jochrtf(cfg.hrtf_path, &field);
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
bus.emit(JOC_EV_HRTF_LOADED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
bus.emit(JOC_EV_HRTF_LOADED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
||||||
"compiled HRTF: " + field.source_sha256.substr(0, 16));
|
"compiled HRTF: " + field.source_sha256.substr(0, 16));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
status = cfg.kernels_path.empty()
|
status = cfg.kernels_path.empty()
|
||||||
? (kernels = ::joc::hrtf::builtin_kernels(), Status::success())
|
? (kernels = ::joc::hrtf::builtin_kernels(), Status::success())
|
||||||
@@ -1434,7 +1388,10 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
profile = ::joc::binaural::Profile::Far;
|
profile = ::joc::binaural::Profile::Far;
|
||||||
}
|
}
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
status = binaural.open(field, kernels, profile);
|
::joc::binaural::RoomConstants room;
|
||||||
|
room.enable_early_reflections = cfg.jochrtf_room ? 1u : 0u;
|
||||||
|
room.enable_late_room = room.enable_early_reflections;
|
||||||
|
status = binaural.open(field, kernels, profile, room);
|
||||||
}
|
}
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return finalize_with_error(status.code(), "render",
|
return finalize_with_error(status.code(), "render",
|
||||||
|
|||||||
+1
-11
@@ -455,9 +455,7 @@ std::string resolve_hrtf_file(const Settings& settings) {
|
|||||||
if (directory.empty()) return {};
|
if (directory.empty()) return {};
|
||||||
// Same convention as the reference CLI next to its executable:
|
// Same convention as the reference CLI next to its executable:
|
||||||
// <base>\HRTF\binaural.sofa or <base>\HRTF\binaural.personalized_headphone.
|
// <base>\HRTF\binaural.sofa or <base>\HRTF\binaural.personalized_headphone.
|
||||||
const char* name = (settings.hrtf_source == HrtfSource::kRosella)
|
const char* name = "binaural.personalized_headphone";
|
||||||
? "binaural.personalized_headphone"
|
|
||||||
: "binaural.sofa";
|
|
||||||
return directory + "\\HRTF\\" + name;
|
return directory + "\\HRTF\\" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,16 +1010,8 @@ bool Engine::start(const std::string& input_path, const Settings& settings, std:
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (settings.hrtf_source == HrtfSource::kRosella) {
|
|
||||||
config.personalized_headphone_path = hrtf_file.c_str();
|
config.personalized_headphone_path = hrtf_file.c_str();
|
||||||
} else {
|
|
||||||
config.hrtf_sofa_path = hrtf_file.c_str();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
config.hrtf_cache_policy = settings.hrtf_cache_policy;
|
|
||||||
config.hrtf_cache_dir =
|
|
||||||
settings.hrtf_cache_dir.empty() ? nullptr : settings.hrtf_cache_dir.c_str();
|
|
||||||
config.hrtf_radius_m = settings.hrtf_radius_m;
|
|
||||||
config.binaural_tail_seconds = settings.tail_seconds;
|
config.binaural_tail_seconds = settings.tail_seconds;
|
||||||
config.object_delay_samples = settings.object_delay_samples;
|
config.object_delay_samples = settings.object_delay_samples;
|
||||||
config.gain_db = settings.gain_db;
|
config.gain_db = settings.gain_db;
|
||||||
|
|||||||
@@ -44,13 +44,6 @@ enum class Output {
|
|||||||
kSpeaker = 1, // N channels, named layout
|
kSpeaker = 1, // N channels, named layout
|
||||||
};
|
};
|
||||||
|
|
||||||
// Which HRTF to render with. Both inputs are user-facing model/data files; how
|
|
||||||
// the renderer gets from them to its internal filter field is its own business.
|
|
||||||
enum class HrtfSource {
|
|
||||||
kSofa = 0,
|
|
||||||
kRosella = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Where the E-AC-3 syncframes come from. A bare stream is read straight from the
|
// Where the E-AC-3 syncframes come from. A bare stream is read straight from the
|
||||||
// file; inside a container the track has to be extracted first (ffmpeg, stream copy).
|
// file; inside a container the track has to be extracted first (ffmpeg, stream copy).
|
||||||
enum class InputKind {
|
enum class InputKind {
|
||||||
@@ -64,12 +57,8 @@ struct Settings {
|
|||||||
// Which of the container's audio tracks holds the E-AC-3 stream, 0-based.
|
// Which of the container's audio tracks holds the E-AC-3 stream, 0-based.
|
||||||
unsigned audio_index = 0;
|
unsigned audio_index = 0;
|
||||||
std::string speaker_layout = "7.1";
|
std::string speaker_layout = "7.1";
|
||||||
HrtfSource hrtf_source = HrtfSource::kSofa;
|
|
||||||
// Empty means the default file in the default folder, see resolve_hrtf_file().
|
// Empty means the default file in the default folder, see resolve_hrtf_file().
|
||||||
std::string hrtf_file;
|
std::string hrtf_file;
|
||||||
std::string hrtf_cache_dir; // SOFA compile cache (disk policy)
|
|
||||||
unsigned hrtf_cache_policy = 1; // 0 none, 1 memory, 2 disk
|
|
||||||
double hrtf_radius_m = 1.0; // SOFA measurement-radius shell
|
|
||||||
std::uint32_t binaural_mode = 3; // JOC_BINAURAL_MID
|
std::uint32_t binaural_mode = 3; // JOC_BINAURAL_MID
|
||||||
double gain_db = 0.0;
|
double gain_db = 0.0;
|
||||||
double tail_seconds = 5.0;
|
double tail_seconds = 5.0;
|
||||||
|
|||||||
+1
-13
@@ -404,10 +404,6 @@ private:
|
|||||||
void load_values(const joc_settings::Values& values) {
|
void load_values(const joc_settings::Values& values) {
|
||||||
CheckRadioButton(m_hwnd, IDC_RADIO_BINAURAL, IDC_RADIO_SPEAKER,
|
CheckRadioButton(m_hwnd, IDC_RADIO_BINAURAL, IDC_RADIO_SPEAKER,
|
||||||
values.output == 0 ? IDC_RADIO_BINAURAL : IDC_RADIO_SPEAKER);
|
values.output == 0 ? IDC_RADIO_BINAURAL : IDC_RADIO_SPEAKER);
|
||||||
CheckRadioButton(m_hwnd, IDC_RADIO_HRTF_SOFA, IDC_RADIO_HRTF_ROSELLA,
|
|
||||||
values.hrtf_source == joc_settings::HrtfSource::kRosella
|
|
||||||
? IDC_RADIO_HRTF_ROSELLA
|
|
||||||
: IDC_RADIO_HRTF_SOFA);
|
|
||||||
|
|
||||||
set_text(GetDlgItem(m_hwnd, IDC_EDIT_HRTF), values.hrtf_file);
|
set_text(GetDlgItem(m_hwnd, IDC_EDIT_HRTF), values.hrtf_file);
|
||||||
set_text(GetDlgItem(m_hwnd, IDC_EDIT_FFMPEG), values.ffmpeg_path);
|
set_text(GetDlgItem(m_hwnd, IDC_EDIT_FFMPEG), values.ffmpeg_path);
|
||||||
@@ -464,9 +460,6 @@ private:
|
|||||||
static_cast<int>(SendDlgItemMessageW(m_hwnd, IDC_COMBO_MODE, CB_GETCURSEL, 0, 0));
|
static_cast<int>(SendDlgItemMessageW(m_hwnd, IDC_COMBO_MODE, CB_GETCURSEL, 0, 0));
|
||||||
values.binaural_mode = mode_value(mode_sel < 0 ? 1u : static_cast<unsigned>(mode_sel));
|
values.binaural_mode = mode_value(mode_sel < 0 ? 1u : static_cast<unsigned>(mode_sel));
|
||||||
|
|
||||||
values.hrtf_source = IsDlgButtonChecked(m_hwnd, IDC_RADIO_HRTF_ROSELLA) == BST_CHECKED
|
|
||||||
? joc_settings::HrtfSource::kRosella
|
|
||||||
: joc_settings::HrtfSource::kSofa;
|
|
||||||
values.hrtf_file = get_text(GetDlgItem(m_hwnd, IDC_EDIT_HRTF));
|
values.hrtf_file = get_text(GetDlgItem(m_hwnd, IDC_EDIT_HRTF));
|
||||||
values.ffmpeg_path = get_text(GetDlgItem(m_hwnd, IDC_EDIT_FFMPEG));
|
values.ffmpeg_path = get_text(GetDlgItem(m_hwnd, IDC_EDIT_FFMPEG));
|
||||||
values.tail_seconds =
|
values.tail_seconds =
|
||||||
@@ -503,13 +496,9 @@ private:
|
|||||||
set_text(GetDlgItem(m_hwnd, IDC_LABEL_OUTPUT_STATUS), output_status);
|
set_text(GetDlgItem(m_hwnd, IDC_LABEL_OUTPUT_STATUS), output_status);
|
||||||
|
|
||||||
joc_decode::Settings effective = joc_settings::current();
|
joc_decode::Settings effective = joc_settings::current();
|
||||||
effective.hrtf_source = static_cast<joc_decode::HrtfSource>(values.hrtf_source);
|
|
||||||
effective.hrtf_file = values.hrtf_file;
|
effective.hrtf_file = values.hrtf_file;
|
||||||
const std::string file = joc_decode::resolve_hrtf_file(effective);
|
const std::string file = joc_decode::resolve_hrtf_file(effective);
|
||||||
const joc_lang::Text source = values.hrtf_source == joc_settings::HrtfSource::kRosella
|
std::string hrtf_status = joc_lang::get(language, joc_lang::Text::kHrtfSourceRosella);
|
||||||
? joc_lang::Text::kHrtfSourceRosella
|
|
||||||
: joc_lang::Text::kHrtfSourceSofa;
|
|
||||||
std::string hrtf_status = joc_lang::get(language, source);
|
|
||||||
hrtf_status += joc_lang::get(language, joc_lang::Text::kSeparator);
|
hrtf_status += joc_lang::get(language, joc_lang::Text::kSeparator);
|
||||||
if (values.hrtf_file.empty()) {
|
if (values.hrtf_file.empty()) {
|
||||||
hrtf_status += joc_lang::get(language, joc_lang::Text::kHrtfDefault);
|
hrtf_status += joc_lang::get(language, joc_lang::Text::kHrtfDefault);
|
||||||
@@ -538,7 +527,6 @@ private:
|
|||||||
const joc_settings::Values now = read_controls();
|
const joc_settings::Values now = read_controls();
|
||||||
if (now.output != m_initial.output) return true;
|
if (now.output != m_initial.output) return true;
|
||||||
if (now.speaker_layout != m_initial.speaker_layout) return true;
|
if (now.speaker_layout != m_initial.speaker_layout) return true;
|
||||||
if (now.hrtf_source != m_initial.hrtf_source) return true;
|
|
||||||
if (now.hrtf_file != m_initial.hrtf_file) return true;
|
if (now.hrtf_file != m_initial.hrtf_file) return true;
|
||||||
if (now.binaural_mode != m_initial.binaural_mode) return true;
|
if (now.binaural_mode != m_initial.binaural_mode) return true;
|
||||||
if (now.gain_enabled != m_initial.gain_enabled) return true;
|
if (now.gain_enabled != m_initial.gain_enabled) return true;
|
||||||
|
|||||||
+2
-5
@@ -39,14 +39,11 @@ BEGIN
|
|||||||
LTEXT "切换后需刷新文件信息", IDC_LABEL_INT24_HINT, 176, 65, 136, 10
|
LTEXT "切换后需刷新文件信息", IDC_LABEL_INT24_HINT, 176, 65, 136, 10
|
||||||
|
|
||||||
GROUPBOX "HRTF", IDC_GROUP_HRTF, 7, 79, 316, 92
|
GROUPBOX "HRTF", IDC_GROUP_HRTF, 7, 79, 316, 92
|
||||||
CONTROL "SOFA 文件", IDC_RADIO_HRTF_SOFA, "Button",
|
LTEXT "Rosella 个性化模型", IDC_RADIO_HRTF_ROSELLA, 16, 91, 146, 10
|
||||||
BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 16, 91, 50, 10
|
|
||||||
CONTROL "Rosella 个性化模型", IDC_RADIO_HRTF_ROSELLA, "Button",
|
|
||||||
BS_AUTORADIOBUTTON | WS_TABSTOP, 70, 91, 146, 10
|
|
||||||
LTEXT "HRTF 文件", IDC_LABEL_HRTF, 16, 106, 40, 10
|
LTEXT "HRTF 文件", IDC_LABEL_HRTF, 16, 106, 40, 10
|
||||||
EDITTEXT IDC_EDIT_HRTF, 58, 103, 186, 13, ES_AUTOHSCROLL
|
EDITTEXT IDC_EDIT_HRTF, 58, 103, 186, 13, ES_AUTOHSCROLL
|
||||||
PUSHBUTTON "浏览…", IDC_BROWSE_HRTF, 248, 103, 52, 13
|
PUSHBUTTON "浏览…", IDC_BROWSE_HRTF, 248, 103, 52, 13
|
||||||
LTEXT "留空时读组件目录下 HRTF\\binaural.sofa 或 HRTF\\binaural.personalized_headphone。",
|
LTEXT "留空时读组件目录下 HRTF\\binaural.personalized_headphone。",
|
||||||
IDC_LABEL_HRTF_HINT, 16, 121, 300, 20
|
IDC_LABEL_HRTF_HINT, 16, 121, 300, 20
|
||||||
LTEXT "", IDC_LABEL_STATUS, 16, 143, 300, 20
|
LTEXT "", IDC_LABEL_STATUS, 16, 143, 300, 20
|
||||||
|
|
||||||
|
|||||||
+4
-26
@@ -24,7 +24,6 @@ constexpr GUID kGuidLayout = {0x7b62e5d1, 0x14a8, 0x4c07, {0x83, 0x2f, 0x6b, 0x9
|
|||||||
// Reused from the previous build, where it stored the .jochrtf path: it still
|
// Reused from the previous build, where it stored the .jochrtf path: it still
|
||||||
// holds "the HRTF file", so the meaning is unchanged for anyone upgrading.
|
// holds "the HRTF file", so the meaning is unchanged for anyone upgrading.
|
||||||
constexpr GUID kGuidHrtfFile = {0x4e8a1f36, 0x2c95, 0x47d0, {0xb1, 0x68, 0x3e, 0xa2, 0x77, 0x09, 0xf5, 0x8c}};
|
constexpr GUID kGuidHrtfFile = {0x4e8a1f36, 0x2c95, 0x47d0, {0xb1, 0x68, 0x3e, 0xa2, 0x77, 0x09, 0xf5, 0x8c}};
|
||||||
constexpr GUID kGuidHrtfSource = {0xa3d51b72, 0x6f48, 0x4c19, {0x9e, 0x04, 0x2b, 0x87, 0xd1, 0x53, 0x6a, 0x20}};
|
|
||||||
constexpr GUID kGuidBinauralMode = {0x1a57c9e4, 0x83b6, 0x42f1, {0x9c, 0x50, 0x24, 0xfd, 0x6a, 0x18, 0x73, 0x0e}};
|
constexpr GUID kGuidBinauralMode = {0x1a57c9e4, 0x83b6, 0x42f1, {0x9c, 0x50, 0x24, 0xfd, 0x6a, 0x18, 0x73, 0x0e}};
|
||||||
constexpr GUID kGuidGainEnabled = {0x74b1e5c8, 0x2a39, 0x4d16, {0x8f, 0x62, 0x0d, 0x51, 0xb7, 0x3c, 0x9a, 0x28}};
|
constexpr GUID kGuidGainEnabled = {0x74b1e5c8, 0x2a39, 0x4d16, {0x8f, 0x62, 0x0d, 0x51, 0xb7, 0x3c, 0x9a, 0x28}};
|
||||||
constexpr GUID kGuidGain = {0x6c04d8b2, 0xe75f, 0x4a39, {0x8d, 0x26, 0x51, 0xb3, 0xc8, 0x40, 0x9e, 0x27}};
|
constexpr GUID kGuidGain = {0x6c04d8b2, 0xe75f, 0x4a39, {0x8d, 0x26, 0x51, 0xb3, 0xc8, 0x40, 0x9e, 0x27}};
|
||||||
@@ -37,7 +36,6 @@ constexpr GUID kGuidLanguage = {0x58e17a04, 0x3d92, 0x4f6b, {0xa1, 0x27, 0x94, 0
|
|||||||
cfg_uint g_output(kGuidOutput, 0);
|
cfg_uint g_output(kGuidOutput, 0);
|
||||||
cfg_string g_layout(kGuidLayout, "7.1");
|
cfg_string g_layout(kGuidLayout, "7.1");
|
||||||
// 0 = SOFA, 1 = Rosella model, 2 = compiled .jochrtf (advanced)
|
// 0 = SOFA, 1 = Rosella model, 2 = compiled .jochrtf (advanced)
|
||||||
cfg_uint g_hrtf_source(kGuidHrtfSource, 0);
|
|
||||||
cfg_string g_hrtf_file(kGuidHrtfFile, "");
|
cfg_string g_hrtf_file(kGuidHrtfFile, "");
|
||||||
cfg_uint g_binaural_mode(kGuidBinauralMode, 3);
|
cfg_uint g_binaural_mode(kGuidBinauralMode, 3);
|
||||||
cfg_bool g_gain_enabled(kGuidGainEnabled, true);
|
cfg_bool g_gain_enabled(kGuidGainEnabled, true);
|
||||||
@@ -99,18 +97,7 @@ bool env_string(const char* name, std::string* out) {
|
|||||||
|
|
||||||
namespace joc_settings {
|
namespace joc_settings {
|
||||||
|
|
||||||
const char* hrtf_source_name(HrtfSource source) {
|
const char* hrtf_default_file_name() { return "binaural.personalized_headphone"; }
|
||||||
return source == HrtfSource::kRosella ? "Rosella 个性化模型" : "SOFA";
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* hrtf_source_extension(HrtfSource source) {
|
|
||||||
return source == HrtfSource::kRosella ? "personalized_headphone" : "sofa";
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* hrtf_default_file_name(HrtfSource source) {
|
|
||||||
return source == HrtfSource::kRosella ? "binaural.personalized_headphone"
|
|
||||||
: "binaural.sofa";
|
|
||||||
}
|
|
||||||
|
|
||||||
Values defaults() { return Values(); }
|
Values defaults() { return Values(); }
|
||||||
|
|
||||||
@@ -131,8 +118,6 @@ Values read() {
|
|||||||
}
|
}
|
||||||
values.speaker_layout = "7.1";
|
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();
|
values.hrtf_file = g_hrtf_file.get_ptr();
|
||||||
values.binaural_mode = static_cast<unsigned>(g_binaural_mode);
|
values.binaural_mode = static_cast<unsigned>(g_binaural_mode);
|
||||||
values.gain_enabled = static_cast<bool>(g_gain_enabled);
|
values.gain_enabled = static_cast<bool>(g_gain_enabled);
|
||||||
@@ -162,7 +147,6 @@ Values read() {
|
|||||||
void write(const Values& values) {
|
void write(const Values& values) {
|
||||||
g_output = static_cast<unsigned>(values.output);
|
g_output = static_cast<unsigned>(values.output);
|
||||||
g_layout = values.speaker_layout.c_str();
|
g_layout = values.speaker_layout.c_str();
|
||||||
g_hrtf_source = static_cast<unsigned>(values.hrtf_source);
|
|
||||||
g_hrtf_file = values.hrtf_file.c_str();
|
g_hrtf_file = values.hrtf_file.c_str();
|
||||||
g_binaural_mode = values.binaural_mode;
|
g_binaural_mode = values.binaural_mode;
|
||||||
g_gain_enabled = values.gain_enabled;
|
g_gain_enabled = values.gain_enabled;
|
||||||
@@ -182,9 +166,6 @@ joc_decode::Settings current() {
|
|||||||
if (env_string("JOC_OUTPUT", &text)) values.output = (text == "speaker") ? 1 : 0;
|
if (env_string("JOC_OUTPUT", &text)) values.output = (text == "speaker") ? 1 : 0;
|
||||||
if (env_string("JOC_LAYOUT", &text)) values.speaker_layout = text;
|
if (env_string("JOC_LAYOUT", &text)) values.speaker_layout = text;
|
||||||
(void)env_string("JOC_HRTF", &values.hrtf_file);
|
(void)env_string("JOC_HRTF", &values.hrtf_file);
|
||||||
if (env_string("JOC_HRTF_SOURCE", &text)) {
|
|
||||||
values.hrtf_source = (text == "rosella") ? HrtfSource::kRosella : HrtfSource::kSofa;
|
|
||||||
}
|
|
||||||
(void)env_string("JOC_FFMPEG", &values.ffmpeg_path);
|
(void)env_string("JOC_FFMPEG", &values.ffmpeg_path);
|
||||||
if (env_string("JOC_BINAURAL_MODE", &text)) {
|
if (env_string("JOC_BINAURAL_MODE", &text)) {
|
||||||
values.binaural_mode = (text == "near") ? 1u : (text == "far") ? 2u : 3u;
|
values.binaural_mode = (text == "near") ? 1u : (text == "far") ? 2u : 3u;
|
||||||
@@ -200,7 +181,6 @@ joc_decode::Settings current() {
|
|||||||
settings.output =
|
settings.output =
|
||||||
(values.output == 0) ? joc_decode::Output::kBinaural : joc_decode::Output::kSpeaker;
|
(values.output == 0) ? joc_decode::Output::kBinaural : joc_decode::Output::kSpeaker;
|
||||||
settings.speaker_layout = values.speaker_layout;
|
settings.speaker_layout = values.speaker_layout;
|
||||||
settings.hrtf_source = static_cast<joc_decode::HrtfSource>(values.hrtf_source);
|
|
||||||
settings.hrtf_file = values.hrtf_file;
|
settings.hrtf_file = values.hrtf_file;
|
||||||
settings.binaural_mode = values.binaural_mode;
|
settings.binaural_mode = values.binaural_mode;
|
||||||
// The switch is explicit rather than implied by the value: binaural rendering
|
// The switch is explicit rather than implied by the value: binaural rendering
|
||||||
@@ -219,9 +199,8 @@ std::string describe(const joc_decode::Settings& settings) {
|
|||||||
char text[640] = {};
|
char text[640] = {};
|
||||||
if (settings.output == joc_decode::Output::kBinaural) {
|
if (settings.output == joc_decode::Output::kBinaural) {
|
||||||
std::snprintf(text, sizeof(text),
|
std::snprintf(text, sizeof(text),
|
||||||
"binaural, hrtf=%s(%s), mode=%u, gain=%.2f dB, tail=%.2f s, delay=%u, "
|
"binaural, hrtf=%s, mode=%u, gain=%.2f dB, tail=%.2f s, delay=%u, "
|
||||||
"threads=%u, ffmpeg=%s",
|
"threads=%u, ffmpeg=%s",
|
||||||
hrtf_source_name(static_cast<HrtfSource>(settings.hrtf_source)),
|
|
||||||
settings.hrtf_file.empty() ? "(默认位置)" : settings.hrtf_file.c_str(),
|
settings.hrtf_file.empty() ? "(默认位置)" : settings.hrtf_file.c_str(),
|
||||||
settings.binaural_mode, settings.gain_db, settings.tail_seconds,
|
settings.binaural_mode, settings.gain_db, settings.tail_seconds,
|
||||||
settings.object_delay_samples, settings.native_threads,
|
settings.object_delay_samples, settings.native_threads,
|
||||||
@@ -244,10 +223,9 @@ std::string describe(const joc_decode::Settings& settings) {
|
|||||||
std::string describe(const Values& values) {
|
std::string describe(const Values& values) {
|
||||||
char text[640] = {};
|
char text[640] = {};
|
||||||
std::snprintf(text, sizeof(text),
|
std::snprintf(text, sizeof(text),
|
||||||
"output=%d layout=%s hrtf=%s(%s) mode=%u gain=%s%.2f dB tail=%.2f s delay=%u "
|
"output=%d layout=%s hrtf=%s mode=%u gain=%s%.2f dB tail=%.2f s delay=%u "
|
||||||
"threads=%u ffmpeg=\"%s\"",
|
"threads=%u ffmpeg=\"%s\"",
|
||||||
values.output, values.speaker_layout.c_str(),
|
values.output, values.speaker_layout.c_str(), values.hrtf_file.c_str(),
|
||||||
hrtf_source_name(values.hrtf_source), values.hrtf_file.c_str(),
|
|
||||||
values.binaural_mode, values.gain_enabled ? "" : "(off) ", values.gain_db,
|
values.binaural_mode, values.gain_enabled ? "" : "(off) ", values.gain_db,
|
||||||
values.tail_seconds, values.object_delay_samples, values.native_threads,
|
values.tail_seconds, values.object_delay_samples, values.native_threads,
|
||||||
values.ffmpeg_path.c_str());
|
values.ffmpeg_path.c_str());
|
||||||
|
|||||||
+2
-12
@@ -17,24 +17,14 @@
|
|||||||
|
|
||||||
namespace joc_settings {
|
namespace joc_settings {
|
||||||
|
|
||||||
// Which HRTF the binaural renderer uses. Only these two inputs exist: everything
|
|
||||||
// else (compiling a SOFA into the renderer's field, caching it) is internal.
|
|
||||||
enum class HrtfSource {
|
|
||||||
kSofa = 0, // SOFA SimpleFreeFieldHRIR, compiled by the renderer
|
|
||||||
kRosella = 1, // Rosella .personalized_headphone model
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* hrtf_source_name(HrtfSource source);
|
|
||||||
const char* hrtf_source_extension(HrtfSource source);
|
|
||||||
// The file looked up in the default folder (next to the component) when no path
|
// The file looked up in the default folder (next to the component) when no path
|
||||||
// is configured; same names the reference CLI uses.
|
// is configured; same name the reference CLI uses.
|
||||||
const char* hrtf_default_file_name(HrtfSource source);
|
const char* hrtf_default_file_name();
|
||||||
|
|
||||||
// The stored values, exactly as the preferences page shows them.
|
// The stored values, exactly as the preferences page shows them.
|
||||||
struct Values {
|
struct Values {
|
||||||
int output = 0; // 0 = binaural, 1 = speaker layout
|
int output = 0; // 0 = binaural, 1 = speaker layout
|
||||||
std::string speaker_layout = "7.1";
|
std::string speaker_layout = "7.1";
|
||||||
HrtfSource hrtf_source = HrtfSource::kSofa;
|
|
||||||
// Empty means "the default file in the default folder".
|
// Empty means "the default file in the default folder".
|
||||||
std::string hrtf_file;
|
std::string hrtf_file;
|
||||||
unsigned binaural_mode = 3; // JOC_BINAURAL_NEAR/FAR/MID = 1/2/3
|
unsigned binaural_mode = 3; // JOC_BINAURAL_NEAR/FAR/MID = 1/2/3
|
||||||
|
|||||||
Reference in new issue
Block a user