Muleiple vorbis bitstreams in one file for streaming. Bitstreams can be different formats. (!)

CQTexperiment
vspader 2007-03-03 22:55:26 +00:00
parent aafb021a80
commit c810d2f492
4 changed files with 38 additions and 30 deletions

View File

@ -20,6 +20,7 @@
//Temporary for callback use
void *inputBuffer;
int inputBufferSize;
BOOL needsReset;
//end
int outputSize;

View File

@ -46,10 +46,13 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
converter->inputBufferSize = 0;
}
else {
NSLog(@"RETURNING 0");
ioData->mBuffers[0].mData = NULL;
ioData->mBuffers[0].mDataByteSize = 0;
ioData->mNumberBuffers = 1;
*ioNumberDataPackets = 0;
//Reset the converter's internal bufferrs.
converter->needsReset = YES;
}
return err;
@ -62,20 +65,20 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
OSStatus err;
needsReset = NO;
ioNumberFrames = outputSize/outputFormat.mBytesPerFrame;
ioData.mBuffers[0].mData = outputBuffer;
ioData.mBuffers[0].mDataByteSize = outputSize;
ioData.mBuffers[0].mNumberChannels = outputFormat.mChannelsPerFrame;
ioData.mNumberBuffers = 1;
inputBuffer = input;
inputBufferSize = inputSize;
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 != noErr || needsReset) //It returns insz at EOS at times...so run it again to make sure all data is converted
{
NSLog(@"WOAH NELLY THIS SHOULDNT BE A-HAPPENIN");
// return [self convert:input amount:inputSize];
AudioConverterReset(converter);
}
return ioData.mBuffers[0].mDataByteSize;
@ -115,7 +118,11 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
(void*)&outputSize);
if (outputBuffer)
{
NSLog(@"FREEING");
free(outputBuffer);
NSLog(@"FREED");
}
outputBuffer = malloc(outputSize);
@ -133,9 +140,10 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
- (void)cleanUp
{
if (outputBuffer)
if (outputBuffer) {
free(outputBuffer);
outputBuffer = NULL;
}
AudioConverterDispose(converter);
}

View File

@ -95,12 +95,10 @@
}
amountRead = [decoder fillBuffer:inputBuffer ofSize:CHUNK_SIZE];
amountConverted = [converter convert:inputBuffer amount:amountRead]; //Convert fills in converter buffer, til the next call
if (amountConverted <= 0)
{
endOfStream = YES;
DBLog(@"END OF INPUT WAS REACHED");
[controller endOfInputReached];
break; //eof
}

View File

@ -80,30 +80,31 @@ long sourceTell(void *datasource)
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
{
int numread;
int total = 0;
do {
lastSection = currentSection;
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, &currentSection);
if (numread > 0) {
total += numread;
}
if (currentSection != lastSection) {
vorbis_info *vi;
vi = ov_info(&vorbisRef, -1);
bitsPerSample = vi->channels * 8;
bitrate = (vi->bitrate_nominal/1000.0);
channels = vi->channels;
frequency = vi->rate;
NSLog(@"Format changed...");
}
if (currentSection != lastSection) {
vorbis_info *vi;
vi = ov_info(&vorbisRef, -1);
} while (total != size && numread != 0);
bitsPerSample = vi->channels * 8;
bitrate = (vi->bitrate_nominal/1000.0);
channels = vi->channels;
frequency = vi->rate;
NSLog(@"Format changed...");
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
NSLog(@"Done with format change...");
}
return total;
lastSection = currentSection;
do {
numread = ov_read(&vorbisRef, (char *)buf, size, 0, bitsPerSample/8, 1, &currentSection);
if (numread < 0) {
NSLog(@"SOME KINDA ERROR!");
}
} while (numread < 0);
return numread;
}
- (void)close