Changeset 1050

Show
Ignore:
Timestamp:
10/31/07 13:20:44 (15 months ago)
Author:
stephen_booth
Message:

Bug fixes for seeking

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Audio/Decoders/MPEGDecoder.m

    r1046 r1050  
    700700                _samplesToSkipInNextFrame       = 0; 
    701701                _samplesDecoded                         = 0; 
    702                  
    703                 // Zero the buffers 
    704                 unsigned i; 
    705                 for(i = 0; i < _bufferList->mNumberBuffers; ++i) 
    706                         _bufferList->mBuffers[i].mDataByteSize = 0; 
    707                  
     702 
    708703                mad_stream_buffer(&_mad_stream, NULL, 0); 
    709704        } 
    710  
     705        // Mark any buffered audio as read 
     706        else 
     707                _currentFrame += _bufferList->mBuffers[0].mDataByteSize / sizeof(float); 
     708         
     709        // Zero the buffers 
     710        unsigned i; 
     711        for(i = 0; i < _bufferList->mNumberBuffers; ++i) 
     712                _bufferList->mBuffers[i].mDataByteSize = 0; 
     713         
    711714        for(;;) { 
    712715                // All requested frames were skipped or read 
     
    758761                } 
    759762                 
    760                 // Decode the header only of the MPEG frame for speed 
    761                 int result = mad_header_decode(&_mad_frame.header, &_mad_stream); 
     763                // Decode the MPEG frame 
     764                int result = mad_frame_decode(&_mad_frame, &_mad_stream); 
    762765                if(-1 == result) { 
    763766                        if(MAD_RECOVERABLE(_mad_stream.error)) { 
     
    828831                // If this MPEG frame contains the desired seek frame, synthesize its audio to PCM 
    829832                if(_samplesDecoded + (sampleCount - startingSample) > frame) { 
    830                         // Finish decoding the MPEG frame 
    831                         result = mad_frame_decode(&_mad_frame, &_mad_stream); 
    832                         if(-1 == result) { 
    833                                 if(MAD_RECOVERABLE(_mad_stream.error)) { 
    834         #if DEBUG 
    835                                         NSLog(@"Recoverable frame level error (%s)", mad_stream_errorstr(&_mad_stream)); 
    836         #endif 
    837                                         continue; 
    838                                 } 
    839                                 else { 
    840         #if DEBUG 
    841                                         NSLog(@"Unrecoverable frame level error (%s)", mad_stream_errorstr(&_mad_stream)); 
    842         #endif 
    843                                         break; 
    844                                 } 
    845                         } 
    846                          
    847833                        // Synthesize the frame into PCM 
    848834                        mad_synth_frame(&_mad_synth, &_mad_frame); 
     
    870856 
    871857                        // Only a portion of the frame was skipped- the rest was synthesized and stored in our buffers 
    872                         _samplesDecoded += additionalSamplesToSkip; 
     858                        _samplesDecoded         += (sampleCount - startingSample); 
     859                        _currentFrame           += additionalSamplesToSkip; 
    873860                } 
    874861                // The entire frame was skipped 
    875                 else 
    876                         _samplesDecoded += (sampleCount - startingSample); 
     862                else { 
     863                        _samplesDecoded         += (sampleCount - startingSample); 
     864                        _currentFrame           += (sampleCount - startingSample); 
     865                } 
    877866        } 
    878          
    879         _currentFrame = _samplesDecoded; 
    880867         
    881868        return [self currentFrame];