// Programmed by Jedidiah Barber // Released into the public domain #include #include "c_asndfile_virtual.h" sf_count_t c_filelen_hook(void * user_data) { return (sf_count_t) ada_filelen_hook(user_data); } sf_count_t c_seek_hook(sf_count_t offset, int whence, void * user_data) { return (sf_count_t) ada_seek_hook((int64_t) offset, whence, user_data); } sf_count_t c_read_hook(void * ptr, sf_count_t count, void * user_data) { return (sf_count_t) ada_read_hook(ptr, (int64_t) count, user_data); } sf_count_t c_write_hook(const void * ptr, sf_count_t count, void * user_data) { return (sf_count_t) ada_write_hook(ptr, (int64_t) count, user_data); } sf_count_t c_tell_hook(void * user_data) { return (sf_count_t) ada_tell_hook(user_data); } SF_VIRTUAL_IO hooks = { .get_filelen = &c_filelen_hook, .seek = &c_seek_hook, .read = &c_read_hook, .write = &c_write_hook, .tell = &c_tell_hook }; SNDFILE * asf_open_virtual(int mode, Asf_Info * sfinfo, void * user_data) { SF_INFO actual; actual.frames = (sf_count_t)sfinfo->frames; actual.samplerate = sfinfo->samplerate; actual.channels = sfinfo->channels; actual.format = sfinfo->major & sfinfo->minor & sfinfo->endian; actual.sections = sfinfo->sections; actual.seekable = sfinfo->seekable; SNDFILE * result = sf_open_virtual(&hooks, mode, &actual, user_data); if (result == NULL) { return NULL; } sfinfo->frames = (long long)actual.frames; sfinfo->samplerate = actual.samplerate; sfinfo->channels = actual.channels; sfinfo->major = actual.format & SF_FORMAT_TYPEMASK; sfinfo->minor = actual.format & SF_FORMAT_SUBMASK; sfinfo->endian = actual.format & SF_FORMAT_ENDMASK; sfinfo->sections = actual.sections; sfinfo->seekable = actual.seekable; return result; }