[vorbis-dev] Reading OGG embedded in a pack file
John Morton
jwm at eslnz.co.nz
Mon May 3 23:32:53 PDT 2004
On Tue, 04 May 2004 16:58, Ken Rogoway wrote:
> Michael,
>
> I respect your knowledge and apologize if I am trying to do something that
> is poor application design. Having coded for over 20 years I would like
> to think that I should know better, but I am a bit stumped as to how I can
> have 100+ different OGG files inside a large package file, and then when
> needed go and grab a single OGG file from the package to decode it for
> the SDL_mixer which expects a properly decoded wave buffer. If you have
> some thoughts on how best to approach this I would greatly appreciate your
> sharing them with me.
ogg files can be concatenated together to form one large physical stream
containing several logical streams, and the vorbisfile API has fairly good
support for working with logical streams within a physical stream.
I don't know what sort of package format your're using overall, but what you
could do is store all the vorbis sound fragments concatenated into one ogg
vorbis stream, store that in the main package and have the stream access
callbacks consider the start of the physical stream at it's offset in the
main package, and raise an EOF when it hits the offset for the end of the
physical stream.
You can then go head and treat the ogg/vorbis physical stream block as
seakable, use code like:
if (start_lstream > -1) {
i = 0;
while (i < start_lstream) {
jump_pos += ov_raw_total(&vf, i++);
}
if (ov_raw_seek(&vf, jump_pos) != 0) {
pthread_mutex_unlock(&vf_mutex);
vorbis_eos = TRUE;
goto play_cleanup;
}
}
...to seek to the logical stream you want to play at any given point, and when
decoding, use the way that ov_read increments the 'bitstream' argument when
it hits the end of the current logical stream to know when to stop decoding.
You should be able to do the conventional business of decoding into a PCM
buffer and have SDL_mixer play out of that (and you shouldn't need to decode
the whole song into the buffer before you start playback, either).
Once you get that working, you might want to take a look at the crosslap
related functions, if you're working with a lot of sound effects style of
playback.
I assume you've found the vorbisfile API docs:
http://www.xiph.org/ogg/vorbis/doc/vorbisfile/reference.html
They're not bad, but could do with some tutorials for solving common problems,
as there are a few gotchas that crop up. You might also like to have a look
at the code to my hacked on xmms plugin:
http://savannah.nongnu.org/cgi-bin/viewcvs/vgplay/vgplay/xmms-vorbis-plugin/
It does something fairly similar; it takes files with multiple logical streams
(ie concatenated albums, captured streams) and breaks them out into separate
tracks in the playlist, so you can do as you please with the order.
John
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Vorbis-dev
mailing list