Esempio n. 1
0
/*
	Example: AAC, 1024 frames/packet, 2112 frame offset

                                           2112
                                             |
    Absolute frames:  0       1024      2048 |    3072
                      +---------+---------+--|------+---------+---------+
    Packets:          |    0    |    1    |  | 2    |    3    |    4    |
                      +---------+---------+--|------+---------+---------+
    Client frames:  -2112   -1088       -64  |     960						SeekToFrame, TellFrame
                                             |
                                             0

	*   Offset between absolute and client frames is mFrame0Offset.
	*** mFrameMark is in client frames ***

	Examples:
		clientFrame					0		960		1000	1024
		absoluteFrame				2112	3072	3112	3136
		packet						0		0		0		1
		tempFrameMark*				-2112	-2112	-2112	-1088
		mFramesToSkipFollowingSeek	2112	3072	3112	2112
*/
void	CAAudioFile::Seek(SInt64 clientFrame)
{
	if (clientFrame == mFrameMark)
		return; // already there! don't reset converter

	//SInt64 absoluteFrame = clientFrame + mFrame0Offset;
	XThrowIf(mMode != kReading || clientFrame < 0 || !mClientDataFormat.IsPCM(), kExtAudioFileError_InvalidSeek, "seek to frame in audio file");

#if VERBOSE_IO
	SInt64 prevFrameMark = mFrameMark;
#endif

	SInt64 packet;
	packet = FrameToPacket(clientFrame);
	if (packet < 0)
		packet = 0;
	SeekToPacket(packet);
	// this will have backed up mFrameMark to match the beginning of the packet
	mFramesToSkipFollowingSeek = std::max(UInt32(clientFrame - mFrameMark), UInt32(0));
	mFrameMark = clientFrame;

#if VERBOSE_IO
	printf("CAAudioFile::SeekToFrame: frame %qd (from %qd), packet %qd, skip %ld frames\n", mFrameMark, prevFrameMark, packet, mFramesToSkipFollowingSeek);
#endif
}
Esempio n. 2
0
// ////////////////////////////////////////////////////////////////////////////
unsigned int PacketFileReader::GetPacketCount()
{
	if (packet_count_is_known_)
		return(packet_count_);

	FileOffsetSaver    saved_offset(*this);
	unsigned long long packet_offset = packet_offset_;
	unsigned int       packet_count;

	SeekToPacket(std::numeric_limits<unsigned int>::max(), packet_count);

	packet_offset_         = packet_offset;
	packet_count_          = packet_count;
	packet_count_is_known_ = true;

	return(packet_count);
}
Esempio n. 3
0
// ////////////////////////////////////////////////////////////////////////////
bool PacketFileReader::SeekToPacket(unsigned int packet_index)
{
	unsigned int packet_count;

	return(SeekToPacket(packet_index, packet_count));
}