Fix up gapless logic a little.

CQTexperiment
vspader 2009-02-26 22:12:05 -08:00
parent 876efcde38
commit 94259fd366
1 changed files with 11 additions and 7 deletions

View File

@ -360,27 +360,31 @@ audio_linear_round(unsigned int bits,
// NSLog(@"Counts: %i, %i", startingSample, sampleCount); // NSLog(@"Counts: %i, %i", startingSample, sampleCount);
if (_foundLAMEHeader) { if (_foundLAMEHeader) {
if (_framesDecoded < _startPadding) { // We are at the beginning and need to skip frames
if (_startPadding > _framesDecoded) {
// NSLog(@"Skipping start."); // NSLog(@"Skipping start.");
startingSample = _startPadding - _framesDecoded; startingSample = _startPadding - _framesDecoded;
} }
if (_framesDecoded > totalFrames - _endPadding + startingSample) { // Past the end of the file.
if (totalFrames - _endPadding <= _framesDecoded) {
// NSLog(@"End of file. Not writing."); // NSLog(@"End of file. Not writing.");
return; return;
} }
if (_framesDecoded + sampleCount + _endPadding > totalFrames + startingSample ) { // We haven't even gotten to the start yet
// NSLog(@"End of file. %li", totalFrames - _endPadding - _framesDecoded);
sampleCount = totalFrames + startingSample - _endPadding - _framesDecoded;
}
if (startingSample > sampleCount) { if (startingSample > sampleCount) {
// NSLog(@"Skipping entire sample"); // NSLog(@"Skipping entire sample");
_framesDecoded += _synth.pcm.length; _framesDecoded += _synth.pcm.length;
return; return;
} }
// We are at the end of the file and need to read the last few frames
if (_framesDecoded + (sampleCount - startingSample) > totalFrames - _endPadding) {
// NSLog(@"End of file. %li", totalFrames - _endPadding - _framesDecoded);
sampleCount = totalFrames - _endPadding - _framesDecoded + startingSample;
}
} }
//NSLog(@"Revised: %i, %i", startingSample, sampleCount); //NSLog(@"Revised: %i, %i", startingSample, sampleCount);