void AVIDecoder::AVIAudioTrack::skipAudio(const Audio::Timestamp &time, const Audio::Timestamp &frameTime) { Audio::Timestamp timeDiff = time.convertToFramerate(_wvInfo.samplesPerSec) - frameTime.convertToFramerate(_wvInfo.samplesPerSec); int skipFrames = timeDiff.totalNumberOfFrames(); if (skipFrames <= 0) return; if (_audStream->isStereo()) skipFrames *= 2; int16 *tempBuffer = new int16[skipFrames]; _audStream->readBuffer(tempBuffer, skipFrames); delete[] tempBuffer; }
void QuickTimeDecoder::VideoTrackHandler::seekToTime(Audio::Timestamp time) { // First, figure out what edit we're in time = time.convertToFramerate(_parent->timeScale); // Continue until we get to where we need to be for (_curEdit = 0; !endOfTrack(); _curEdit++) if ((uint32)time.totalNumberOfFrames() >= getCurEditTimeOffset() && (uint32)time.totalNumberOfFrames() < getCurEditTimeOffset() + getCurEditTrackDuration()) break; // This track is done if (endOfTrack()) return; enterNewEditList(false); // One extra check for the end of a track if (endOfTrack()) return; // Now we're in the edit and need to figure out what frame we need while (getRateAdjustedFrameTime() < (uint32)time.totalNumberOfFrames()) { _curFrame++; if (_durationOverride >= 0) { _nextFrameStartTime += _durationOverride; _durationOverride = -1; } else { _nextFrameStartTime += getFrameDuration(); } } // All that's left is to figure out what our starting time is going to be // Compare the starting point for the frame to where we need to be _holdNextFrameStartTime = getRateAdjustedFrameTime() != (uint32)time.totalNumberOfFrames(); // If we went past the time, go back a frame if (_holdNextFrameStartTime) _curFrame--; // Handle the keyframe here int32 destinationFrame = _curFrame + 1; assert(destinationFrame < (int32)_parent->frameCount); _curFrame = findKeyFrame(destinationFrame) - 1; while (_curFrame < destinationFrame - 1) bufferNextFrame(); }
int16 ScriptFunctions::sfGetSoundEnergy(int16 argc, int16 *argv) { // This is called while in-game voices are played to animate // mouths when NPCs are talking int result = 0; if (_vm->_mixer->isSoundHandleActive(_audioStreamHandle) && _vm->_soundEnergyArray) { while (_vm->_soundEnergyIndex < _vm->_soundEnergyArray->size()) { SoundEnergyItem *soundEnergyItem = &(*_vm->_soundEnergyArray)[_vm->_soundEnergyIndex]; const Audio::Timestamp ts = _vm->_mixer->getElapsedTime(_audioStreamHandle); if (ts.convertToFramerate(_vm->_soundRate).totalNumberOfFrames() < (int)soundEnergyItem->position) { result = soundEnergyItem->energy; break; } _vm->_soundEnergyIndex++; } if (_vm->_soundEnergyIndex >= _vm->_soundEnergyArray->size()) result = 0; } return result; }
bool QuickTimeDecoder::VideoTrackHandler::seek(const Audio::Timestamp &requestedTime) { uint32 convertedFrames = requestedTime.convertToFramerate(_decoder->_timeScale).totalNumberOfFrames(); for (_curEdit = 0; !atLastEdit(); _curEdit++) if (convertedFrames >= _parent->editList[_curEdit].timeOffset && convertedFrames < _parent->editList[_curEdit].timeOffset + _parent->editList[_curEdit].trackDuration) break; // If we did reach the end of the track, break out if (atLastEdit()) return true; // If this track is in an empty edit, position us at the next non-empty // edit. There's nothing else to do after this. if (_parent->editList[_curEdit].mediaTime == -1) { while (!atLastEdit() && _parent->editList[_curEdit].mediaTime == -1) _curEdit++; if (!atLastEdit()) enterNewEditList(true); return true; } enterNewEditList(false); // One extra check for the end of a track if (atLastEdit()) return true; // Now we're in the edit and need to figure out what frame we need Audio::Timestamp time = requestedTime.convertToFramerate(_parent->timeScale); while (getRateAdjustedFrameTime() < (uint32)time.totalNumberOfFrames()) { _curFrame++; if (_durationOverride >= 0) { _nextFrameStartTime += _durationOverride; _durationOverride = -1; } else { _nextFrameStartTime += getFrameDuration(); } } // All that's left is to figure out what our starting time is going to be // Compare the starting point for the frame to where we need to be _holdNextFrameStartTime = getRateAdjustedFrameTime() != (uint32)time.totalNumberOfFrames(); // If we went past the time, go back a frame. _curFrame before this point is at the frame // that should be displayed. This adjustment ensures it is on the frame before the one that // should be displayed. if (_holdNextFrameStartTime) _curFrame--; if (_reversed) { // Call setReverse again to update setReverse(true); } else { // Handle the keyframe here int32 destinationFrame = _curFrame + 1; assert(destinationFrame < (int32)_parent->frameCount); _curFrame = findKeyFrame(destinationFrame) - 1; while (_curFrame < destinationFrame - 1) bufferNextFrame(); } return true; }