Tertium Organum
2006-Jan-19 14:12 UTC
[Vorbis-dev] re: want to know, how much data will be extracted from every single packet; solved but some issues
ok, ok, i've found the solution to my problem.
if anybody dont mind, i 'll tell, what i have achieve :)
let's see logical vorbis stream (actually i have no stream, coz i have rid
of ogg).
first three packets - identification, comments and codebooks. then goes a
packet, which, as i understood, is just auxiliary for the next one. In addition,
it holds (it can be found via vorbis_packet_blocksize) size of pcm data, that
the next one holds. In general every packet holds part of size of pcm data in
next packet, i.e.:
? ? ? cur = vorbis_packet_blocksize(&m_vorb_info,
&m_packets[cur_packet_num]);
? ? ? if ( cur <= 0 ) ?
? ? ? ?m_packets_real_lengths[cur_packet_num] = 0;
? ? ? else
? ? ? {
? ? ? ?if (prev == 0 )
? ? ? ? prev = cur;
? ? ? if (cur_packet_num > 3 && cur_packet_num < m_packets_number
- 1)
? ? ? {
? ? ? ? m_packets_real_lengths[cur_packet_num] = cur + prev;
? ? ? ? m_data_size += m_packets_real_lengths[cur_packet_num];
? ? ? }
? ? ? else
? ? ? ? m_packets_real_lengths[cur_packet_num] = 0;
? ? ? ?prev = cur;
? ?}
But not so easy. We must begin loop where cur_packet_num > 3 and
cur_packet_num < m_packets_number - 1, because:
- first (aux) after 3 info packets (so it's index will be 3) always has
size of pcm data of 0
- last packet (it's index well be m_packets_number - 1) - size of pcm data
in most cases its impossible to get this way accuratly - because of the how
vorbis handles little packets u will get greater value than actually is.
so, first 4 (if include 3 info packets, as i did) pcm sizes in vector
m_packets_real_lengths are zeros.
in order to get the last value correctly for the last packet we must unpack some
last packets. As i read different mail lists i found metion about the fact that
for unpacking packet X one need unpack packet X - 1 befor.
I honestly tried do this, but in fact works properly only this code:
for (uint32 i = m_packets_number - 6; i < m_packets_number; i++)
{
?if (vorbis_synthesis(&vorb_block,&m_packets[i])==0)
? vorbis_synthesis_blockin(&vorb_dsp_state,&vorb_block);
?int bout = vorbis_synthesis_pcmout(&vorb_dsp_state,NULL);
?if (i == m_packets_number - 1)
?{
? m_packets_real_lengths[i] ?= 2 * m_vorb_info.channels * bout;
? m_data_size += m_packets_real_lengths[i];
?}
?vorbis_synthesis_read(&vorb_dsp_state,bout);
}
exactly m_packets_number - 6 and no more :) i 'm lost in conjectures, why
is this so... but it works.
hah, strange thing, but in code that unpack later fragments of stream into pcm
buffer i consider that for packet X i must have only X-1 and code works too...
PLEASE SOMEBODY TELL ME WHY I MUST UNPACK 5 (!!!) PACKETS BEFORE I CAN PROPERLY
UNPACK THE LAST PACKET AND GET THE ACTUAL SIZE OF PCM DATA IT HOLDS???
