mirror of https://github.com/jetkvm/kvm.git
style(audio): fix formatting and add missing newlines
- Fix indentation in test files and supervisor code - Add missing newlines at end of files - Clean up documentation formatting - Fix buffer pool pointer return type
This commit is contained in:
parent
6a68e23d12
commit
e8d12bae4b
|
@ -182,8 +182,11 @@ func (abm *AdaptiveBufferManager) adaptationLoop() {
|
||||||
//
|
//
|
||||||
// Mathematical Model:
|
// Mathematical Model:
|
||||||
// 1. Factor Calculation:
|
// 1. Factor Calculation:
|
||||||
|
//
|
||||||
// - CPU Factor: Sigmoid function that increases buffer size under high CPU load
|
// - CPU Factor: Sigmoid function that increases buffer size under high CPU load
|
||||||
|
//
|
||||||
// - Memory Factor: Inverse relationship that decreases buffer size under memory pressure
|
// - Memory Factor: Inverse relationship that decreases buffer size under memory pressure
|
||||||
|
//
|
||||||
// - Latency Factor: Exponential decay that aggressively reduces buffers when latency exceeds targets
|
// - Latency Factor: Exponential decay that aggressively reduces buffers when latency exceeds targets
|
||||||
//
|
//
|
||||||
// 2. Combined Factor:
|
// 2. Combined Factor:
|
||||||
|
|
|
@ -40,7 +40,8 @@ func NewAudioBufferPool(bufferSize int) *AudioBufferPool {
|
||||||
preallocSize: preallocSize,
|
preallocSize: preallocSize,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return make([]byte, 0, bufferSize)
|
buf := make([]byte, 0, bufferSize)
|
||||||
|
return &buf
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,9 +254,10 @@ func validateAudioDataIntegrity(data []byte, channels int) error {
|
||||||
|
|
||||||
for i := 0; i < len(data); i += 2 {
|
for i := 0; i < len(data); i += 2 {
|
||||||
sample := int16(data[i]) | int16(data[i+1])<<8
|
sample := int16(data[i]) | int16(data[i+1])<<8
|
||||||
if sample == 0 {
|
switch sample {
|
||||||
|
case 0:
|
||||||
zeroCount++
|
zeroCount++
|
||||||
} else if sample == 32767 || sample == -32768 {
|
case 32767, -32768:
|
||||||
maxCount++
|
maxCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
// allocations and memory copying in the audio pipeline:
|
// allocations and memory copying in the audio pipeline:
|
||||||
//
|
//
|
||||||
// Key Features:
|
// Key Features:
|
||||||
|
//
|
||||||
// 1. Reference Counting: Multiple components can safely share the same frame data
|
// 1. Reference Counting: Multiple components can safely share the same frame data
|
||||||
// without copying. The frame is automatically returned to the pool when the last
|
// without copying. The frame is automatically returned to the pool when the last
|
||||||
// reference is released.
|
// reference is released.
|
||||||
|
@ -27,6 +28,7 @@ import (
|
||||||
// memory access is provided while maintaining safety through reference counting.
|
// memory access is provided while maintaining safety through reference counting.
|
||||||
//
|
//
|
||||||
// Usage Pattern:
|
// Usage Pattern:
|
||||||
|
//
|
||||||
// frame := pool.Get() // Acquire frame (refCount = 1)
|
// frame := pool.Get() // Acquire frame (refCount = 1)
|
||||||
// frame.AddRef() // Share with another component (refCount = 2)
|
// frame.AddRef() // Share with another component (refCount = 2)
|
||||||
// data := frame.Data() // Access data safely
|
// data := frame.Data() // Access data safely
|
||||||
|
@ -52,16 +54,19 @@ type ZeroCopyAudioFrame struct {
|
||||||
// real-time audio processing with minimal allocation overhead:
|
// real-time audio processing with minimal allocation overhead:
|
||||||
//
|
//
|
||||||
// Tier 1 - Pre-allocated Frames:
|
// Tier 1 - Pre-allocated Frames:
|
||||||
|
//
|
||||||
// A small number of frames are pre-allocated at startup and kept ready
|
// A small number of frames are pre-allocated at startup and kept ready
|
||||||
// for immediate use. This provides the fastest possible allocation for
|
// for immediate use. This provides the fastest possible allocation for
|
||||||
// the most common case and eliminates allocation latency spikes.
|
// the most common case and eliminates allocation latency spikes.
|
||||||
//
|
//
|
||||||
// Tier 2 - sync.Pool Cache:
|
// Tier 2 - sync.Pool Cache:
|
||||||
|
//
|
||||||
// The standard Go sync.Pool provides efficient reuse of frames with
|
// The standard Go sync.Pool provides efficient reuse of frames with
|
||||||
// automatic garbage collection integration. Frames are automatically
|
// automatic garbage collection integration. Frames are automatically
|
||||||
// returned here when memory pressure is low.
|
// returned here when memory pressure is low.
|
||||||
//
|
//
|
||||||
// Tier 3 - Memory Guard:
|
// Tier 3 - Memory Guard:
|
||||||
|
//
|
||||||
// A configurable limit prevents excessive memory usage by limiting
|
// A configurable limit prevents excessive memory usage by limiting
|
||||||
// the total number of allocated frames. When the limit is reached,
|
// the total number of allocated frames. When the limit is reached,
|
||||||
// allocation requests are denied to prevent OOM conditions.
|
// allocation requests are denied to prevent OOM conditions.
|
||||||
|
|
Loading…
Reference in New Issue