Fixed up shorten decoder.

CQTexperiment
vspader 2007-05-16 01:30:28 +00:00
parent 79934e0607
commit a18ab13d58
3 changed files with 20 additions and 56 deletions

View File

@ -58,7 +58,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
ioData->mBuffers[0].mDataByteSize = 0;
ioData->mNumberBuffers = 1;
*ioNumberDataPackets = 0;
//Reset the converter's internal bufferrs.
converter->needsReset = YES;
}

View File

@ -17,9 +17,6 @@
shn_reader *decoder;
long bufferSize; //total size
void *buffer;
void *inputBuffer;//derek
long bufferAmount; //amount currently in
int channels;
int bitsPerSample;

View File

@ -28,7 +28,6 @@
decoder->open([[url path] UTF8String], true);
bufferSize = decoder->shn_get_buffer_block_size(512);
buffer = malloc(bufferSize);
decoder->file_info(NULL, &channels, &frequency, NULL, &bitsPerSample, NULL);
@ -44,55 +43,29 @@
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
{
//long numread = bufferAmount;
//long count = 0;
long numread, count;
bufferAmount = 0;
inputBuffer = malloc(bufferSize);
long totalRead, amountRead, amountToRead;
//Fill from buffer, going by bufferAmount
//if still needs more, decode and repeat
if (bufferAmount == 0)
{
//bufferAmount = shn_read(handle, buffer, bufferSize);
while((bufferAmount = decoder->read(inputBuffer, bufferSize)) == (unsigned)(-1))
totalRead = 0;
while (totalRead < size) {
amountToRead = size - totalRead;
if (amountToRead > bufferSize) {
amountToRead = bufferSize;
}
do
{
bufferAmount = decoder->read(inputBuffer, bufferSize);
amountRead = decoder->read(((char *)buf) + totalRead, amountToRead);
} while(amountRead == -1);
if (amountRead <= 0) {
return totalRead;
}
if (bufferAmount == 0) {
return 0;
}
else if(bufferAmount == (unsigned)( -2))
{
return -2;
}
else
{
memcpy(buffer, inputBuffer, bufferAmount);
free(inputBuffer);
}
}
count = bufferAmount;
if (bufferAmount > size)
{
count = size;
}
memcpy(buf, buffer, count);
bufferAmount -= count;
if (bufferAmount > 0)
memmove(buffer, (&((char *)buffer)[count]), bufferAmount);
if (count < size)
numread = [self fillBuffer:(&((char *)buf)[count]) ofSize:(size - count)];
else
numread = 0;
return count + numread;
totalRead += amountRead;
}
return totalRead;
}
- (double)seekToTime:(double)milliseconds
@ -120,12 +93,6 @@
decoder = NULL;
}
if (buffer)
{
free(buffer);
buffer = NULL;
}
/*if (shn_cleanup_decoder(handle))
shn_unload(handle);*/
}