Gapless playback fixes.

CQTexperiment
vspader 2007-03-03 21:13:25 +00:00
parent 1e16835c8c
commit aafb021a80
3 changed files with 30 additions and 32 deletions

View File

@ -15,28 +15,24 @@
{ {
AudioConverterRef converter; AudioConverterRef converter;
void *inputBuffer;
void *outputBuffer; void *outputBuffer;
//Temporary for callback use //Temporary for callback use
void *inputBuffer;
int inputBufferSize; int inputBufferSize;
//end //end
int outputSize; int outputSize;
int maxInputSize;
AudioStreamBasicDescription inputFormat; AudioStreamBasicDescription inputFormat;
AudioStreamBasicDescription outputFormat; AudioStreamBasicDescription outputFormat;
} }
- (void *)outputBuffer; - (void *)outputBuffer;
- (void *)inputBuffer;
- (void)setupWithInputFormat:(AudioStreamBasicDescription)inputFormat outputFormat:(AudioStreamBasicDescription)outputFormat; - (void)setupWithInputFormat:(AudioStreamBasicDescription)inputFormat outputFormat:(AudioStreamBasicDescription)outputFormat;
- (void)cleanUp; - (void)cleanUp;
- (int)convert:(int)amount; - (int)convert:(void *)input amount:(int)inputSize;
- (int)maxInputSize;
@end @end

View File

@ -35,15 +35,27 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
Converter *converter = (Converter *)inUserData; Converter *converter = (Converter *)inUserData;
OSStatus err = noErr; OSStatus err = noErr;
ioData->mBuffers[0].mData = converter->inputBuffer; if (converter->inputBufferSize > 0) {
ioData->mBuffers[0].mDataByteSize = converter->inputBufferSize; ioData->mBuffers[0].mData = converter->inputBuffer;
ioData->mBuffers[0].mNumberChannels = (converter->inputFormat.mChannelsPerFrame); ioData->mBuffers[0].mDataByteSize = converter->inputBufferSize;
ioData->mNumberBuffers = 1; ioData->mBuffers[0].mNumberChannels = (converter->inputFormat.mChannelsPerFrame);
ioData->mNumberBuffers = 1;
*ioNumberDataPackets = converter->inputBufferSize / converter->inputFormat.mBytesPerFrame;
converter->inputBufferSize = 0;
}
else {
NSLog(@"RETURNING 0");
ioData->mBuffers[0].mData = NULL;
ioData->mBuffers[0].mDataByteSize = 0;
*ioNumberDataPackets = 0;
}
return err; return err;
} }
- (int)convert:(int)inputSize - (int)convert:(void *)input amount:(int)inputSize
{ {
AudioBufferList ioData; AudioBufferList ioData;
UInt32 ioNumberFrames; UInt32 ioNumberFrames;
@ -56,12 +68,14 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
ioData.mBuffers[0].mNumberChannels = outputFormat.mChannelsPerFrame; ioData.mBuffers[0].mNumberChannels = outputFormat.mChannelsPerFrame;
ioData.mNumberBuffers = 1; ioData.mNumberBuffers = 1;
inputBuffer = input;
inputBufferSize = inputSize; inputBufferSize = inputSize;
err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL); err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL);
if (err == kAudioConverterErr_InvalidInputSize) //It returns insz at EOS at times...so run it again to make sure all data is converted if (err == kAudioConverterErr_InvalidInputSize) //It returns insz at EOS at times...so run it again to make sure all data is converted
{ {
return [self convert:inputSize]; NSLog(@"WOAH NELLY THIS SHOULDNT BE A-HAPPENIN");
// return [self convert:input amount:inputSize];
} }
return ioData.mBuffers[0].mDataByteSize; return ioData.mBuffers[0].mDataByteSize;
@ -94,20 +108,16 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
} }
outputSize = CHUNK_SIZE; outputSize = CHUNK_SIZE;
maxInputSize = outputSize; UInt32 dataSize = sizeof(outputSize);
UInt32 dataSize = sizeof(maxInputSize);
AudioConverterGetProperty(converter, AudioConverterGetProperty(converter,
kAudioConverterPropertyCalculateInputBufferSize, kAudioConverterPropertyCalculateOutputBufferSize,
&dataSize, &dataSize,
(void*)&maxInputSize); (void*)&outputSize);
if (outputBuffer) if (outputBuffer)
free(outputBuffer); free(outputBuffer);
outputBuffer = malloc(outputSize); outputBuffer = malloc(outputSize);
if (inputBuffer)
free(inputBuffer);
inputBuffer = malloc(maxInputSize);
NSLog(@"Converter setup!"); NSLog(@"Converter setup!");
@ -115,25 +125,14 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
PrintStreamDesc(&outf); PrintStreamDesc(&outf);
} }
- (int)maxInputSize
{
return maxInputSize;
}
- (void *)outputBuffer - (void *)outputBuffer
{ {
return outputBuffer; return outputBuffer;
} }
- (void *)inputBuffer
{
return inputBuffer;
}
- (void)cleanUp - (void)cleanUp
{ {
if (inputBuffer)
free(inputBuffer);
if (outputBuffer) if (outputBuffer)
free(outputBuffer); free(outputBuffer);

View File

@ -81,6 +81,7 @@
- (void)process - (void)process
{ {
int amountRead, amountConverted; int amountRead, amountConverted;
void *inputBuffer = malloc(CHUNK_SIZE);
NSLog(@"Playing file: %i", self); NSLog(@"Playing file: %i", self);
@ -93,9 +94,9 @@
shouldSeek = NO; shouldSeek = NO;
} }
amountRead = [decoder fillBuffer:[converter inputBuffer] ofSize:[converter maxInputSize]]; amountRead = [decoder fillBuffer:inputBuffer ofSize:CHUNK_SIZE];
amountConverted = [converter convert:amountRead]; //Convert fills in converter buffer, til the next call amountConverted = [converter convert:inputBuffer amount:amountRead]; //Convert fills in converter buffer, til the next call
if (amountConverted <= 0) if (amountConverted <= 0)
{ {
endOfStream = YES; endOfStream = YES;
@ -110,6 +111,8 @@
[decoder close]; [decoder close];
[converter cleanUp]; [converter cleanUp];
free(inputBuffer);
NSLog(@"CLOSED: %i", self); NSLog(@"CLOSED: %i", self);
} }