1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************/
12 module iv
.xyph
.vorbisfile
/*is aliced*/;
13 pragma(lib
, "vorbisfile");
15 import core
.stdc
.config
;
16 import core
.stdc
.stdio
;
20 import iv
.xyph
.vorbis
;
23 extern(C
) nothrow @nogc:
26 usize
function (void *ptr
, usize size
, usize nmemb
, void *datasource
) read_func
;
27 int function (void *datasource
, long offset
, int whence
) seek_func
;
28 int function (void *datasource
) close_func
;
29 c_long
function (void *datasource
) tell_func
;
41 struct OggVorbis_File
{
42 void* datasource
; /* Pointer to a FILE *, etc. */
48 /* If the FILE handle isn't seekable (eg, a pipe), only the current stream appears */
53 long* pcmlengths
; /* overloaded to maintain binary compatibility; x2 size, stores both beginning and end values */
57 /* Decoding working state local storage */
60 c_long current_serialno
;
66 ogg_stream_state os
; /* take physical pages, weld into a logical stream of packets */
67 vorbis_dsp_state vd
; /* central working state for the packet->PCM decoder */
68 vorbis_block vb
; /* local working space for packet->PCM decode */
70 ov_callbacks callbacks
;
74 int ov_clear (OggVorbis_File
* vf
);
75 int ov_fopen (const(char)* path
, OggVorbis_File
* vf
);
76 int ov_open (FILE
* f
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
);
77 int ov_open_callbacks (void* datasource
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
, ov_callbacks callbacks
);
79 int ov_test (FILE
* f
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
);
80 int ov_test_callbacks (void* datasource
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
, ov_callbacks callbacks
);
81 int ov_test_open (OggVorbis_File
* vf
);
83 c_long
ov_bitrate (OggVorbis_File
* vf
, int i
);
84 c_long
ov_bitrate_instant (OggVorbis_File
* vf
);
85 c_long
ov_streams (OggVorbis_File
* vf
);
86 c_long
ov_seekable (OggVorbis_File
* vf
);
87 c_long
ov_serialnumber (OggVorbis_File
* vf
, int i
);
89 long ov_raw_total (OggVorbis_File
* vf
, int i
);
90 long ov_pcm_total (OggVorbis_File
* vf
, int i
);
91 double ov_time_total (OggVorbis_File
* vf
, int i
);
93 int ov_raw_seek (OggVorbis_File
* vf
, long pos
);
94 int ov_pcm_seek (OggVorbis_File
* vf
, long pos
);
95 int ov_pcm_seek_page (OggVorbis_File
* vf
, long pos
);
96 int ov_time_seek (OggVorbis_File
* vf
, double pos
);
97 int ov_time_seek_page (OggVorbis_File
* vf
, double pos
);
99 int ov_raw_seek_lap (OggVorbis_File
* vf
, long pos
);
100 int ov_pcm_seek_lap (OggVorbis_File
* vf
, long pos
);
101 int ov_pcm_seek_page_lap (OggVorbis_File
* vf
, long pos
);
102 int ov_time_seek_lap (OggVorbis_File
* vf
, double pos
);
103 int ov_time_seek_page_lap (OggVorbis_File
* vf
, double pos
);
105 long ov_raw_tell (OggVorbis_File
* vf
);
106 long ov_pcm_tell (OggVorbis_File
* vf
);
107 double ov_time_tell (OggVorbis_File
* vf
);
109 vorbis_info
* ov_info (OggVorbis_File
* vf
, int link
);
110 vorbis_comment
* ov_comment (OggVorbis_File
* vf
, int link
);
112 c_long
ov_read_float (OggVorbis_File
* vf
, float*** pcm_channels
, int samples
, int* bitstream
);
113 c_long
ov_read_filter (OggVorbis_File
* vf
, char* buffer
, int length
, int bigendianp
, int word
, int sgned
, int* bitstream
,
114 void function (float** pcm
, c_long channels
, c_long samples
, void* filter_param
) filter
, void* filter_param
);
115 c_long
ov_read (OggVorbis_File
* vf
, void* buffer
, int length
, int bigendianp
, int word
, int sgned
, int* bitstream
);
116 int ov_crosslap (OggVorbis_File
* vf1
, OggVorbis_File
* vf2
);
118 int ov_halfrate (OggVorbis_File
* vf
, int flag
);
119 int ov_halfrate_p (OggVorbis_File
* vf
);
123 usize
libcfile_VorbisRead (void* ptr
, usize byteSize
, usize sizeToRead
, void* datasource
) {
124 return fread(ptr
, byteSize
, sizeToRead
, cast(FILE
*)datasource
);
127 int libcfile_VorbisSeek (void* datasource
, long offset
, int whence
) {
128 return fseek(cast(FILE
*)datasource
, cast(int)offset
, whence
);
131 int libcfile_VorbisClose (void* datasource
) {
132 return fclose(cast(FILE
*)datasource
);
135 c_long
libcfile_VorbisTell (void* datasource
) {
136 return cast(c_long
)ftell(cast(FILE
*)datasource
);
140 // ov_open is rewritten below because of incompatibility between compilers with FILE struct
141 // Using this wrapper, it *should* work exactly as it would in c++. --JoeCoder
142 int ov_open (FILE
* f
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
) {
143 // Fill the ov_callbacks structure
144 ov_callbacks vorbisCallbacks
; // Structure to hold pointers to callback functions
145 vorbisCallbacks
.read_func
= &libcfile_VorbisRead
;
146 vorbisCallbacks
.close_func
= &libcfile_VorbisClose
;
147 vorbisCallbacks
.seek_func
= &libcfile_VorbisSeek
;
148 vorbisCallbacks
.tell_func
= &libcfile_VorbisTell
;
149 return ov_open_callbacks(cast(void*)f
, vf
, initial
, cast(int)ibytes
, vorbisCallbacks
);
152 int ov_open_noclose (FILE
* f
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
) {
153 // Fill the ov_callbacks structure
154 ov_callbacks vorbisCallbacks
; // Structure to hold pointers to callback functions
155 vorbisCallbacks
.read_func
= &libcfile_VorbisRead
;
156 vorbisCallbacks
.close_func
= null;
157 vorbisCallbacks
.seek_func
= &libcfile_VorbisSeek
;
158 vorbisCallbacks
.tell_func
= &libcfile_VorbisTell
;
159 return ov_open_callbacks(cast(void*)f
, vf
, initial
, cast(int)ibytes
, vorbisCallbacks
);
163 int ov_test (FILE
* f
, OggVorbis_File
* vf
, const(char)* initial
, c_long ibytes
) {
164 // Fill the ov_callbacks structure
165 ov_callbacks vorbisCallbacks
; // Structure to hold pointers to callback functions
166 vorbisCallbacks
.read_func
= &libcfile_VorbisRead
;
167 vorbisCallbacks
.close_func
= &libcfile_VorbisClose
;
168 vorbisCallbacks
.seek_func
= &libcfile_VorbisSeek
;
169 vorbisCallbacks
.tell_func
= &libcfile_VorbisTell
;
170 return ov_test_callbacks(cast(void*)f
, vf
, initial
, cast(int)ibytes
, vorbisCallbacks
);