Improve audio buffering situation
Buffer up to 20 seconds per stage, and buffer only up to 2 seconds before starting the next stage. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
fb72db74f8
commit
122b6d6a6d
2 changed files with 25 additions and 19 deletions
|
@ -33,6 +33,8 @@
|
|||
AudioStreamBasicDescription nodeFormat;
|
||||
uint32_t nodeChannelConfig;
|
||||
BOOL nodeLossless;
|
||||
|
||||
double durationPrebuffer;
|
||||
}
|
||||
- (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
- (id)initWithController:(id)c previous:(id)p {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
buffer = [[ChunkList alloc] initWithMaximumDuration:1.0];
|
||||
buffer = [[ChunkList alloc] initWithMaximumDuration:20.0];
|
||||
semaphore = [[Semaphore alloc] init];
|
||||
|
||||
accessLock = [[NSLock alloc] init];
|
||||
|
@ -36,6 +36,8 @@
|
|||
nodeChannelConfig = 0;
|
||||
nodeLossless = NO;
|
||||
|
||||
durationPrebuffer = 2.0;
|
||||
|
||||
[self setPreviousNode:p];
|
||||
}
|
||||
|
||||
|
@ -66,10 +68,10 @@
|
|||
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
||||
|
||||
const double chunkDuration = [chunk duration];
|
||||
double durationLeft = [buffer maxDuration] - [buffer listDuration];
|
||||
double durationList = [buffer listDuration];
|
||||
double durationLeft = [buffer maxDuration] - durationList;
|
||||
|
||||
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||
if(durationLeft < chunkDuration) {
|
||||
if(shouldContinue == YES && durationList > durationPrebuffer) {
|
||||
if(initialBufferFilled == NO) {
|
||||
initialBufferFilled = YES;
|
||||
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
||||
|
@ -77,6 +79,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||
if(durationLeft < chunkDuration || shouldReset) {
|
||||
[accessLock unlock];
|
||||
[semaphore wait];
|
||||
|
@ -95,10 +98,10 @@
|
|||
[accessLock lock];
|
||||
|
||||
const double chunkDuration = [chunk duration];
|
||||
double durationLeft = [buffer maxDuration] - [buffer listDuration];
|
||||
double durationList = [buffer listDuration];
|
||||
double durationLeft = [buffer maxDuration] - durationList;
|
||||
|
||||
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||
if(durationLeft < chunkDuration) {
|
||||
if(shouldContinue == YES && durationList > durationPrebuffer) {
|
||||
if(initialBufferFilled == NO) {
|
||||
initialBufferFilled = YES;
|
||||
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
||||
|
@ -106,6 +109,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||
if(durationLeft < chunkDuration || shouldReset) {
|
||||
[accessLock unlock];
|
||||
[semaphore wait];
|
||||
|
|
Loading…
Reference in a new issue