Re: [AD] Audio plugin function names |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Sunday 05 October 2008 01:12:34 pm Thomas Fjellstrom wrote:
> With vorbis and ogg you CAN pass in read/write functions just fine, so I
> don't see the likeness. sndfile has a hack that somehow bypasses its
> incomplete fd handler..
I'm not sure what the issue is. sf_open_virtual takes a pointer to a struct
that holds function pointers. The functions include read/write functions..
static sf_count_t snd_get_filelen(void *user_data)
{
MemDataInfo *data = (MemDataInfo*)user_data;
return data->Length;
}
static sf_count_t snd_seek(sf_count_t offset, int whence, void *user_data)
{
...
}
static sf_count_t snd_read(void *ptr, sf_count_t count, void *user_data)
{
...
}
static sf_count_t snd_write(const void *ptr, sf_count_t count, void
*user_data)
{
...
}
static sf_count_t snd_tell(void *user_data)
{
MemDataInfo *data = (MemDataInfo*)user_data;
return data->Pos;
}
static SF_VIRTUAL_IO sndMemIO = {
snd_get_filelen,
snd_seek,
snd_read,
snd_write,
snd_tell
};
...
SNDFILE *sndFile = sf_open_virtual(&sndMemIO, SFM_READ, &sndInfo, data);
...
sf_close(sndFile);
And it works just fine. VorbisFile is nearly identical, except it doesn't have
get_filelen, has a close function, the function prototypes are
ever-so-slightly different, and the struct is not passed by pointer. Granted,
the internals could be a mess, but then so were APEG's custom IO callbacks
(and could still be considered as so), and I'm sure Allegro's PACKFILE
callbacks were, too. They still work just fine, though.