-
Notifications
You must be signed in to change notification settings - Fork 1
feat(core): add authored stereo haptics analysis #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1638f02
feat(core): add authored stereo haptics analysis
qiin2333 a1f2f3d
fix(core): harden authored stereo ABI boundaries
qiin2333 3ca5da4
fix(authored): make analysis timing chunk invariant
qiin2333 6afdfc2
test(authored): verify error output reset
qiin2333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /build/ | ||
| /build-*/ | ||
| /consumer-build/ | ||
| /dist/ | ||
| /install/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.6.0 | ||
| 0.7.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #ifndef MOONLIGHT_HAPTICS_AUTHORED_HAPTICS_H | ||
| #define MOONLIGHT_HAPTICS_AUTHORED_HAPTICS_H | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| #include "moonlight_haptics/audio_haptics.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* | ||
| * Device-independent, two-lane authored haptics analysis. | ||
| * | ||
| * This API is a fallback for transports that cannot carry the original | ||
| * haptics PCM. It intentionally preserves the two source lanes and leaves | ||
| * actuator calibration and rendering to the client. | ||
| */ | ||
| typedef struct AhAuthoredEngine AhAuthoredEngine; | ||
|
|
||
| typedef uint32_t AhAuthoredInputFlags; | ||
| enum { | ||
| AH_AUTHORED_INPUT_NONE = 0, | ||
| AH_AUTHORED_INPUT_STREAM_START = 1u << 0, | ||
| AH_AUTHORED_INPUT_DISCONTINUITY = 1u << 1, | ||
| AH_AUTHORED_INPUT_STREAM_END = 1u << 2 | ||
| }; | ||
|
|
||
| typedef uint32_t AhAuthoredFrameFlags; | ||
| enum { | ||
| AH_AUTHORED_FRAME_NONE = 0, | ||
| AH_AUTHORED_FRAME_DISCONTINUITY = 1u << 0, | ||
| AH_AUTHORED_FRAME_PARTIAL = 1u << 1, | ||
| AH_AUTHORED_FRAME_STREAM_END = 1u << 2, | ||
| AH_AUTHORED_FRAME_SILENT = 1u << 3 | ||
| }; | ||
|
|
||
| typedef struct AhAuthoredConfig { | ||
| uint32_t struct_size; | ||
| uint32_t sample_rate; | ||
| uint32_t channel_count; /* Must be 2. */ | ||
| uint32_t analysis_hop_frames; /* 0 selects 5 ms. */ | ||
| uint32_t feature_flags; /* Must be 0 in ABI v2. */ | ||
| uint32_t reserved[7]; | ||
| } AhAuthoredConfig; | ||
|
|
||
| typedef struct AhAuthoredProcessInput { | ||
| uint32_t struct_size; | ||
| const int16_t* interleaved_pcm; | ||
| uint32_t frame_count; | ||
| uint32_t flags; /* AhAuthoredInputFlags bitset. */ | ||
| uint64_t first_sample_time_us; | ||
| uint32_t sequence_number; /* Monotonic per stream, wraps naturally. */ | ||
| uint32_t reserved; | ||
| } AhAuthoredProcessInput; | ||
|
|
||
| typedef struct AhAuthoredLaneFrame { | ||
| float rms_amplitude; /* Linear full scale, 0.0 .. 1.0. */ | ||
| float peak_amplitude; /* Linear full scale, 0.0 .. 1.0. */ | ||
| float transient_strength; /* Relative attack, 0.0 .. 1.0. */ | ||
| float low_band_ratio; /* Energy below roughly 200 Hz, 0.0 .. 1.0. */ | ||
| /* Sign transitions per second; a texture hint, not a pitch estimate. */ | ||
| float zero_crossing_rate_hz; | ||
| uint32_t reserved[3]; | ||
| } AhAuthoredLaneFrame; | ||
|
|
||
| typedef struct AhAuthoredHapticFrame { | ||
| uint32_t struct_size; | ||
| uint32_t flags; /* AhAuthoredFrameFlags bitset. */ | ||
| uint64_t timestamp_us; /* End time of the represented PCM window. */ | ||
| uint32_t source_sequence_number; | ||
| uint32_t source_frame_count; | ||
| AhAuthoredLaneFrame lanes[2]; /* Source order: left, right. */ | ||
| float lane_correlation; /* -1.0 .. 1.0; diagnostic only. */ | ||
| uint32_t reserved[3]; | ||
| } AhAuthoredHapticFrame; | ||
|
|
||
| #define AH_AUTHORED_CONFIG_V2_SIZE 48u | ||
| #define AH_AUTHORED_PROCESS_INPUT_V2_SIZE \ | ||
| ((uint32_t)(offsetof(AhAuthoredProcessInput, reserved) + sizeof(uint32_t))) | ||
| #define AH_AUTHORED_LANE_FRAME_V2_SIZE 32u | ||
| #define AH_AUTHORED_HAPTIC_FRAME_V2_SIZE 104u | ||
|
|
||
| MOONLIGHT_HAPTICS_API AhStatus ah_authored_config_init( | ||
| AhAuthoredConfig* config, | ||
| uint32_t sample_rate); | ||
|
|
||
| MOONLIGHT_HAPTICS_API AhStatus ah_authored_create( | ||
| const AhAuthoredConfig* config, | ||
| AhAuthoredEngine** out_engine); | ||
|
|
||
| MOONLIGHT_HAPTICS_API uint32_t ah_authored_get_max_output_frames( | ||
| const AhAuthoredEngine* engine, | ||
| uint32_t input_frame_count, | ||
| uint32_t input_flags); | ||
|
|
||
| /* | ||
| * No allocation, locking, logging, or platform calls occur in this function. | ||
| * On AH_STATUS_BUFFER_TOO_SMALL, input is not consumed and out_count is zero. | ||
| */ | ||
| MOONLIGHT_HAPTICS_API AhStatus ah_authored_process_i16( | ||
| AhAuthoredEngine* engine, | ||
| const AhAuthoredProcessInput* input, | ||
| AhAuthoredHapticFrame* out_frames, | ||
| uint32_t out_capacity, | ||
| uint32_t* out_count); | ||
|
|
||
| MOONLIGHT_HAPTICS_API void ah_authored_reset(AhAuthoredEngine* engine); | ||
| MOONLIGHT_HAPTICS_API void ah_authored_destroy(AhAuthoredEngine* engine); | ||
|
|
||
| #ifdef __cplusplus | ||
| } // extern "C" | ||
| #endif | ||
|
|
||
| #endif // MOONLIGHT_HAPTICS_AUTHORED_HAPTICS_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.