Skip to main content

miniaudio/
base.rs

1use miniaudio_sys as sys;
2
3#[inline(always)]
4pub(crate) const fn to_bool32(b: bool) -> sys::ma_bool32 {
5    b as u32 as _
6}
7
8#[inline(always)]
9pub(crate) const fn from_bool32(b32: sys::ma_bool32) -> bool {
10    b32 != 0
11}
12
13#[repr(i32)]
14#[derive(Clone, Copy, PartialEq, Eq)]
15pub enum Error {
16    Generic = sys::MA_ERROR,
17    InvalidArgs = sys::MA_INVALID_ARGS,
18    InvalidOperation = sys::MA_INVALID_OPERATION,
19    OutOfMemory = sys::MA_OUT_OF_MEMORY,
20    OutOfRange = sys::MA_OUT_OF_RANGE,
21    AccessDenied = sys::MA_ACCESS_DENIED,
22    DoesNotExist = sys::MA_DOES_NOT_EXIST,
23    AlreadyExists = sys::MA_ALREADY_EXISTS,
24    TooManyOpenFiles = sys::MA_TOO_MANY_OPEN_FILES,
25    InvalidFile = sys::MA_INVALID_FILE,
26    TooBig = sys::MA_TOO_BIG,
27    PathTooLong = sys::MA_PATH_TOO_LONG,
28    NameTooLong = sys::MA_NAME_TOO_LONG,
29    NotDirectory = sys::MA_NOT_DIRECTORY,
30    IsDirectory = sys::MA_IS_DIRECTORY,
31    DirectoryNotEmpty = sys::MA_DIRECTORY_NOT_EMPTY,
32    EndOfFile = sys::MA_END_OF_FILE,
33    NoSpace = sys::MA_NO_SPACE,
34    Busy = sys::MA_BUSY,
35    IoError = sys::MA_IO_ERROR,
36    Interrupt = sys::MA_INTERRUPT,
37    Unavailable = sys::MA_UNAVAILABLE,
38    AlreadyInUse = sys::MA_ALREADY_IN_USE,
39    BadAddress = sys::MA_BAD_ADDRESS,
40    BadSeek = sys::MA_BAD_SEEK,
41    BadPipe = sys::MA_BAD_PIPE,
42    Deadlock = sys::MA_DEADLOCK,
43    TooManyLinks = sys::MA_TOO_MANY_LINKS,
44    NotImplemented = sys::MA_NOT_IMPLEMENTED,
45    NoMessage = sys::MA_NO_MESSAGE,
46    BadMessage = sys::MA_BAD_MESSAGE,
47    NoDataAvailable = sys::MA_NO_DATA_AVAILABLE,
48    InvalidData = sys::MA_INVALID_DATA,
49    Timeout = sys::MA_TIMEOUT,
50    NoNetwork = sys::MA_NO_NETWORK,
51    NotUnique = sys::MA_NOT_UNIQUE,
52    NotSocket = sys::MA_NOT_SOCKET,
53    NoAddress = sys::MA_NO_ADDRESS,
54    BadProtocol = sys::MA_BAD_PROTOCOL,
55    ProtocolUnavailable = sys::MA_PROTOCOL_UNAVAILABLE,
56    ProtocolNotSupported = sys::MA_PROTOCOL_NOT_SUPPORTED,
57    ProtocolFamilyNotSupported = sys::MA_PROTOCOL_FAMILY_NOT_SUPPORTED,
58    AddressFamilyNotSupported = sys::MA_ADDRESS_FAMILY_NOT_SUPPORTED,
59    SocketNotSupported = sys::MA_SOCKET_NOT_SUPPORTED,
60    ConnectionReset = sys::MA_CONNECTION_RESET,
61    AlreadyConnected = sys::MA_ALREADY_CONNECTED,
62    NotConnected = sys::MA_NOT_CONNECTED,
63    ConnectionRefused = sys::MA_CONNECTION_REFUSED,
64    NoHost = sys::MA_NO_HOST,
65    InProgress = sys::MA_IN_PROGRESS,
66    Cancelled = sys::MA_CANCELLED,
67    MemoryAlreadyMapped = sys::MA_MEMORY_ALREADY_MAPPED,
68    AtEnd = sys::MA_AT_END,
69
70    /* General miniaudio-specific errors. */
71    FormatNotSupported = sys::MA_FORMAT_NOT_SUPPORTED,
72    DeviceTypeNotSupported = sys::MA_DEVICE_TYPE_NOT_SUPPORTED,
73    ShareModeNotSupported = sys::MA_SHARE_MODE_NOT_SUPPORTED,
74    NoBackend = sys::MA_NO_BACKEND,
75    NoDevice = sys::MA_NO_DEVICE,
76    ApiNotFound = sys::MA_API_NOT_FOUND,
77    InvalidDeviceConfig = sys::MA_INVALID_DEVICE_CONFIG,
78
79    /* State errors. */
80    DeviceNotInitialized = sys::MA_DEVICE_NOT_INITIALIZED,
81    DeviceAlreadyInitialized = sys::MA_DEVICE_ALREADY_INITIALIZED,
82    DeviceNotStarted = sys::MA_DEVICE_NOT_STARTED,
83    DeviceNotStopped = sys::MA_DEVICE_NOT_STOPPED,
84
85    /* Operation errors. */
86    FailedToInitBackend = sys::MA_FAILED_TO_INIT_BACKEND,
87    FailedToOpenBackendDevice = sys::MA_FAILED_TO_OPEN_BACKEND_DEVICE,
88    FailedToStartBackendDevice = sys::MA_FAILED_TO_START_BACKEND_DEVICE,
89    FailedToStopBackendDevice = sys::MA_FAILED_TO_STOP_BACKEND_DEVICE,
90}
91
92impl Error {
93    #[inline(always)]
94    pub(crate) const fn is_c_error(c_result: sys::ma_result) -> bool {
95        c_result != sys::MA_SUCCESS as _
96    }
97
98    /// Converts a C result value into a `Result` with `Error`.
99    pub(crate) fn from_c_result(c_result: sys::ma_result) -> Result<(), Error> {
100        if !Self::is_c_error(c_result) {
101            Ok(())
102        } else {
103            Err(Self::from_c_error(c_result))
104        }
105    }
106
107    /// Converts an error from C library's int format into an `Error` enum.
108    pub(crate) fn from_c_error(c_error: sys::ma_result) -> Error {
109        match c_error {
110            sys::MA_INVALID_ARGS => Error::InvalidArgs,
111            sys::MA_INVALID_OPERATION => Error::InvalidOperation,
112            sys::MA_OUT_OF_MEMORY => Error::OutOfMemory,
113            sys::MA_OUT_OF_RANGE => Error::OutOfRange,
114            sys::MA_ACCESS_DENIED => Error::AccessDenied,
115            sys::MA_DOES_NOT_EXIST => Error::DoesNotExist,
116            sys::MA_ALREADY_EXISTS => Error::AlreadyExists,
117            sys::MA_TOO_MANY_OPEN_FILES => Error::TooManyOpenFiles,
118            sys::MA_INVALID_FILE => Error::InvalidFile,
119            sys::MA_TOO_BIG => Error::TooBig,
120            sys::MA_PATH_TOO_LONG => Error::PathTooLong,
121            sys::MA_NAME_TOO_LONG => Error::NameTooLong,
122            sys::MA_NOT_DIRECTORY => Error::NotDirectory,
123            sys::MA_IS_DIRECTORY => Error::IsDirectory,
124            sys::MA_DIRECTORY_NOT_EMPTY => Error::DirectoryNotEmpty,
125            sys::MA_END_OF_FILE => Error::EndOfFile,
126            sys::MA_NO_SPACE => Error::NoSpace,
127            sys::MA_BUSY => Error::Busy,
128            sys::MA_IO_ERROR => Error::IoError,
129            sys::MA_INTERRUPT => Error::Interrupt,
130            sys::MA_UNAVAILABLE => Error::Unavailable,
131            sys::MA_ALREADY_IN_USE => Error::AlreadyInUse,
132            sys::MA_BAD_ADDRESS => Error::BadAddress,
133            sys::MA_BAD_SEEK => Error::BadSeek,
134            sys::MA_BAD_PIPE => Error::BadPipe,
135            sys::MA_DEADLOCK => Error::Deadlock,
136            sys::MA_TOO_MANY_LINKS => Error::TooManyLinks,
137            sys::MA_NOT_IMPLEMENTED => Error::NotImplemented,
138            sys::MA_NO_MESSAGE => Error::NoMessage,
139            sys::MA_BAD_MESSAGE => Error::BadMessage,
140            sys::MA_NO_DATA_AVAILABLE => Error::NoDataAvailable,
141            sys::MA_INVALID_DATA => Error::InvalidData,
142            sys::MA_TIMEOUT => Error::Timeout,
143            sys::MA_NO_NETWORK => Error::NoNetwork,
144            sys::MA_NOT_UNIQUE => Error::NotUnique,
145            sys::MA_NOT_SOCKET => Error::NotSocket,
146            sys::MA_NO_ADDRESS => Error::NoAddress,
147            sys::MA_BAD_PROTOCOL => Error::BadProtocol,
148            sys::MA_PROTOCOL_UNAVAILABLE => Error::ProtocolUnavailable,
149            sys::MA_PROTOCOL_NOT_SUPPORTED => Error::ProtocolNotSupported,
150            sys::MA_PROTOCOL_FAMILY_NOT_SUPPORTED => Error::ProtocolFamilyNotSupported,
151            sys::MA_ADDRESS_FAMILY_NOT_SUPPORTED => Error::AddressFamilyNotSupported,
152            sys::MA_SOCKET_NOT_SUPPORTED => Error::SocketNotSupported,
153            sys::MA_CONNECTION_RESET => Error::ConnectionReset,
154            sys::MA_ALREADY_CONNECTED => Error::AlreadyConnected,
155            sys::MA_NOT_CONNECTED => Error::NotConnected,
156            sys::MA_CONNECTION_REFUSED => Error::ConnectionRefused,
157            sys::MA_NO_HOST => Error::NoHost,
158            sys::MA_IN_PROGRESS => Error::InProgress,
159            sys::MA_CANCELLED => Error::Cancelled,
160            sys::MA_MEMORY_ALREADY_MAPPED => Error::MemoryAlreadyMapped,
161            sys::MA_AT_END => Error::AtEnd,
162
163            /* General miniaudio-specific errors. */
164            sys::MA_FORMAT_NOT_SUPPORTED => Error::FormatNotSupported,
165            sys::MA_DEVICE_TYPE_NOT_SUPPORTED => Error::DeviceTypeNotSupported,
166            sys::MA_SHARE_MODE_NOT_SUPPORTED => Error::ShareModeNotSupported,
167            sys::MA_NO_BACKEND => Error::NoBackend,
168            sys::MA_NO_DEVICE => Error::NoDevice,
169            sys::MA_API_NOT_FOUND => Error::ApiNotFound,
170            sys::MA_INVALID_DEVICE_CONFIG => Error::InvalidDeviceConfig,
171
172            /* State errors. */
173            sys::MA_DEVICE_NOT_INITIALIZED => Error::DeviceNotInitialized,
174            sys::MA_DEVICE_ALREADY_INITIALIZED => Error::DeviceAlreadyInitialized,
175            sys::MA_DEVICE_NOT_STARTED => Error::DeviceNotStarted,
176            sys::MA_DEVICE_NOT_STOPPED => Error::DeviceNotStopped,
177
178            /* Operation errors. */
179            sys::MA_FAILED_TO_INIT_BACKEND => Error::FailedToInitBackend,
180            sys::MA_FAILED_TO_OPEN_BACKEND_DEVICE => Error::FailedToOpenBackendDevice,
181            sys::MA_FAILED_TO_START_BACKEND_DEVICE => Error::FailedToStartBackendDevice,
182            sys::MA_FAILED_TO_STOP_BACKEND_DEVICE => Error::FailedToStopBackendDevice,
183            _ => Error::Generic,
184        }
185    }
186
187    /// Returns the message associated with an error type.
188    pub fn message(self) -> &'static str {
189        match self {
190            Error::Generic => "generic",
191            Error::InvalidArgs => "invalid args",
192            Error::InvalidOperation => "invalid operation",
193            Error::OutOfMemory => "out of memory",
194            Error::OutOfRange => "out of range",
195            Error::AccessDenied => "access denied",
196            Error::DoesNotExist => "does not exist",
197            Error::AlreadyExists => "already exists",
198            Error::TooManyOpenFiles => "too many open files",
199            Error::InvalidFile => "invalid file",
200            Error::TooBig => "too big",
201            Error::PathTooLong => "path too long",
202            Error::NameTooLong => "name too long",
203            Error::NotDirectory => "not directory",
204            Error::IsDirectory => "is directory",
205            Error::DirectoryNotEmpty => "directory not empty",
206            Error::EndOfFile => "end of file",
207            Error::NoSpace => "no space",
208            Error::Busy => "busy",
209            Error::IoError => "io error",
210            Error::Interrupt => "interrupt",
211            Error::Unavailable => "unavailable",
212            Error::AlreadyInUse => "already in use",
213            Error::BadAddress => "bad address",
214            Error::BadSeek => "bad seek",
215            Error::BadPipe => "bad pipe",
216            Error::Deadlock => "deadlock",
217            Error::TooManyLinks => "too many links",
218            Error::NotImplemented => "not implemented",
219            Error::NoMessage => "no message",
220            Error::BadMessage => "bad message",
221            Error::NoDataAvailable => "no data available",
222            Error::InvalidData => "invalid data",
223            Error::Timeout => "timeout",
224            Error::NoNetwork => "no network",
225            Error::NotUnique => "not unique",
226            Error::NotSocket => "not socket",
227            Error::NoAddress => "no address",
228            Error::BadProtocol => "bad protocol",
229            Error::ProtocolUnavailable => "protocol unavailable",
230            Error::ProtocolNotSupported => "protocol not supported",
231            Error::ProtocolFamilyNotSupported => "protocol family not supported",
232            Error::AddressFamilyNotSupported => "address family not supported",
233            Error::SocketNotSupported => "socket not supported",
234            Error::ConnectionReset => "connection reset",
235            Error::AlreadyConnected => "already connected",
236            Error::NotConnected => "not connected",
237            Error::ConnectionRefused => "connection refused",
238            Error::NoHost => "no host",
239            Error::InProgress => "in progress",
240            Error::Cancelled => "cancelled",
241            Error::MemoryAlreadyMapped => "memory already mapped",
242            Error::AtEnd => "at end",
243
244            /* General miniaudio-specific errors. */
245            Error::FormatNotSupported => "format not supported",
246            Error::DeviceTypeNotSupported => "device type not supported",
247            Error::ShareModeNotSupported => "share mode not supported",
248            Error::NoBackend => "no backend",
249            Error::NoDevice => "no device",
250            Error::ApiNotFound => "api not found",
251            Error::InvalidDeviceConfig => "invalid device config",
252
253            /* State errors. */
254            Error::DeviceNotInitialized => "device not initialized",
255            Error::DeviceAlreadyInitialized => "device already initialized",
256            Error::DeviceNotStarted => "device not started",
257            Error::DeviceNotStopped => "device not stopped",
258
259            /* Operation errors. */
260            Error::FailedToInitBackend => "failed to init backend",
261            Error::FailedToOpenBackendDevice => "failed to open backend device",
262            Error::FailedToStartBackendDevice => "failed to start backend device",
263            Error::FailedToStopBackendDevice => "failed to stop backend device",
264        }
265    }
266}
267
268impl std::fmt::Display for Error {
269    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
270        write!(f, "{}", self.message())
271    }
272}
273
274impl std::fmt::Debug for Error {
275    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
276        write!(f, "{}", self.message())
277    }
278}
279
280#[repr(u8)]
281#[derive(Debug, Clone, Copy, PartialEq, Eq)]
282pub enum Channel {
283    None = 0,
284    Mono = 1,
285    FrontLeft = 2,
286    FrontRight = 3,
287    FrontCenter = 4,
288    Lfe = 5,
289    BackLeft = 6,
290    BackRight = 7,
291    FrontLeftCenter = 8,
292    FrontRightCenter = 9,
293    BackCenter = 10,
294    SideLeft = 11,
295    SideRight = 12,
296    TopCenter = 13,
297    TopFrontLeft = 14,
298    TopFrontCenter = 15,
299    TopFrontRight = 16,
300    TopBackLeft = 17,
301    TopBackCenter = 18,
302    TopBackRight = 19,
303    Aux0 = 20,
304    Aux1 = 21,
305    Aux2 = 22,
306    Aux3 = 23,
307    Aux4 = 24,
308    Aux5 = 25,
309    Aux6 = 26,
310    Aux7 = 27,
311    Aux8 = 28,
312    Aux9 = 29,
313    Aux10 = 30,
314    Aux11 = 31,
315    Aux12 = 32,
316    Aux13 = 33,
317    Aux14 = 34,
318    Aux15 = 35,
319    Aux16 = 36,
320    Aux17 = 37,
321    Aux18 = 38,
322    Aux19 = 39,
323    Aux20 = 40,
324    Aux21 = 41,
325    Aux22 = 42,
326    Aux23 = 43,
327    Aux24 = 44,
328    Aux25 = 45,
329    Aux26 = 46,
330    Aux27 = 47,
331    Aux28 = 48,
332    Aux29 = 49,
333    Aux30 = 50,
334    Aux31 = 51,
335}
336impl_from_c!(Channel, sys::ma_channel);
337
338impl Channel {
339    /// The default left channel.
340    pub const LEFT: Self = Self::FrontLeft;
341    /// The default right channel.
342    pub const RIGHT: Self = Self::FrontRight;
343    /// The number of channels.
344    pub const COUNT: usize = sys::MA_CHANNEL_POSITION_COUNT as usize;
345}
346
347impl Default for Channel {
348    fn default() -> Self {
349        Self::None
350    }
351}
352
353#[repr(C)]
354#[derive(Debug, Clone, Copy, PartialEq, Eq)]
355pub enum StreamFormat {
356    PCM = sys::ma_stream_format_pcm as _,
357}
358
359impl Default for StreamFormat {
360    fn default() -> Self {
361        Self::PCM
362    }
363}
364
365#[repr(C)]
366#[derive(Debug, Clone, Copy, PartialEq, Eq)]
367pub enum StreamLayout {
368    Interleaved = sys::ma_stream_layout_interleaved as _,
369    Deinterleaved = sys::ma_stream_layout_deinterleaved as _,
370}
371
372impl Default for StreamLayout {
373    fn default() -> Self {
374        Self::Interleaved
375    }
376}
377
378#[repr(C)]
379#[derive(Debug, Clone, Copy, PartialEq, Eq)]
380pub enum DitherMode {
381    None = sys::ma_dither_mode_none as _,
382    Rectangle = sys::ma_dither_mode_rectangle as _,
383    Triangle = sys::ma_dither_mode_triangle as _,
384}
385
386impl Default for DitherMode {
387    fn default() -> Self {
388        Self::None
389    }
390}
391
392#[repr(C)]
393#[derive(Debug, Clone, Copy, PartialEq, Eq)]
394pub enum Format {
395    Unknown = sys::ma_format_unknown as _,
396    U8 = sys::ma_format_u8 as _,
397    S16 = sys::ma_format_s16 as _,
398    S24 = sys::ma_format_s24 as _,
399    S32 = sys::ma_format_s32 as _,
400    F32 = sys::ma_format_f32 as _,
401}
402impl_from_c!(Format, sys::ma_format);
403
404impl Format {
405    /// Return sthe number of stream formats available.
406    pub const fn count() -> usize {
407        sys::ma_format_count as usize
408    }
409
410    /// The size of one sample in this format in bytes.
411    pub fn size_in_bytes(self) -> usize {
412        match self {
413            Self::Unknown => 0,
414            Self::U8 => 1,
415            Self::S16 => 2,
416            Self::S24 => 3,
417            Self::S32 => 4,
418            Self::F32 => 4,
419        }
420    }
421}
422
423impl Default for Format {
424    fn default() -> Self {
425        Self::Unknown
426    }
427}
428
429#[repr(C)]
430#[derive(Debug, Clone, Copy, PartialEq, Eq)]
431pub enum ChannelMixMode {
432    /// Simple averaging based on the plane(s) the channel is sitting on.
433    Rectangular = sys::ma_channel_mix_mode_rectangular as _,
434    /// Drop excess channels; zeroed out extra channels.
435    Simple = sys::ma_channel_mix_mode_simple as _,
436    /// Use custom weights specified in `ChannelRouterConfig`.
437    CustomWeights = sys::ma_channel_mix_mode_custom_weights as _,
438}
439impl_from_c!(ChannelMixMode, sys::ma_channel_mix_mode);
440
441impl ChannelMixMode {
442    pub const PLANAR_BLEND: Self = Self::Rectangular;
443    pub const DEFAULT: Self = Self::PLANAR_BLEND;
444}
445
446impl Default for ChannelMixMode {
447    fn default() -> Self {
448        Self::DEFAULT
449    }
450}
451
452#[repr(C)]
453#[derive(Debug, Clone, Copy, PartialEq, Eq)]
454pub enum StandardChannelMap {
455    Microsoft = sys::ma_standard_channel_map_microsoft as _,
456    Alsa = sys::ma_standard_channel_map_alsa as _,
457    /// Based on AIFF.
458    Rfc3551 = sys::ma_standard_channel_map_rfc3551 as _,
459    Flac = sys::ma_standard_channel_map_flac as _,
460    Vorbis = sys::ma_standard_channel_map_vorbis as _,
461    /// FreeBSD's sound(4).
462    Sound4 = sys::ma_standard_channel_map_sound4 as _,
463    /// https://www.sndio.org/tips.html
464    Sndio = sys::ma_standard_channel_map_sndio as _,
465}
466impl_from_c!(StandardChannelMap, sys::ma_standard_channel_map);
467
468impl StandardChannelMap {
469    /// https://webaudio.github.io/web-audio-api/#ChannelOrdering.
470    /// Only 1, 2, 4 and 6 channels are defined, but can fill in the gaps with logical assumptions.
471    pub const WEBAUDIO: Self = Self::Flac;
472    pub const DEFAULT: Self = Self::Microsoft;
473}
474
475impl Default for StandardChannelMap {
476    fn default() -> Self {
477        Self::DEFAULT
478    }
479}
480
481#[repr(C)]
482#[derive(Debug, Clone, Copy, PartialEq, Eq)]
483pub enum PerformanceProfile {
484    LowLatency = sys::ma_performance_profile_low_latency as _,
485    Conservative = sys::ma_performance_profile_conservative as _,
486}
487impl_from_c!(PerformanceProfile, sys::ma_performance_profile);
488
489impl Default for PerformanceProfile {
490    fn default() -> Self {
491        Self::LowLatency
492    }
493}
494
495// Standard Sample Rates:
496pub const SAMPLE_RATE_8000: u32 = sys::MA_SAMPLE_RATE_8000;
497pub const SAMPLE_RATE_11025: u32 = sys::MA_SAMPLE_RATE_11025;
498pub const SAMPLE_RATE_16000: u32 = sys::MA_SAMPLE_RATE_16000;
499pub const SAMPLE_RATE_22050: u32 = sys::MA_SAMPLE_RATE_22050;
500pub const SAMPLE_RATE_24000: u32 = sys::MA_SAMPLE_RATE_24000;
501pub const SAMPLE_RATE_32000: u32 = sys::MA_SAMPLE_RATE_32000;
502pub const SAMPLE_RATE_44100: u32 = sys::MA_SAMPLE_RATE_44100;
503pub const SAMPLE_RATE_48000: u32 = sys::MA_SAMPLE_RATE_48000;
504pub const SAMPLE_RATE_88200: u32 = sys::MA_SAMPLE_RATE_88200;
505pub const SAMPLE_RATE_96000: u32 = sys::MA_SAMPLE_RATE_96000;
506pub const SAMPLE_RATE_176400: u32 = sys::MA_SAMPLE_RATE_176400;
507pub const SAMPLE_RATE_192000: u32 = sys::MA_SAMPLE_RATE_192000;
508pub const SAMPLE_RATE_352800: u32 = sys::MA_SAMPLE_RATE_352800;
509pub const SAMPLE_RATE_384000: u32 = sys::MA_SAMPLE_RATE_384000;
510
511pub const MIN_SAMPLE_RATE: u32 = SAMPLE_RATE_8000;
512pub const MAX_SAMPLE_RATE: u32 = SAMPLE_RATE_384000;
513
514/// Minimum number of channels in a channel map.
515pub const MIN_CHANNELS: usize = sys::MA_MIN_CHANNELS as usize;
516
517/// Maximum number of channels in a channel map.
518pub const MAX_CHANNELS: usize = sys::MA_MAX_CHANNELS as usize;
519
520pub const MAX_FILTER_ORDER: usize = sys::MA_MAX_FILTER_ORDER as _;