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?
/*HACK TO TEST HOW WELL THIS WOULD WORK*/
[bufferChain seek:time];
[output seek:time];
[bufferChain seek:time];
/*END HACK*/
}

View File

@ -87,19 +87,7 @@
- (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 writeLock] unlock];
[[inputNode readLock] unlock];
}
- (void)endOfInputReached
@ -109,6 +97,7 @@
- (void)initialBufferFilled
{
NSLog(@"Filled initial buffer!");
[controller launchOutputThread];
}

View File

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

View File

@ -64,6 +64,12 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
return err;
}
- (void)reset
{
NSLog(@"RESETTING");
AudioConverterReset(converter);
}
- (int)convert:(void *)input amount:(int)inputSize
{
AudioBufferList ioData;
@ -89,7 +95,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
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
{
AudioConverterReset(converter);
[self reset];
}
outputBufferSize = ioData.mBuffers[0].mDataByteSize;

View File

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

View File

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

View File

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

View File

@ -44,16 +44,19 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
amountToRead = inNumberFrames*(output->deviceFormat.mBytesPerPacket);
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!
{
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
amountRead2 = [output->outputController readData:(readPointer+amountRead) amount:amountToRead-amountRead];
amountRead += amountRead2;
}
// NSLog(@"Amount read: %i", 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;
}