summaryrefslogtreecommitdiff
path: root/src/c_asndfile_virtual.c
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2023-07-02 21:36:34 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2023-07-02 21:36:34 +1200
commit049d2a9a337331295b4a2d4ad13061bc73536236 (patch)
treec360b2ce05f91d070c14dad7a3691c1435df7df7 /src/c_asndfile_virtual.c
Initial commit
Diffstat (limited to 'src/c_asndfile_virtual.c')
-rw-r--r--src/c_asndfile_virtual.c71
1 files changed, 71 insertions, 0 deletions
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 <sndfile.h>
+#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;
+}
+
+