alto/al/
format.rs

1use std::ops::{Deref, DerefMut};
2
3use ::{AltoError, AltoResult};
4use sys;
5use alc::*;
6use al::*;
7use ext;
8
9
10/// Audio formats supported by OpenAL.
11#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
12pub enum Format {
13	Standard(StandardFormat),
14	ExtALaw(ExtALawFormat),
15	ExtBFormat(ExtBFormat),
16	ExtDouble(ExtDoubleFormat),
17	ExtFloat32(ExtFloat32Format),
18	ExtIma4(ExtIma4Format),
19	ExtMcFormats(ExtMcFormat),
20	ExtMuLaw(ExtMuLawFormat),
21	ExtMuLawBFormat(ExtMuLawBFormat),
22	ExtMuLawMcFormats(ExtMuLawMcFormat),
23	SoftMsadpcm(SoftMsadpcmFormat),
24}
25
26
27/// Standard formats defined in the base specification.
28#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
29pub enum StandardFormat {
30	/// `AL_FORMAT_MONO8`
31	MonoU8,
32	/// `AL_FORMAT_MONO16`
33	MonoI16,
34	/// `AL_FORMAT_STEREO8`
35	StereoU8,
36	/// `AL_FORMAT_STEREO16`
37	StereoI16,
38}
39
40
41/// Formats provided by `AL_EXT_ALAW`.
42#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
43pub enum ExtALawFormat {
44	/// `AL_FORMAT_MONO_ALAW_EXT`
45	Mono,
46	/// `AL_FORMAT_STEREO_ALAW_EXT`
47	Stereo,
48}
49
50
51/// Formats provided by `AL_EXT_BFORMAT`.
52#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
53pub enum ExtBFormat {
54	/// `AL_FORMAT_BFORMAT2D_8`
55	B2DU8,
56	/// `AL_FORMAT_BFORMAT2D_16`
57	B2DI16,
58	/// `AL_FORMAT_BFORMAT2D_FLOAT32`
59	B2DF32,
60	/// `AL_FORMAT_BFORMAT3D_8`
61	B3DU8,
62	/// `AL_FORMAT_BFORMAT3D_16`
63	B3DI16,
64	/// `AL_FORMAT_BFORMAT3D_FLOAT32`
65	B3DF32,
66}
67
68
69/// Formats provided by `AL_EXT_double`.
70#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
71pub enum ExtDoubleFormat {
72	/// `AL_FORMAT_MONO_DOUBLE_EXT`
73	Mono,
74	/// `AL_FORMAT_STEREO_DOUBLE_EXT`
75	Stereo,
76}
77
78
79/// Formats provided by `AL_EXT_float32`.
80#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
81pub enum ExtFloat32Format {
82	/// `AL_FORMAT_MONO_FLOAT32`
83	Mono,
84	/// `AL_FORMAT_STEREO_FLOAT32`
85	Stereo,
86}
87
88
89/// Formats provided by `AL_EXT_IMA4`.
90#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
91pub enum ExtIma4Format {
92	/// `AL_FORMAT_MONO_IMA4`
93	Mono,
94	/// `AL_FORMAT_STEREO_IMA4`
95	Stereo,
96}
97
98
99/// Formats provided by `AL_EXT_MCFORMATS`.
100#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
101pub enum ExtMcFormat {
102	/// `AL_FORMAT_QUAD8`
103	QuadU8,
104	/// `AL_FORMAT_QUAD16`
105	QuadI16,
106	/// `AL_FORMAT_QUAD32`
107	QuadF32,
108	/// `AL_FORMAT_REAR8`
109	RearU8,
110	/// `AL_FORMAT_REAR16`
111	RearI16,
112	/// `AL_FORMAT_REAR32`
113	RearF32,
114	/// `AL_FORMAT_51CHN8`
115	Mc51ChnU8,
116	/// `AL_FORMAT_51CHN16`
117	Mc51ChnI16,
118	/// `AL_FORMAT_51CHN32`
119	Mc51ChnF32,
120	/// `AL_FORMAT_61CHN8`
121	Mc61ChnU8,
122	/// `AL_FORMAT_61CHN16`
123	Mc61ChnI16,
124	/// `AL_FORMAT_61CHN32`
125	Mc61ChnF32,
126	/// `AL_FORMAT_71CHN8`
127	Mc71ChnU8,
128	/// `AL_FORMAT_71CHN16`
129	Mc71ChnI16,
130	/// `AL_FORMAT_71CHN32`
131	Mc71ChnF32,
132}
133
134
135/// Formats provided by `AL_EXT_MULAW`.
136#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
137pub enum ExtMuLawFormat {
138	/// `AL_FORMAT_MONO_MULAW_EXT`
139	Mono,
140	/// `AL_FORMAT_STEREO_MULAW_EXT`
141	Stereo,
142}
143
144
145/// Formats provided by `AL_EXT_MULAW_BFORMAT`.
146#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
147pub enum ExtMuLawBFormat {
148	/// `AL_FORMAT_BFORMAT2D_MULAW`
149	B2D,
150	/// `AL_FORMAT_BFORMAT3D_MULAW`
151	B3D,
152}
153
154
155/// Formats provided by `AL_EXT_MULAW_MCFORMATS`.
156#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
157pub enum ExtMuLawMcFormat {
158	/// `AL_FORMAT_MONO_MULAW`
159	Mono,
160	/// `AL_FORMAT_STEREO_MULAW`
161	Stereo,
162	/// `AL_FORMAT_QUAD_MULAW`
163	Quad,
164	/// `AL_FORMAT_REAR_MULAW`
165	Rear,
166	/// `AL_FORMAT_51CHN_MULAW`
167	Mc51Chn,
168	/// `AL_FORMAT_61CHN_MULAW`
169	Mc61Chn,
170	/// `AL_FORMAT_71CHN_MULAW`
171	Mc71Chn,
172}
173
174
175/// Formats provided by `AL_SOFT_MSADPCM`.
176#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
177pub enum SoftMsadpcmFormat {
178	/// `AL_FORMAT_MONO_MSADPCM_SOFT`
179	Mono,
180	/// `AL_FORMAT_STEREO_MSADPCM_SOFT`
181	Stereo,
182}
183
184
185/// Implemented by structs that represent a frame of audio samples.
186/// A sample frame is a grouping of audio samples from each channel
187/// of an output format.
188pub unsafe trait SampleFrame: Copy + 'static {
189	/// Underlying sample type.
190	type Sample: Copy;
191
192
193	/// Length of the frame in samples.
194	fn len() -> usize;
195	/// The exact format described by this struct.
196	fn format() -> Format;
197}
198
199
200/// Implemented for sample frames specified by the base standard.
201pub unsafe trait StandardFrame: SampleFrame { }
202
203
204/// Implemented for types that represent a shared buffer of audio data.
205pub unsafe trait AsBufferData<F: SampleFrame> {
206	#[doc(hidden)]
207	fn as_buffer_data(&self) -> (*const sys::ALvoid, usize);
208}
209
210
211/// Implemented for types that represent a mutable buffer of audio data.
212pub unsafe trait AsBufferDataMut<F: SampleFrame> {
213	#[doc(hidden)]
214	fn as_buffer_data_mut(&mut self) -> (*mut sys::ALvoid, usize);
215}
216
217
218#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
219#[repr(C)]
220pub struct ALawSample(pub u8);
221#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
222#[repr(C)]
223pub struct MuLawSample(pub u8);
224
225
226#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
227#[repr(C)]
228pub struct Mono<S: Copy> {
229	pub center: S,
230}
231
232
233#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
234#[repr(C)]
235pub struct Stereo<S: Copy> {
236	pub left: S,
237	pub right: S,
238}
239
240
241#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
242#[repr(C)]
243pub struct McRear<S: Copy> {
244	pub rear: S,
245}
246
247
248#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
249#[repr(C)]
250pub struct McQuad<S: Copy> {
251	pub front_left: S,
252	pub front_right: S,
253	pub back_left: S,
254	pub back_right: S,
255}
256
257
258#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
259#[repr(C)]
260pub struct Mc51Chn<S: Copy> {
261	pub front_left: S,
262	pub front_right: S,
263	pub front_center: S,
264	pub low_freq: S,
265	pub back_left: S,
266	pub back_right: S,
267}
268
269
270#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
271#[repr(C)]
272pub struct Mc61Chn<S: Copy> {
273	pub front_left: S,
274	pub front_right: S,
275	pub front_center: S,
276	pub low_freq: S,
277	pub back_left: S,
278	pub back_right: S,
279	pub back_center: S,
280}
281
282
283#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
284#[repr(C)]
285pub struct Mc71Chn<S: Copy> {
286	pub front_left: S,
287	pub front_right: S,
288	pub front_center: S,
289	pub low_freq: S,
290	pub back_left: S,
291	pub back_right: S,
292	pub side_left: S,
293	pub side_right: S,
294}
295
296
297#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
298#[repr(C)]
299pub struct BFormat2D<S: Copy> {
300	pub w: S,
301	pub x: S,
302	pub y: S,
303}
304
305
306#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
307#[repr(C)]
308pub struct BFormat3D<S: Copy> {
309	pub w: S,
310	pub x: S,
311	pub y: S,
312	pub z: S,
313}
314
315
316impl Format {
317	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
318		match self {
319			Format::Standard(f) => Ok(f.into_raw()),
320			Format::ExtALaw(f) => f.into_raw(ctx),
321			Format::ExtBFormat(f) => f.into_raw(ctx),
322			Format::ExtDouble(f) => f.into_raw(ctx),
323			Format::ExtFloat32(f) => f.into_raw(ctx),
324			Format::ExtIma4(f) => f.into_raw(ctx),
325			Format::ExtMcFormats(f) => f.into_raw(ctx),
326			Format::ExtMuLaw(f) => f.into_raw(ctx),
327			Format::ExtMuLawBFormat(f) => f.into_raw(ctx),
328			Format::ExtMuLawMcFormats(f) => f.into_raw(ctx),
329			Format::SoftMsadpcm(f) => f.into_raw(ctx),
330		}
331	}
332}
333
334
335impl StandardFormat {
336	pub fn into_raw(self) -> sys::ALint {
337		match self {
338			StandardFormat::MonoU8 => sys::AL_FORMAT_MONO8,
339			StandardFormat::MonoI16 => sys::AL_FORMAT_MONO16,
340			StandardFormat::StereoU8 => sys::AL_FORMAT_STEREO8,
341			StandardFormat::StereoI16 => sys::AL_FORMAT_STEREO16,
342		}
343	}
344}
345
346
347impl ExtALawFormat {
348	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
349		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
350			ExtALawFormat::Mono => Ok(ctx.0.exts.AL_EXT_ALAW()?.AL_FORMAT_MONO_ALAW_EXT?),
351			ExtALawFormat::Stereo => Ok(ctx.0.exts.AL_EXT_ALAW()?.AL_FORMAT_STEREO_ALAW_EXT?),
352		})
353	}
354}
355
356
357impl ExtBFormat {
358	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
359		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
360			ExtBFormat::B2DU8 => Ok(ctx.0.exts.AL_EXT_BFORMAT()?.AL_FORMAT_BFORMAT2D_8?),
361			ExtBFormat::B2DI16 => Ok(ctx.0.exts.AL_EXT_BFORMAT()?.AL_FORMAT_BFORMAT2D_16?),
362			ExtBFormat::B2DF32 => Ok(ctx.0.exts.AL_EXT_BFORMAT()?.AL_FORMAT_BFORMAT2D_FLOAT32?),
363			ExtBFormat::B3DU8 => Ok(ctx.0.exts.AL_EXT_BFORMAT()?.AL_FORMAT_BFORMAT3D_8?),
364			ExtBFormat::B3DI16 => Ok(ctx.0.exts.AL_EXT_BFORMAT()?.AL_FORMAT_BFORMAT3D_16?),
365			ExtBFormat::B3DF32 => Ok(ctx.0.exts.AL_EXT_BFORMAT()?.AL_FORMAT_BFORMAT3D_FLOAT32?),
366		})
367	}
368}
369
370
371impl ExtDoubleFormat {
372	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
373		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
374			ExtDoubleFormat::Mono => Ok(ctx.0.exts.AL_EXT_double()?.AL_FORMAT_MONO_DOUBLE_EXT?),
375			ExtDoubleFormat::Stereo => Ok(ctx.0.exts.AL_EXT_double()?.AL_FORMAT_STEREO_DOUBLE_EXT?),
376		})
377	}
378}
379
380
381impl ExtFloat32Format {
382	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
383		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
384			ExtFloat32Format::Mono => Ok(ctx.0.exts.AL_EXT_float32()?.AL_FORMAT_MONO_FLOAT32?),
385			ExtFloat32Format::Stereo => Ok(ctx.0.exts.AL_EXT_float32()?.AL_FORMAT_STEREO_FLOAT32?),
386		})
387	}
388}
389
390
391impl ExtIma4Format {
392	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
393		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
394			ExtIma4Format::Mono => Ok(ctx.0.exts.AL_EXT_IMA4()?.AL_FORMAT_MONO_IMA4?),
395			ExtIma4Format::Stereo => Ok(ctx.0.exts.AL_EXT_IMA4()?.AL_FORMAT_STEREO_IMA4?),
396		})
397	}
398}
399
400
401impl ExtMcFormat {
402	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
403		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
404			ExtMcFormat::QuadU8 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_QUAD8?),
405			ExtMcFormat::QuadI16 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_QUAD16?),
406			ExtMcFormat::QuadF32 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_QUAD32?),
407			ExtMcFormat::RearU8 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_REAR8?),
408			ExtMcFormat::RearI16 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_REAR16?),
409			ExtMcFormat::RearF32 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_REAR32?),
410			ExtMcFormat::Mc51ChnU8 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_51CHN8?),
411			ExtMcFormat::Mc51ChnI16 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_51CHN16?),
412			ExtMcFormat::Mc51ChnF32 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_51CHN32?),
413			ExtMcFormat::Mc61ChnU8 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_61CHN8?),
414			ExtMcFormat::Mc61ChnI16 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_61CHN16?),
415			ExtMcFormat::Mc61ChnF32 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_61CHN32?),
416			ExtMcFormat::Mc71ChnU8 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_71CHN8?),
417			ExtMcFormat::Mc71ChnI16 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_71CHN16?),
418			ExtMcFormat::Mc71ChnF32 => Ok(ctx.0.exts.AL_EXT_MCFORMATS()?.AL_FORMAT_71CHN32?),
419		})
420	}
421}
422
423
424impl ExtMuLawFormat {
425	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
426		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
427			ExtMuLawFormat::Mono => Ok(ctx.0.exts.AL_EXT_MULAW()?.AL_FORMAT_MONO_MULAW_EXT?),
428			ExtMuLawFormat::Stereo => Ok(ctx.0.exts.AL_EXT_MULAW()?.AL_FORMAT_STEREO_MULAW_EXT?),
429		})
430	}
431}
432
433
434impl ExtMuLawBFormat {
435	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
436		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
437			ExtMuLawBFormat::B2D => Ok(ctx.0.exts.AL_EXT_MULAW_BFORMAT()?.AL_FORMAT_BFORMAT2D_MULAW?),
438			ExtMuLawBFormat::B3D => Ok(ctx.0.exts.AL_EXT_MULAW_BFORMAT()?.AL_FORMAT_BFORMAT3D_MULAW?),
439		})
440	}
441}
442
443
444impl ExtMuLawMcFormat {
445	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
446		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
447			ExtMuLawMcFormat::Mono => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_MONO_MULAW?),
448			ExtMuLawMcFormat::Stereo => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_STEREO_MULAW?),
449			ExtMuLawMcFormat::Quad => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_QUAD_MULAW?),
450			ExtMuLawMcFormat::Rear => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_REAR_MULAW?),
451			ExtMuLawMcFormat::Mc51Chn => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_51CHN_MULAW?),
452			ExtMuLawMcFormat::Mc61Chn => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_61CHN_MULAW?),
453			ExtMuLawMcFormat::Mc71Chn => Ok(ctx.0.exts.AL_EXT_MULAW_MCFORMATS()?.AL_FORMAT_71CHN_MULAW?),
454		})
455	}
456}
457
458
459impl SoftMsadpcmFormat {
460	pub fn into_raw(self, ctx: Option<&Context>) -> AltoResult<sys::ALint> {
461		ctx.ok_or(AltoError::ExtensionNotPresent).and_then(|ctx| match self {
462			SoftMsadpcmFormat::Mono => Ok(ctx.0.exts.AL_SOFT_MSADPCM()?.AL_FORMAT_MONO_MSADPCM_SOFT?),
463			SoftMsadpcmFormat::Stereo => Ok(ctx.0.exts.AL_SOFT_MSADPCM()?.AL_FORMAT_STEREO_MSADPCM_SOFT?),
464		})
465	}
466}
467
468
469unsafe impl SampleFrame for Mono<u8> {
470	type Sample = u8;
471
472	#[inline] fn len() -> usize { 1 }
473	#[inline] fn format() -> Format { Format::Standard(StandardFormat::MonoU8) }
474}
475unsafe impl SampleFrame for Mono<i16> {
476	type Sample = i16;
477
478	#[inline] fn len() -> usize { 1 }
479	#[inline] fn format() -> Format { Format::Standard(StandardFormat::MonoI16) }
480}
481unsafe impl SampleFrame for Mono<f32> {
482	type Sample = f32;
483
484	#[inline] fn len() -> usize { 1 }
485	#[inline] fn format() -> Format { Format::ExtFloat32(ExtFloat32Format::Mono) }
486}
487unsafe impl SampleFrame for Mono<f64> {
488	type Sample = f64;
489
490	#[inline] fn len() -> usize { 1 }
491	#[inline] fn format() -> Format { Format::ExtDouble(ExtDoubleFormat::Mono) }
492}
493unsafe impl SampleFrame for Mono<ALawSample> {
494	type Sample = ALawSample;
495
496	#[inline] fn len() -> usize { 1 }
497	#[inline] fn format() -> Format { Format::ExtALaw(ExtALawFormat::Mono) }
498}
499unsafe impl SampleFrame for Mono<MuLawSample> {
500	type Sample = MuLawSample;
501
502	#[inline] fn len() -> usize { 1 }
503	#[inline] fn format() -> Format { Format::ExtMuLaw(ExtMuLawFormat::Mono) }
504}
505
506
507unsafe impl SampleFrame for Stereo<u8> {
508	type Sample = u8;
509
510	#[inline] fn len() -> usize { 2 }
511	#[inline] fn format() -> Format { Format::Standard(StandardFormat::StereoU8) }
512}
513unsafe impl SampleFrame for Stereo<i16> {
514	type Sample = i16;
515
516	#[inline] fn len() -> usize { 2 }
517	#[inline] fn format() -> Format { Format::Standard(StandardFormat::StereoI16) }
518}
519unsafe impl SampleFrame for Stereo<f32> {
520	type Sample = f32;
521
522	#[inline] fn len() -> usize { 2 }
523	#[inline] fn format() -> Format { Format::ExtFloat32(ExtFloat32Format::Stereo) }
524}
525unsafe impl SampleFrame for Stereo<f64> {
526	type Sample = f64;
527
528	#[inline] fn len() -> usize { 2 }
529	#[inline] fn format() -> Format { Format::ExtDouble(ExtDoubleFormat::Stereo) }
530}
531unsafe impl SampleFrame for Stereo<ALawSample> {
532	type Sample = ALawSample;
533
534	#[inline] fn len() -> usize { 2 }
535	#[inline] fn format() -> Format { Format::ExtALaw(ExtALawFormat::Stereo) }
536}
537unsafe impl SampleFrame for Stereo<MuLawSample> {
538	type Sample = MuLawSample;
539
540	#[inline] fn len() -> usize { 2 }
541	#[inline] fn format() -> Format { Format::ExtMuLaw(ExtMuLawFormat::Stereo) }
542}
543
544
545unsafe impl SampleFrame for McRear<u8> {
546	type Sample = u8;
547
548	#[inline] fn len() -> usize { 1 }
549	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::RearU8) }
550}
551unsafe impl SampleFrame for McRear<i16> {
552	type Sample = i16;
553
554	#[inline] fn len() -> usize { 1 }
555	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::RearI16)  }
556}
557unsafe impl SampleFrame for McRear<f32> {
558	type Sample = f32;
559
560	#[inline] fn len() -> usize { 1 }
561	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::RearF32) }
562}
563unsafe impl SampleFrame for McRear<MuLawSample> {
564	type Sample = MuLawSample;
565
566	#[inline] fn len() -> usize { 1 }
567	#[inline] fn format() -> Format { Format::ExtMuLawMcFormats(ExtMuLawMcFormat::Rear) }
568}
569
570
571unsafe impl SampleFrame for McQuad<u8> {
572	type Sample = u8;
573
574	#[inline] fn len() -> usize { 4 }
575	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::QuadU8) }
576}
577unsafe impl SampleFrame for McQuad<i16> {
578	type Sample = i16;
579
580	#[inline] fn len() -> usize { 4 }
581	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::QuadI16)  }
582}
583unsafe impl SampleFrame for McQuad<f32> {
584	type Sample = f32;
585
586	#[inline] fn len() -> usize { 4 }
587	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::QuadF32) }
588}
589unsafe impl SampleFrame for McQuad<MuLawSample> {
590	type Sample = MuLawSample;
591
592	#[inline] fn len() -> usize { 4 }
593	#[inline] fn format() -> Format { Format::ExtMuLawMcFormats(ExtMuLawMcFormat::Quad) }
594}
595
596
597unsafe impl SampleFrame for Mc51Chn<u8> {
598	type Sample = u8;
599
600	#[inline] fn len() -> usize { 6 }
601	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc51ChnU8) }
602}
603unsafe impl SampleFrame for Mc51Chn<i16> {
604	type Sample = i16;
605
606	#[inline] fn len() -> usize { 6 }
607	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc51ChnI16)  }
608}
609unsafe impl SampleFrame for Mc51Chn<f32> {
610	type Sample = f32;
611
612	#[inline] fn len() -> usize { 6 }
613	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc51ChnF32) }
614}
615unsafe impl SampleFrame for Mc51Chn<MuLawSample> {
616	type Sample = MuLawSample;
617
618	#[inline] fn len() -> usize { 6 }
619	#[inline] fn format() -> Format { Format::ExtMuLawMcFormats(ExtMuLawMcFormat::Mc51Chn) }
620}
621
622
623unsafe impl SampleFrame for Mc61Chn<u8> {
624	type Sample = u8;
625
626	#[inline] fn len() -> usize { 7 }
627	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc61ChnU8) }
628}
629unsafe impl SampleFrame for Mc61Chn<i16> {
630	type Sample = i16;
631
632	#[inline] fn len() -> usize { 7 }
633	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc61ChnI16)  }
634}
635unsafe impl SampleFrame for Mc61Chn<f32> {
636	type Sample = f32;
637
638	#[inline] fn len() -> usize { 7 }
639	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc61ChnF32) }
640}
641unsafe impl SampleFrame for Mc61Chn<MuLawSample> {
642	type Sample = MuLawSample;
643
644	#[inline] fn len() -> usize { 7 }
645	#[inline] fn format() -> Format { Format::ExtMuLawMcFormats(ExtMuLawMcFormat::Mc61Chn) }
646}
647
648
649unsafe impl SampleFrame for Mc71Chn<u8> {
650	type Sample = u8;
651
652	#[inline] fn len() -> usize { 8 }
653	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc71ChnU8) }
654}
655unsafe impl SampleFrame for Mc71Chn<i16> {
656	type Sample = i16;
657
658	#[inline] fn len() -> usize { 8 }
659	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc71ChnI16)  }
660}
661unsafe impl SampleFrame for Mc71Chn<f32> {
662	type Sample = f32;
663
664	#[inline] fn len() -> usize { 8 }
665	#[inline] fn format() -> Format { Format::ExtMcFormats(ExtMcFormat::Mc71ChnF32) }
666}
667unsafe impl SampleFrame for Mc71Chn<MuLawSample> {
668	type Sample = MuLawSample;
669
670	#[inline] fn len() -> usize { 8 }
671	#[inline] fn format() -> Format { Format::ExtMuLawMcFormats(ExtMuLawMcFormat::Mc71Chn) }
672}
673
674
675unsafe impl SampleFrame for BFormat2D<u8> {
676	type Sample = u8;
677
678	#[inline] fn len() -> usize { 3 }
679	#[inline] fn format() -> Format { Format::ExtBFormat(ExtBFormat::B2DU8) }
680}
681unsafe impl SampleFrame for BFormat2D<i16> {
682	type Sample = i16;
683
684	#[inline] fn len() -> usize { 3 }
685	#[inline] fn format() -> Format { Format::ExtBFormat(ExtBFormat::B2DI16) }
686}
687unsafe impl SampleFrame for BFormat2D<f32> {
688	type Sample = f32;
689
690	#[inline] fn len() -> usize { 3 }
691	#[inline] fn format() -> Format { Format::ExtBFormat(ExtBFormat::B2DF32) }
692}
693unsafe impl SampleFrame for BFormat2D<MuLawSample> {
694	type Sample = MuLawSample;
695
696	#[inline] fn len() -> usize { 3 }
697	#[inline] fn format() -> Format { Format::ExtMuLawBFormat(ExtMuLawBFormat::B2D) }
698}
699
700
701unsafe impl SampleFrame for BFormat3D<u8> {
702	type Sample = u8;
703
704	#[inline] fn len() -> usize { 4 }
705	#[inline] fn format() -> Format { Format::ExtBFormat(ExtBFormat::B3DU8) }
706}
707unsafe impl SampleFrame for BFormat3D<i16> {
708	type Sample = i16;
709
710	#[inline] fn len() -> usize { 4 }
711	#[inline] fn format() -> Format { Format::ExtBFormat(ExtBFormat::B3DI16) }
712}
713unsafe impl SampleFrame for BFormat3D<f32> {
714	type Sample = f32;
715
716	#[inline] fn len() -> usize { 4 }
717	#[inline] fn format() -> Format { Format::ExtBFormat(ExtBFormat::B3DF32) }
718}
719unsafe impl SampleFrame for BFormat3D<MuLawSample> {
720	type Sample = MuLawSample;
721
722	#[inline] fn len() -> usize { 4 }
723	#[inline] fn format() -> Format { Format::ExtMuLawBFormat(ExtMuLawBFormat::B3D) }
724}
725
726
727unsafe impl StandardFrame for Mono<u8> { }
728unsafe impl StandardFrame for Mono<i16> { }
729unsafe impl StandardFrame for Stereo<u8> { }
730unsafe impl StandardFrame for Stereo<i16> { }
731
732
733unsafe impl LoopbackFrame for Mono<u8>
734{
735	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_MONO_SOFT?) }
736	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_UNSIGNED_BYTE_SOFT?) }
737}
738unsafe impl LoopbackFrame for Mono<i16>
739{
740	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_MONO_SOFT?) }
741	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_SHORT_SOFT?) }
742}
743unsafe impl LoopbackFrame for Mono<f32>
744{
745	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_MONO_SOFT?) }
746	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_FLOAT_SOFT?) }
747}
748
749
750unsafe impl LoopbackFrame for Stereo<u8>
751{
752	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_STEREO_SOFT?) }
753	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_UNSIGNED_BYTE_SOFT?) }
754}
755unsafe impl LoopbackFrame for Stereo<i16>
756{
757	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_STEREO_SOFT?) }
758	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_SHORT_SOFT?) }
759}
760unsafe impl LoopbackFrame for Stereo<f32>
761{
762	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_STEREO_SOFT?) }
763	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_FLOAT_SOFT?) }
764}
765
766
767unsafe impl LoopbackFrame for McQuad<u8>
768{
769	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_QUAD_SOFT?) }
770	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_UNSIGNED_BYTE_SOFT?) }
771}
772unsafe impl LoopbackFrame for McQuad<i16>
773{
774	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_QUAD_SOFT?) }
775	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_SHORT_SOFT?) }
776}
777unsafe impl LoopbackFrame for McQuad<f32>
778{
779	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_QUAD_SOFT?) }
780	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_FLOAT_SOFT?) }
781}
782
783
784unsafe impl LoopbackFrame for Mc51Chn<u8>
785{
786	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_5POINT1_SOFT?) }
787	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_UNSIGNED_BYTE_SOFT?) }
788}
789unsafe impl LoopbackFrame for Mc51Chn<i16>
790{
791	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_5POINT1_SOFT?) }
792	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_SHORT_SOFT?) }
793}
794unsafe impl LoopbackFrame for Mc51Chn<f32>
795{
796	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_5POINT1_SOFT?) }
797	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_FLOAT_SOFT?) }
798}
799
800
801unsafe impl LoopbackFrame for Mc61Chn<u8>
802{
803	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_6POINT1_SOFT?) }
804	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_UNSIGNED_BYTE_SOFT?) }
805}
806unsafe impl LoopbackFrame for Mc61Chn<i16>
807{
808	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_6POINT1_SOFT?) }
809	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_SHORT_SOFT?) }
810}
811unsafe impl LoopbackFrame for Mc61Chn<f32>
812{
813	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_6POINT1_SOFT?) }
814	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_FLOAT_SOFT?) }
815}
816
817
818unsafe impl LoopbackFrame for Mc71Chn<u8>
819{
820	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_7POINT1_SOFT?) }
821	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_UNSIGNED_BYTE_SOFT?) }
822}
823unsafe impl LoopbackFrame for Mc71Chn<i16>
824{
825	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_7POINT1_SOFT?) }
826	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_SHORT_SOFT?) }
827}
828unsafe impl LoopbackFrame for Mc71Chn<f32>
829{
830	fn channels(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_7POINT1_SOFT?) }
831	fn sample_ty(sl: &ext::ALC_SOFT_loopback) -> AltoResult<sys::ALint> { Ok(sl.ALC_FLOAT_SOFT?) }
832}
833
834
835unsafe impl<F> AsBufferData<F> for [F] where F: SampleFrame {
836	fn as_buffer_data(&self) -> (*const sys::ALvoid, usize) {
837		(self.as_ptr() as *const _, self.len() * mem::size_of::<F>())
838	}
839}
840unsafe impl<F> AsBufferData<F> for [u8] where F: SampleFrame<Sample = u8> {
841	fn as_buffer_data(&self) -> (*const sys::ALvoid, usize) {
842		(self.as_ptr() as *const _, self.len() * mem::size_of::<u8>())
843	}
844}
845unsafe impl<F> AsBufferData<F> for [i16] where F: SampleFrame<Sample = i16> {
846	fn as_buffer_data(&self) -> (*const sys::ALvoid, usize) {
847		(self.as_ptr() as *const _, self.len() * mem::size_of::<i16>())
848	}
849}
850unsafe impl<F> AsBufferData<F> for [f32] where F: SampleFrame<Sample = f32> {
851	fn as_buffer_data(&self) -> (*const sys::ALvoid, usize) {
852		(self.as_ptr() as *const _, self.len() * mem::size_of::<f32>())
853	}
854}
855unsafe impl<F, T> AsBufferData<F> for T where
856	F: SampleFrame,
857	T: Deref,
858	<T as Deref>::Target: AsBufferData<F>,
859{
860	fn as_buffer_data(&self) -> (*const sys::ALvoid, usize) { (**self).as_buffer_data() }
861}
862
863
864unsafe impl<F> AsBufferDataMut<F> for [F] where F: SampleFrame {
865	fn as_buffer_data_mut(&mut self) -> (*mut sys::ALvoid, usize) {
866		(self.as_mut_ptr() as *mut _, self.len() * mem::size_of::<F>())
867	}
868}
869unsafe impl<F> AsBufferDataMut<F> for [u8] where F: SampleFrame<Sample = u8> {
870	fn as_buffer_data_mut(&mut self) -> (*mut sys::ALvoid, usize) {
871		(self.as_mut_ptr() as *mut _, self.len() * mem::size_of::<u8>())
872	}
873}
874unsafe impl<F> AsBufferDataMut<F> for [i16] where F: SampleFrame<Sample = i16> {
875	fn as_buffer_data_mut(&mut self) -> (*mut sys::ALvoid, usize) {
876		(self.as_mut_ptr() as *mut _, self.len() * mem::size_of::<i16>())
877	}
878}
879unsafe impl<F> AsBufferDataMut<F> for [f32] where F: SampleFrame<Sample = f32> {
880	fn as_buffer_data_mut(&mut self) -> (*mut sys::ALvoid, usize) {
881		(self.as_mut_ptr() as *mut _, self.len() * mem::size_of::<f32>())
882	}
883}
884unsafe impl<F, T> AsBufferDataMut<F> for T where
885	F: SampleFrame,
886	T: DerefMut,
887	<T as Deref>::Target: AsBufferDataMut<F>,
888{
889	fn as_buffer_data_mut(&mut self) -> (*mut sys::ALvoid, usize) { (**self).as_buffer_data_mut() }
890}