mirror of https://github.com/jetkvm/kvm.git
Cleanup, Optimizations: Small aaudio optimizations
This commit is contained in:
parent
7ffb9e1d59
commit
8a3f1b6c32
|
@ -11,3 +11,4 @@ tmp/
|
||||||
|
|
||||||
device-tests.tar.gz
|
device-tests.tar.gz
|
||||||
CLAUDE.md
|
CLAUDE.md
|
||||||
|
.claude/
|
|
@ -49,7 +49,7 @@ static int max_attempts_global = 5; // Maximum retry attempts
|
||||||
static int max_backoff_us_global = 500000; // Maximum backoff time
|
static int max_backoff_us_global = 500000; // Maximum backoff time
|
||||||
|
|
||||||
// Performance optimization flags
|
// Performance optimization flags
|
||||||
static int optimized_buffer_size = 1; // Use optimized buffer sizing
|
static const int optimized_buffer_size = 1; // Use optimized buffer sizing
|
||||||
static int trace_logging_enabled = 0; // Enable detailed trace logging
|
static int trace_logging_enabled = 0; // Enable detailed trace logging
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -395,9 +395,12 @@ int jetkvm_audio_capture_init() {
|
||||||
* 0: No audio data available (not an error)
|
* 0: No audio data available (not an error)
|
||||||
* -1: Initialization error or unrecoverable failure
|
* -1: Initialization error or unrecoverable failure
|
||||||
*/
|
*/
|
||||||
int jetkvm_audio_read_encode(void *opus_buf) {
|
__attribute__((hot)) int jetkvm_audio_read_encode(void *opus_buf) {
|
||||||
static short pcm_buffer[1920]; // max 2ch*960
|
static short __attribute__((aligned(16))) pcm_buffer[1920]; // max 2ch*960, aligned for SIMD
|
||||||
unsigned char *out = (unsigned char*)opus_buf;
|
unsigned char * __restrict__ out = (unsigned char*)opus_buf;
|
||||||
|
|
||||||
|
// Prefetch output buffer for better cache performance
|
||||||
|
__builtin_prefetch(out, 1, 3);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int recovery_attempts = 0;
|
int recovery_attempts = 0;
|
||||||
const int max_recovery_attempts = 3;
|
const int max_recovery_attempts = 3;
|
||||||
|
@ -483,8 +486,8 @@ retry_read:
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we got fewer frames than expected, pad with silence
|
// If we got fewer frames than expected, pad with silence
|
||||||
if (pcm_rc < frame_size) {
|
if (__builtin_expect(pcm_rc < frame_size, 0)) {
|
||||||
memset(&pcm_buffer[pcm_rc * channels], 0, (frame_size - pcm_rc) * channels * sizeof(short));
|
__builtin_memset(&pcm_buffer[pcm_rc * channels], 0, (frame_size - pcm_rc) * channels * sizeof(short));
|
||||||
}
|
}
|
||||||
|
|
||||||
int nb_bytes = opus_encode(encoder, pcm_buffer, frame_size, out, max_packet_size);
|
int nb_bytes = opus_encode(encoder, pcm_buffer, frame_size, out, max_packet_size);
|
||||||
|
@ -594,9 +597,12 @@ int jetkvm_audio_playback_init() {
|
||||||
* -1: Invalid input or decode failure
|
* -1: Invalid input or decode failure
|
||||||
* -2: Unrecoverable ALSA error
|
* -2: Unrecoverable ALSA error
|
||||||
*/
|
*/
|
||||||
int jetkvm_audio_decode_write(void *opus_buf, int opus_size) {
|
__attribute__((hot)) int jetkvm_audio_decode_write(void *opus_buf, int opus_size) {
|
||||||
static short pcm_buffer[1920]; // max 2ch*960
|
static short __attribute__((aligned(16))) pcm_buffer[1920]; // max 2ch*960, aligned for SIMD
|
||||||
unsigned char *in = (unsigned char*)opus_buf;
|
unsigned char * __restrict__ in = (unsigned char*)opus_buf;
|
||||||
|
|
||||||
|
// Prefetch input buffer for better cache performance
|
||||||
|
__builtin_prefetch(in, 0, 3);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int recovery_attempts = 0;
|
int recovery_attempts = 0;
|
||||||
const int max_recovery_attempts = 3;
|
const int max_recovery_attempts = 3;
|
||||||
|
|
Loading…
Reference in New Issue