1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
}
|