diff --git a/Audio/Chain/Converter.m b/Audio/Chain/Converter.m index cab75febd..7f324f22c 100644 --- a/Audio/Chain/Converter.m +++ b/Audio/Chain/Converter.m @@ -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; } diff --git a/Plugins/Shorten/ShortenDecoder.h b/Plugins/Shorten/ShortenDecoder.h index be3a78b39..27015da91 100644 --- a/Plugins/Shorten/ShortenDecoder.h +++ b/Plugins/Shorten/ShortenDecoder.h @@ -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; diff --git a/Plugins/Shorten/ShortenDecoder.mm b/Plugins/Shorten/ShortenDecoder.mm index c6dc9657c..5427ec6b8 100644 --- a/Plugins/Shorten/ShortenDecoder.mm +++ b/Plugins/Shorten/ShortenDecoder.mm @@ -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);*/ }