1 ! Copyright (C) 2007 Adam Wendt.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: alien alien.c-types alien.syntax combinators kernel math system ;
8 { [ macosx? ] [ "libmad.0.dylib" ] }
9 { [ unix? ] [ "libmad.so" ] }
10 { [ windows? ] [ "mad.dll" ] }
11 } cond "cdecl" add-library >>
15 TYPEDEF: int mad_fixed_t
16 TYPEDEF: int mad_fixed64hi_t
17 TYPEDEF: uint mad_fixed64lo_t
20 TYPEDEF: int mad_decoder_mode
21 TYPEDEF: int mad_error
22 TYPEDEF: int mad_layer
24 TYPEDEF: int mad_emphasis
28 { "ulong" "fraction" }
39 { "uchar*" "buffend" }
42 { "ulong" "freerate" }
43 { "uchar*" "this_frame" }
44 { "uchar*" "next_frame" }
45 { "mad_bitptr" "ptr" }
46 { "mad_bitptr" "anc_ptr" }
47 { "uchar*" "main_data" }
50 { "mad_error" "error" }
53 C-STRUCT: struct_async
60 { "mad_layer" "layer" }
62 { "int" "mode_extension" }
63 { "mad_emphasis" "emphasis" }
65 { "uint" "samplerate" }
66 { "ushort" "crc_check" }
67 { "ushort" "crc_target" }
69 { "int" "private_bits" }
70 { "mad_timer_t" "duration" }
74 { "mad_header" "header" }
76 { { "mad_fixed_t" 2304 } "sbsample" }
77 { "mad_fixed_t*" "overlap" }
81 { "uint" "samplerate" }
82 { "ushort" "channels" }
84 { { "mad_fixed_t" 2304 } "samples" }
87 : mad_pcm-sample-left ( pcm int -- sample )
88 swap mad_pcm-samples int-nth ;
89 : mad_pcm-sample-right ( pcm int -- sample )
90 1152 + swap mad_pcm-samples int-nth ;
93 { { "mad_fixed_t" 1024 } "filter" }
99 { "mad_stream" "stream" }
100 { "mad_frame" "frame" }
101 { "mad_synth" "synth" }
104 C-STRUCT: mad_decoder
105 { "mad_decoder_mode" "mode" }
107 { "struct_async" "async" }
108 { "struct_sync*" "sync" }
109 { "void*" "cb_data" }
110 { "void*" "input_func" }
111 { "void*" "header_func" }
112 { "void*" "filter_func" }
113 { "void*" "output_func" }
114 { "void*" "error_func" }
115 { "void*" "message_func" }
118 : MAD_F_FRACBITS ( -- number ) 28 ; inline
119 : MAD_F_ONE HEX: 10000000 ;
121 : MAD_DECODER_MODE_SYNC ( -- number ) HEX: 0 ; inline
122 : MAD_DECODER_MODE_ASYNC ( -- number ) HEX: 1 ; inline
124 : MAD_FLOW_CONTINUE ( -- number ) HEX: 0 ; inline
125 : MAD_FLOW_STOP ( -- number ) HEX: 10 ; inline
126 : MAD_FLOW_BREAK ( -- number ) HEX: 11 ; inline
127 : MAD_FLOW_IGNORE ( -- number ) HEX: 20 ; inline
129 : MAD_ERROR_NONE ( -- number ) HEX: 0 ; inline
130 : MAD_ERROR_BUFLEN ( -- number ) HEX: 1 ; inline
131 : MAD_ERROR_BUFPTR ( -- number ) HEX: 2 ; inline
132 : MAD_ERROR_NOMEM ( -- number ) HEX: 31 ; inline
133 : MAD_ERROR_LOSTSYNC ( -- number ) HEX: 101 ; inline
134 : MAD_ERROR_BADLAYER ( -- number ) HEX: 102 ; inline
135 : MAD_ERROR_BADBITRATE ( -- number ) HEX: 103 ; inline
136 : MAD_ERROR_BADSAMPLERATE ( -- number ) HEX: 104 ; inline
137 : MAD_ERROR_BADEMPHASIS ( -- number ) HEX: 105 ; inline
138 : MAD_ERROR_BADCRC ( -- number ) HEX: 201 ; inline
139 : MAD_ERROR_BADBITALLOC ( -- number ) HEX: 211 ; inline
140 : MAD_ERROR_BADSCALEFACTOR ( -- number ) HEX: 221 ; inline
141 : MAD_ERROR_BADMODE ( -- number ) HEX: 222 ; inline
142 : MAD_ERROR_BADFRAMELEN ( -- number ) HEX: 231 ; inline
143 : MAD_ERROR_BADBIGVALUES ( -- number ) HEX: 232 ; inline
144 : MAD_ERROR_BADBLOCKTYPE ( -- number ) HEX: 233 ; inline
145 : MAD_ERROR_BADSCFSI ( -- number ) HEX: 234 ; inline
146 : MAD_ERROR_BADDATAPTR ( -- number ) HEX: 235 ; inline
147 : MAD_ERROR_BADPART3LEN ( -- number ) HEX: 236 ; inline
148 : MAD_ERROR_BADHUFFTABLE ( -- number ) HEX: 237 ; inline
149 : MAD_ERROR_BADHUFFDATA ( -- number ) HEX: 238 ; inline
150 : MAD_ERROR_BADSTEREO ( -- number ) HEX: 239 ; inline
153 FUNCTION: void mad_decoder_init ( mad_decoder* decoder, void* data, void* input_func, void* header_func, void* filter_func, void* output_func, void* error_func, void* message_func ) ;
154 FUNCTION: int mad_decoder_run ( mad_decoder* decoder, mad_decoder_mode mode ) ;
155 FUNCTION: void mad_stream_buffer ( mad_stream* stream, uchar* start, ulong length ) ;