Fixed up shorten decoder.
parent
79934e0607
commit
a18ab13d58
|
@ -58,7 +58,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
|
||||||
ioData->mBuffers[0].mDataByteSize = 0;
|
ioData->mBuffers[0].mDataByteSize = 0;
|
||||||
ioData->mNumberBuffers = 1;
|
ioData->mNumberBuffers = 1;
|
||||||
*ioNumberDataPackets = 0;
|
*ioNumberDataPackets = 0;
|
||||||
|
|
||||||
//Reset the converter's internal bufferrs.
|
//Reset the converter's internal bufferrs.
|
||||||
converter->needsReset = YES;
|
converter->needsReset = YES;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
shn_reader *decoder;
|
shn_reader *decoder;
|
||||||
|
|
||||||
long bufferSize; //total size
|
long bufferSize; //total size
|
||||||
void *buffer;
|
|
||||||
void *inputBuffer;//derek
|
|
||||||
long bufferAmount; //amount currently in
|
|
||||||
|
|
||||||
int channels;
|
int channels;
|
||||||
int bitsPerSample;
|
int bitsPerSample;
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
decoder->open([[url path] UTF8String], true);
|
decoder->open([[url path] UTF8String], true);
|
||||||
|
|
||||||
bufferSize = decoder->shn_get_buffer_block_size(512);
|
bufferSize = decoder->shn_get_buffer_block_size(512);
|
||||||
buffer = malloc(bufferSize);
|
|
||||||
|
|
||||||
decoder->file_info(NULL, &channels, &frequency, NULL, &bitsPerSample, NULL);
|
decoder->file_info(NULL, &channels, &frequency, NULL, &bitsPerSample, NULL);
|
||||||
|
|
||||||
|
@ -44,55 +43,29 @@
|
||||||
|
|
||||||
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
||||||
{
|
{
|
||||||
//long numread = bufferAmount;
|
long totalRead, amountRead, amountToRead;
|
||||||
//long count = 0;
|
|
||||||
long numread, count;
|
|
||||||
bufferAmount = 0;
|
|
||||||
inputBuffer = malloc(bufferSize);
|
|
||||||
|
|
||||||
//Fill from buffer, going by bufferAmount
|
totalRead = 0;
|
||||||
//if still needs more, decode and repeat
|
|
||||||
if (bufferAmount == 0)
|
while (totalRead < size) {
|
||||||
{
|
amountToRead = size - totalRead;
|
||||||
//bufferAmount = shn_read(handle, buffer, bufferSize);
|
if (amountToRead > bufferSize) {
|
||||||
while((bufferAmount = decoder->read(inputBuffer, bufferSize)) == (unsigned)(-1))
|
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
|
- (double)seekToTime:(double)milliseconds
|
||||||
|
@ -120,12 +93,6 @@
|
||||||
decoder = NULL;
|
decoder = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer)
|
|
||||||
{
|
|
||||||
free(buffer);
|
|
||||||
buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if (shn_cleanup_decoder(handle))
|
/*if (shn_cleanup_decoder(handle))
|
||||||
shn_unload(handle);*/
|
shn_unload(handle);*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue