From 77c7819dd6651194337132eb635a70f182378bbb Mon Sep 17 00:00:00 2001 From: vspader Date: Mon, 19 Mar 2007 00:19:47 +0000 Subject: [PATCH] Added some error messages that should hopefully fix some initial stuttering issues. --- Audio/AudioPlayer.h | 3 +++ Audio/AudioPlayer.m | 12 ++++++++++-- Audio/Chain/BufferChain.h | 2 ++ Audio/Chain/BufferChain.m | 5 +++++ Audio/Chain/Node.h | 1 + Audio/Chain/Node.m | 15 ++++++++++++++- 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index 17975d5eb..a26c12b24 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -22,6 +22,8 @@ id nextStreamUserInfo; id delegate; + + BOOL outputLaunched; } - (id)init; @@ -65,6 +67,7 @@ - (void)endOfInputReached:(BufferChain *)sender; - (void)setShouldContinue:(BOOL)s; - (BufferChain *)bufferChain; +- (void)launchOutputThread; - (void)endOfInputPlayed; - (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait; @end diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 8a63e4a7c..3737d23b4 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -22,6 +22,7 @@ { output = NULL; bufferChain = NULL; + outputLaunched = NO; chainQueue = [[NSMutableArray alloc] init]; } @@ -91,9 +92,9 @@ [bufferChain setUserInfo:userInfo]; [self setShouldContinue:YES]; - DBLog(@"DETACHING THREADS"); - [output launchThread]; + outputLaunched = NO; + NSLog(@"Launching input thread!"); [bufferChain launchThreads]; [self setPlaybackStatus:kCogStatusPlaying]; @@ -165,6 +166,13 @@ return [output amountPlayed]; } +- (void)launchOutputThread +{ + if (outputLaunched == NO) { + NSLog(@"Launching output thread!"); + [output launchThread]; + } +} diff --git a/Audio/Chain/BufferChain.h b/Audio/Chain/BufferChain.h index ae9b71c28..4e3a359c2 100644 --- a/Audio/Chain/BufferChain.h +++ b/Audio/Chain/BufferChain.h @@ -40,6 +40,8 @@ - (void)setShouldContinue:(BOOL)s; +- (void)initialBufferFilled; + - (void)endOfInputReached; diff --git a/Audio/Chain/BufferChain.m b/Audio/Chain/BufferChain.m index 89a46fcd8..b44866fdf 100644 --- a/Audio/Chain/BufferChain.m +++ b/Audio/Chain/BufferChain.m @@ -107,6 +107,11 @@ [controller endOfInputReached:self]; } +- (void)initialBufferFilled +{ + [controller launchOutputThread]; +} + - (id)finalNode { diff --git a/Audio/Chain/Node.h b/Audio/Chain/Node.h index ab8aa83bd..226430655 100644 --- a/Audio/Chain/Node.h +++ b/Audio/Chain/Node.h @@ -24,6 +24,7 @@ BOOL shouldContinue; BOOL endOfStream; //All data is now in buffer + BOOL initialBufferFilled; } - (id)initWithController:(id)c previous:(id)p; diff --git a/Audio/Chain/Node.m b/Audio/Chain/Node.m index 581c3665c..dc25a3c14 100644 --- a/Audio/Chain/Node.m +++ b/Audio/Chain/Node.m @@ -20,6 +20,8 @@ readLock = [[NSLock alloc] init]; writeLock = [[NSLock alloc] init]; + initialBufferFilled = NO; + controller = c; previousNode = p; endOfStream = NO; @@ -43,6 +45,11 @@ if (availOutput == 0) { [writeLock unlock]; + if (initialBufferFilled == NO) { + initialBufferFilled = YES;\ + if ([controller respondsToSelector:@selector(initialBufferFilled)]) + [controller performSelector:@selector(initialBufferFilled)]; + } [semaphore wait]; [writeLock lock]; } @@ -104,7 +111,13 @@ //If it is the outputNode, [soundController newInputChain]; //else endOfStream = YES; - } + } + if (availInput <= 0) { + NSLog(@"BUFFER RAN DRY!"); + } + else if (availInput < amount) { + NSLog(@"BUFFER IN DANGER"); + } amountToCopy = availInput; if (amountToCopy > amount)