Fixed some seeking bugs.

CQTexperiment
vspader 2007-05-26 22:13:11 +00:00
parent 7f177c29b4
commit 88d26d3461
8 changed files with 31 additions and 25 deletions

View File

@ -127,9 +127,8 @@
{ {
//Need to reset everything's buffers, and then seek? //Need to reset everything's buffers, and then seek?
/*HACK TO TEST HOW WELL THIS WOULD WORK*/ /*HACK TO TEST HOW WELL THIS WOULD WORK*/
[bufferChain seek:time];
[output seek:time]; [output seek:time];
[bufferChain seek:time];
/*END HACK*/ /*END HACK*/
} }

View File

@ -87,19 +87,7 @@
- (void)seek:(double)time - (void)seek:(double)time
{ {
[[inputNode readLock] lock];
[[inputNode writeLock] lock];
//Signal so its waiting when we unlock
[[inputNode semaphore] signal];
NSLog(@"Reset input buffer!");
[inputNode resetBuffer];
NSLog(@"Seeking in bufferchain!");
[inputNode seek:time]; [inputNode seek:time];
[[inputNode writeLock] unlock];
[[inputNode readLock] unlock];
} }
- (void)endOfInputReached - (void)endOfInputReached
@ -109,6 +97,7 @@
- (void)initialBufferFilled - (void)initialBufferFilled
{ {
NSLog(@"Filled initial buffer!");
[controller launchOutputThread]; [controller launchOutputThread];
} }

View File

@ -36,6 +36,8 @@
- (void)setupWithInputFormat:(AudioStreamBasicDescription)inputFormat outputFormat:(AudioStreamBasicDescription)outputFormat; - (void)setupWithInputFormat:(AudioStreamBasicDescription)inputFormat outputFormat:(AudioStreamBasicDescription)outputFormat;
- (void)cleanUp; - (void)cleanUp;
- (void)reset;
//Returns the amount actually read from input //Returns the amount actually read from input
- (int)convert:(void *)input amount:(int)inputSize; - (int)convert:(void *)input amount:(int)inputSize;

View File

@ -64,6 +64,12 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
return err; return err;
} }
- (void)reset
{
NSLog(@"RESETTING");
AudioConverterReset(converter);
}
- (int)convert:(void *)input amount:(int)inputSize - (int)convert:(void *)input amount:(int)inputSize
{ {
AudioBufferList ioData; AudioBufferList ioData;
@ -89,7 +95,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL); err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL);
if (err != noErr || needsReset) //It returns insz at EOS at times...so run it again to make sure all data is converted if (err != noErr || needsReset) //It returns insz at EOS at times...so run it again to make sure all data is converted
{ {
AudioConverterReset(converter); [self reset];
} }
outputBufferSize = ioData.mBuffers[0].mDataByteSize; outputBufferSize = ioData.mBuffers[0].mDataByteSize;

View File

@ -92,6 +92,9 @@
NSLog(@"Actually seeking"); NSLog(@"Actually seeking");
[decoder seekToTime:seekTime]; [decoder seekToTime:seekTime];
shouldSeek = NO; shouldSeek = NO;
[self resetBuffer];
initialBufferFilled = NO;
} }
if (amountInBuffer < CHUNK_SIZE) { if (amountInBuffer < CHUNK_SIZE) {
@ -133,7 +136,8 @@
NSLog(@"SEEKING IN INPUTNODE"); NSLog(@"SEEKING IN INPUTNODE");
seekTime = time; seekTime = time;
shouldSeek = YES; shouldSeek = YES;
initialBufferFilled = NO; [self resetBuffer];
[semaphore signal];
} }
- (void)dealloc - (void)dealloc

View File

@ -166,7 +166,13 @@
- (void)resetBuffer - (void)resetBuffer
{ {
[readLock lock];
[writeLock lock];
[buffer empty]; [buffer empty];
[writeLock unlock];
[readLock unlock];
} }
- (NSLock *)readLock - (NSLock *)readLock

View File

@ -24,8 +24,9 @@
- (void)seek:(double)time - (void)seek:(double)time
{ {
NSLog(@"SEEKING!");
[output pause]; [output pause];
[semaphore signal];
amountPlayed = time*format.mBytesPerFrame*(format.mSampleRate/1000.0); amountPlayed = time*format.mBytesPerFrame*(format.mSampleRate/1000.0);
} }
@ -52,15 +53,11 @@
previousNode = [[controller bufferChain] finalNode]; previousNode = [[controller bufferChain] finalNode];
n = [super readData:ptr amount:amount]; n = [super readData:ptr amount:amount];
// NSLog(@"N: %i %i", n, endOfStream);
if (endOfStream == YES) if (endOfStream == YES)
{ {
DBLog(@"End of stream reached: %i", endOfStream); NSLog(@"End of stream reached!");
amountPlayed = 0; amountPlayed = 0;
[controller endOfInputPlayed]; //Updates shouldContinue appropriately? [controller endOfInputPlayed]; //Updates shouldContinue appropriately?
DBLog(@"End of stream reached: %i", endOfStream);
// return (n + [self readData:ptr amount:(amount-n)]);
} }
if (n == 0) { if (n == 0) {

View File

@ -44,17 +44,20 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
amountToRead = inNumberFrames*(output->deviceFormat.mBytesPerPacket); amountToRead = inNumberFrames*(output->deviceFormat.mBytesPerPacket);
amountRead = [output->outputController readData:(readPointer) amount:amountToRead]; amountRead = [output->outputController readData:(readPointer) amount:amountToRead];
// NSLog(@"Amount read: %i %i", amountRead, [output->outputController endOfStream]);
if ((amountRead < amountToRead) && [output->outputController endOfStream] == NO) //Try one more time! for track changes! if ((amountRead < amountToRead) && [output->outputController endOfStream] == NO) //Try one more time! for track changes!
{ {
NSLog(@"READING AGAIN! %i/%i", amountRead, amountToRead);
int amountRead2; //Use this since return type of readdata isnt known...may want to fix then can do a simple += to readdata int amountRead2; //Use this since return type of readdata isnt known...may want to fix then can do a simple += to readdata
amountRead2 = [output->outputController readData:(readPointer+amountRead) amount:amountToRead-amountRead]; amountRead2 = [output->outputController readData:(readPointer+amountRead) amount:amountToRead-amountRead];
amountRead += amountRead2; amountRead += amountRead2;
} }
// NSLog(@"Amount read: %i", amountRead);
ioData->mBuffers[0].mDataByteSize = amountRead; ioData->mBuffers[0].mDataByteSize = amountRead;
ioData->mBuffers[0].mNumberChannels = output->deviceFormat.mChannelsPerFrame;
// NSLog(@"Amount read for output: (%i) %i %i/%i", ioData->mNumberBuffers, ioData->mBuffers[0].mNumberChannels, amountRead, amountToRead);
return err; return err;
} }