Handled FLAC seeking to the end of file, and stopping on seek errors in general

CQTexperiment
Chris Moeller 2014-03-26 02:46:36 -07:00
parent 104e4c140f
commit 9d5a1fc32e
2 changed files with 5 additions and 3 deletions

View File

@ -117,6 +117,7 @@
void *inputBuffer = malloc(CHUNK_SIZE);
BOOL shouldClose = YES;
BOOL seekError = NO;
while ([self shouldContinue] == YES && [self endOfStream] == NO)
{
@ -126,7 +127,7 @@
BOOL isPaused = [output isPaused];
if ( !isPaused ) [output pause];
DLog(@"SEEKING!");
[decoder seek:seekFrame];
seekError = [decoder seek:seekFrame] < 0;
if ( !isPaused ) [output resume];
shouldSeek = NO;
DLog(@"Seeked! Resetting Buffer");
@ -141,7 +142,7 @@
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
if (framesRead > 0)
if (framesRead > 0 && !seekError)
{
amountInBuffer += (framesRead * bytesPerFrame);
[self writeData:inputBuffer amount:amountInBuffer];

View File

@ -262,7 +262,8 @@ void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorS
- (long)seek:(long)sample
{
FLAC__stream_decoder_seek_absolute(decoder, sample);
if (!FLAC__stream_decoder_seek_absolute(decoder, sample))
return -1;
return sample;
}