From 049d2a9a337331295b4a2d4ad13061bc73536236 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sun, 2 Jul 2023 21:36:34 +1200 Subject: Initial commit --- src/c_asndfile_virtual.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/c_asndfile_virtual.c (limited to 'src/c_asndfile_virtual.c') diff --git a/src/c_asndfile_virtual.c b/src/c_asndfile_virtual.c new file mode 100644 index 0000000..a7bd941 --- /dev/null +++ b/src/c_asndfile_virtual.c @@ -0,0 +1,71 @@ + + +// 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; +} + + -- cgit