Visualization: Improve latency and buffering appearance
Adjust the buffering so if latency is too low, we fill the rest of the output with silence instead of peeking at the oldest part of the buffer. Also increase latency by half a buffer size so that the requested sample is in the center of the buffer, which improves the 4096 sample situation with the current low latency output. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
416e77d220
commit
8e90da6292
1 changed files with 13 additions and 2 deletions
|
@ -98,15 +98,26 @@ class VisualizationController : NSObject {
|
|||
var outPCMCopy = Array<Float>(repeating: 0.0, count: 4096)
|
||||
|
||||
serialQueue.sync {
|
||||
let latencySamples = (Int)(self.latency * self.sampleRate)
|
||||
// Offset latency so the target sample is in the center of the window
|
||||
let latencySamples = (Int)((self.latency + latencyOffset) * self.sampleRate) + 2048
|
||||
var samplesToDo = 4096;
|
||||
if(latencySamples < 4096) {
|
||||
// Latency can sometimes dip below this threshold
|
||||
samplesToDo = latencySamples;
|
||||
}
|
||||
var j = self.visAudioCursor - latencySamples
|
||||
let k = self.visAudioSize
|
||||
if j < 0 { j += k }
|
||||
for i in 0...4095 {
|
||||
for i in 0..<samplesToDo {
|
||||
let x = self.visAudio[j]
|
||||
outPCMCopy[i] = x
|
||||
j += 1; if j >= k { j = 0 }
|
||||
}
|
||||
if(samplesToDo < 4096) {
|
||||
for i in samplesToDo...4095 {
|
||||
outPCMCopy[i] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(outPCM != nil) {
|
||||
|
|
Loading…
Reference in a new issue