1 /+
2 +            Copyright 2023 – 2024 Aya Partridge
3 + Distributed under the Boost Software License, Version 1.0.
4 +     (See accompanying file LICENSE_1_0.txt or copy at
5 +           http://www.boost.org/LICENSE_1_0.txt)
6 +/
7 module opusfile;
8 
9 import bindbc.opus.config;
10 static if(bindOpusfile):
11 import bindbc.opus.codegen;
12 
13 enum opusfileVersion = (){
14 	version(Opusfile_0_12) return Version(0,12,0);
15 	else static assert(0);
16 }();
17 
18 struct OpusHead;
19 
20 struct OpusTags;
21 
22 struct OpusPictureTag;
23 
24 struct OpusServerInfo;
25 
26 struct OpusFileCallbacks;
27 
28 struct OggOpusFile;
29 
30 enum{
31 	OP_FALSE          = -1,
32 	OP_EOF            = -2,
33 	OP_HOLE           = -3,
34 	OP_EREAD          = -128,
35 	OP_EFAULT         = -129,
36 	OP_EIMPL          = -130,
37 	OP_EINVAL         = -131,
38 	OP_ENOTFORMAT     = -132,
39 	OP_EBADHEADER     = -133,
40 	OP_EVERSION       = -134,
41 	OP_ENOTAUDIO      = -135,
42 	OP_EBADPACKET     = -136,
43 	OP_EBADLINK       = -137,
44 	OP_ENOSEEK        = -138,
45 	OP_EBADTIMESTAMP  = -139,
46 }
47 
48 enum OPUS_CHANNEL_COUNT_MAX = 255;
49 
50 struct OpusHead{
51 	int version_;
52 	int channelCount;
53 	uint preSkip, inputSampleRate;
54 	int outputGain, mappingFamily;
55 	int streamCount, coupledCount;
56 	ubyte[OPUS_CHANNEL_COUNT_MAX] mapping;
57 	
58 	alias channel_count = channelCount;
59 	alias pre_skip = preSkip;
60 	alias input_sample_rate = inputSampleRate;
61 	alias output_gain = outputGain;
62 	alias mapping_family = mappingFamily;
63 	alias stream_count = streamCount;
64 	alias coupled_count = coupledCount;
65 }
66 
67 struct OpusTags{
68 	char** userComments;
69 	int* commentLengths;
70 	int comments;
71 	char* vendor;
72 	
73 	alias user_comments = userComments;
74 	alias comment_lengths = commentLengths;
75 }
76 
77 enum{
78 	OP_PIC_FORMAT_UNKNOWN  = -1,
79 	OP_PIC_FORMAT_URL      =  0,
80 	OP_PIC_FORMAT_JPEG     =  1,
81 	OP_PIC_FORMAT_PNG      =  2,
82 	OP_PIC_FORMAT_GIF      =  3,
83 }
84 
85 struct OpusPictureTag{
86 	int type;
87 	char* mimeType, description;
88 	uint width, height, depth, colours;
89 	uint dataLength;
90 	ubyte* data;
91 	int format;
92 	
93 	alias mime_type = mimeType;
94 	alias colors = colours;
95 	alias data_length = dataLength;
96 }
97 
98 mixin(joinFnBinds((){
99 	FnBind[] ret = [
100 		{q{int}, q{opus_head_parse}, q{OpusHead* head, const(ubyte)* data, size_t len}},
101 		{q{long}, q{opus_granule_sample}, q{const(OpusHead)* head, long gp}},
102 		{q{int}, q{opus_tags_parse}, q{OpusTags* tags, const(ubyte)* data, size_t len}},
103 		{q{int}, q{opus_tags_copy}, q{OpusTags* dst, const(OpusTags)* src}},
104 		{q{void}, q{opus_tags_init}, q{OpusTags* tags}},
105 		{q{int}, q{opus_tags_add}, q{OpusTags* tags, const(char)* tag, const(char)* value}},
106 		{q{int}, q{opus_tags_add_comment}, q{OpusTags* tags, const(char)* comment}},
107 		{q{int}, q{opus_tags_set_binary_suffix}, q{OpusTags* tags, const(ubyte)* _data, int len}},
108 		{q{const(char)*}, q{opus_tags_query}, q{const(OpusTags)* tags, const(char)* tag, int count}},
109 		{q{int}, q{opus_tags_query_count}, q{const(OpusTags)* tags, const(char)* tag}},
110 		{q{const(ubyte)*}, q{opus_tags_get_binary_suffix}, q{const(OpusTags)* tags, int* len}},
111 		{q{int}, q{opus_tags_get_album_gain}, q{const(OpusTags)* tags, int* gainQ8}},
112 		{q{int}, q{opus_tags_get_track_gain}, q{const(OpusTags)* tags, int* gainQ8}},
113 		{q{void}, q{opus_tags_clear}, q{OpusTags* tags}},
114 		{q{int}, q{opus_tagcompare}, q{const(char)* tagName, const(char)* comment}},
115 		{q{int}, q{opus_tagncompare}, q{const(char)* tagName, int tagLen, const(char)* comment}},
116 		{q{int}, q{opus_picture_tag_parse}, q{OpusPictureTag* pic, const(char)* tag}},
117 		{q{void}, q{opus_picture_tag_init}, q{OpusPictureTag* pic}},
118 		{q{void}, q{opus_picture_tag_clear}, q{OpusPictureTag* pic}},
119 	];
120 	return ret;
121 }()));
122 
123 static if(!staticBinding):
124 import bindbc.loader;
125 
126 mixin(makeDynloadFns("Opusfile", makeLibPaths(["opusfile"]), [__MODULE__]));