objc2_avf_audio/generated/
AVAudioBuffer.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-audio-types")]
7use objc2_core_audio_types::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13    /// A buffer of audio data, with a format.
14    ///
15    /// AVAudioBuffer represents a buffer of audio data and its format.
16    ///
17    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiobuffer?language=objc)
18    #[unsafe(super(NSObject))]
19    #[derive(Debug, PartialEq, Eq, Hash)]
20    pub struct AVAudioBuffer;
21);
22
23extern_conformance!(
24    unsafe impl NSCopying for AVAudioBuffer {}
25);
26
27unsafe impl CopyingHelper for AVAudioBuffer {
28    type Result = Self;
29}
30
31extern_conformance!(
32    unsafe impl NSObjectProtocol for AVAudioBuffer {}
33);
34
35impl AVAudioBuffer {
36    extern_methods!(
37        #[cfg(feature = "AVAudioFormat")]
38        /// The format of the audio in the buffer.
39        #[unsafe(method(format))]
40        #[unsafe(method_family = none)]
41        pub unsafe fn format(&self) -> Retained<AVAudioFormat>;
42
43        #[cfg(feature = "objc2-core-audio-types")]
44        /// The buffer's underlying AudioBufferList.
45        ///
46        /// For compatibility with lower-level CoreAudio and AudioToolbox API's, this method accesses
47        /// the buffer implementation's internal AudioBufferList. The buffer list structure must
48        /// not be modified, though you may modify buffer contents.
49        ///
50        /// The mDataByteSize fields of this AudioBufferList express the buffer's current frameLength.
51        #[unsafe(method(audioBufferList))]
52        #[unsafe(method_family = none)]
53        pub unsafe fn audioBufferList(&self) -> NonNull<AudioBufferList>;
54
55        #[cfg(feature = "objc2-core-audio-types")]
56        /// A mutable version of the buffer's underlying AudioBufferList.
57        ///
58        /// Some lower-level CoreAudio and AudioToolbox API's require a mutable AudioBufferList,
59        /// for example, AudioConverterConvertComplexBuffer.
60        ///
61        /// The mDataByteSize fields of this AudioBufferList express the buffer's current frameCapacity.
62        /// If they are altered, you should modify the buffer's frameLength to match.
63        #[unsafe(method(mutableAudioBufferList))]
64        #[unsafe(method_family = none)]
65        pub unsafe fn mutableAudioBufferList(&self) -> NonNull<AudioBufferList>;
66    );
67}
68
69/// Methods declared on superclass `NSObject`.
70impl AVAudioBuffer {
71    extern_methods!(
72        #[unsafe(method(init))]
73        #[unsafe(method_family = init)]
74        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
75
76        #[unsafe(method(new))]
77        #[unsafe(method_family = new)]
78        pub unsafe fn new() -> Retained<Self>;
79    );
80}
81
82extern_class!(
83    /// A subclass of AVAudioBuffer for use with PCM audio formats.
84    ///
85    /// AVAudioPCMBuffer provides a number of methods useful for manipulating buffers of
86    /// audio in PCM format.
87    ///
88    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiopcmbuffer?language=objc)
89    #[unsafe(super(AVAudioBuffer, NSObject))]
90    #[derive(Debug, PartialEq, Eq, Hash)]
91    pub struct AVAudioPCMBuffer;
92);
93
94extern_conformance!(
95    unsafe impl NSCopying for AVAudioPCMBuffer {}
96);
97
98unsafe impl CopyingHelper for AVAudioPCMBuffer {
99    type Result = Self;
100}
101
102extern_conformance!(
103    unsafe impl NSObjectProtocol for AVAudioPCMBuffer {}
104);
105
106impl AVAudioPCMBuffer {
107    extern_methods!(
108        #[cfg(all(feature = "AVAudioFormat", feature = "AVAudioTypes"))]
109        /// Initialize a buffer that is to contain PCM audio samples.
110        ///
111        /// Parameter `format`: The format of the PCM audio to be contained in the buffer.
112        ///
113        /// Parameter `frameCapacity`: The capacity of the buffer in PCM sample frames.
114        ///
115        /// An exception is raised if the format is not PCM.
116        ///
117        /// Returns nil in the following cases:
118        /// - if the format has zero bytes per frame (format.streamDescription->mBytesPerFrame == 0)
119        /// - if the buffer byte capacity (frameCapacity * format.streamDescription->mBytesPerFrame)
120        /// cannot be represented by an uint32_t
121        #[unsafe(method(initWithPCMFormat:frameCapacity:))]
122        #[unsafe(method_family = init)]
123        pub unsafe fn initWithPCMFormat_frameCapacity(
124            this: Allocated<Self>,
125            format: &AVAudioFormat,
126            frame_capacity: AVAudioFrameCount,
127        ) -> Option<Retained<Self>>;
128
129        #[cfg(all(
130            feature = "AVAudioFormat",
131            feature = "block2",
132            feature = "objc2-core-audio-types"
133        ))]
134        /// Initialize a buffer that is to contain PCM audio samples with a given AudioBufferList
135        /// without copying samples and a custom deallocator block.
136        ///
137        /// Parameter `format`: The format of the PCM audio to be contained in the buffer.
138        ///
139        /// Parameter `bufferList`: The buffer list with allocated memory to contain the PCM audio data.
140        ///
141        /// Parameter `deallocator`: A block to invoke when the resulting AVAudioPCMBuffer object is deallocated.
142        ///
143        /// An exception is raised if the format is not PCM.
144        ///
145        /// Returns nil in the following cases:
146        /// - if the format has zero bytes per frame (format.streamDescription->mBytesPerFrame == 0)
147        /// - if supplied buffer has zero number of buffers
148        /// - if each buffer's data byte size are not equal or if any of the buffers' data byte size is zero
149        /// - if there is a mismatch between the format's number of buffers and the AudioBufferList's size
150        /// (1 if interleaved, mChannelsPerFrame if deinterleaved)
151        /// - if the AudioBufferList's pointer to the buffer of audio data is null.
152        ///
153        /// Use the deallocator block to define your own deallocation behavior for the provided AudioBufferList's
154        /// underlying memory.
155        ///
156        /// The AudioBufferList passed to the deallocator is identical to the one which was passed to the initializer,
157        /// in terms of the buffer count, and each buffer's mData and mDataByteSize members.
158        #[unsafe(method(initWithPCMFormat:bufferListNoCopy:deallocator:))]
159        #[unsafe(method_family = init)]
160        pub unsafe fn initWithPCMFormat_bufferListNoCopy_deallocator(
161            this: Allocated<Self>,
162            format: &AVAudioFormat,
163            buffer_list: NonNull<AudioBufferList>,
164            deallocator: Option<&block2::DynBlock<dyn Fn(NonNull<AudioBufferList>)>>,
165        ) -> Option<Retained<Self>>;
166
167        #[cfg(feature = "AVAudioTypes")]
168        /// The buffer's capacity, in audio sample frames.
169        #[unsafe(method(frameCapacity))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn frameCapacity(&self) -> AVAudioFrameCount;
172
173        #[cfg(feature = "AVAudioTypes")]
174        /// The current number of valid sample frames in the buffer.
175        ///
176        /// You may modify the length of the buffer as part of an operation that modifies its contents.
177        /// The length must be less than or equal to the frameCapacity. Modifying frameLength will update
178        /// the mDataByteSize in each of the underlying AudioBufferList's AudioBuffer's correspondingly,
179        /// and vice versa. Note that in the case of deinterleaved formats, mDataByteSize will refers
180        /// the size of one channel's worth of audio samples.
181        #[unsafe(method(frameLength))]
182        #[unsafe(method_family = none)]
183        pub unsafe fn frameLength(&self) -> AVAudioFrameCount;
184
185        #[cfg(feature = "AVAudioTypes")]
186        /// Setter for [`frameLength`][Self::frameLength].
187        #[unsafe(method(setFrameLength:))]
188        #[unsafe(method_family = none)]
189        pub unsafe fn setFrameLength(&self, frame_length: AVAudioFrameCount);
190
191        /// The buffer's number of interleaved channels.
192        ///
193        /// Useful in conjunction with floatChannelData etc.
194        #[unsafe(method(stride))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn stride(&self) -> NSUInteger;
197
198        /// Access the buffer's float audio samples.
199        ///
200        /// floatChannelData returns pointers to the buffer's audio samples if the buffer's format is
201        /// 32-bit float, or nil if it is another format.
202        ///
203        /// The returned pointer is to format.channelCount pointers to float. Each of these pointers
204        /// is to "frameLength" valid samples, which are spaced by "stride" samples.
205        ///
206        /// If format.interleaved is false (as with the standard deinterleaved float format), then
207        /// the pointers will be to separate chunks of memory. "stride" is 1.
208        ///
209        /// If format.interleaved is true, then the pointers will refer into the same chunk of interleaved
210        /// samples, each offset by 1 frame. "stride" is the number of interleaved channels.
211        #[unsafe(method(floatChannelData))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn floatChannelData(&self) -> *mut NonNull<c_float>;
214
215        /// Access the buffer's int16_t audio samples.
216        ///
217        /// int16ChannelData returns the buffer's audio samples if the buffer's format has 2-byte
218        /// integer samples, or nil if it is another format.
219        ///
220        /// See the discussion of floatChannelData.
221        #[unsafe(method(int16ChannelData))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn int16ChannelData(&self) -> *mut NonNull<i16>;
224
225        /// Access the buffer's int32_t audio samples.
226        ///
227        /// int32ChannelData returns the buffer's audio samples if the buffer's format has 4-byte
228        /// integer samples, or nil if it is another format.
229        ///
230        /// See the discussion of floatChannelData.
231        #[unsafe(method(int32ChannelData))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn int32ChannelData(&self) -> *mut NonNull<i32>;
234    );
235}
236
237/// Methods declared on superclass `NSObject`.
238impl AVAudioPCMBuffer {
239    extern_methods!(
240        #[unsafe(method(init))]
241        #[unsafe(method_family = init)]
242        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
243
244        #[unsafe(method(new))]
245        #[unsafe(method_family = new)]
246        pub unsafe fn new() -> Retained<Self>;
247    );
248}
249
250extern_class!(
251    /// A subclass of AVAudioBuffer for use with compressed audio formats.
252    ///
253    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiocompressedbuffer?language=objc)
254    #[unsafe(super(AVAudioBuffer, NSObject))]
255    #[derive(Debug, PartialEq, Eq, Hash)]
256    pub struct AVAudioCompressedBuffer;
257);
258
259extern_conformance!(
260    unsafe impl NSCopying for AVAudioCompressedBuffer {}
261);
262
263unsafe impl CopyingHelper for AVAudioCompressedBuffer {
264    type Result = Self;
265}
266
267extern_conformance!(
268    unsafe impl NSObjectProtocol for AVAudioCompressedBuffer {}
269);
270
271impl AVAudioCompressedBuffer {
272    extern_methods!(
273        #[cfg(all(feature = "AVAudioFormat", feature = "AVAudioTypes"))]
274        /// Initialize a buffer that is to contain compressed audio data.
275        ///
276        /// Parameter `format`: The format of the audio to be contained in the buffer.
277        ///
278        /// Parameter `packetCapacity`: The capacity of the buffer in packets.
279        ///
280        /// Parameter `maximumPacketSize`: The maximum size in bytes of a compressed packet.
281        /// The maximum packet size can be obtained from the maximumOutputPacketSize property of an AVAudioConverter configured for encoding this format.
282        ///
283        /// An exception is raised if the format is PCM.
284        #[unsafe(method(initWithFormat:packetCapacity:maximumPacketSize:))]
285        #[unsafe(method_family = init)]
286        pub unsafe fn initWithFormat_packetCapacity_maximumPacketSize(
287            this: Allocated<Self>,
288            format: &AVAudioFormat,
289            packet_capacity: AVAudioPacketCount,
290            maximum_packet_size: NSInteger,
291        ) -> Retained<Self>;
292
293        #[cfg(all(feature = "AVAudioFormat", feature = "AVAudioTypes"))]
294        /// Initialize a buffer that is to contain constant bytes per packet compressed audio data.
295        ///
296        /// Parameter `format`: The format of the audio to be contained in the buffer.
297        ///
298        /// Parameter `packetCapacity`: The capacity of the buffer in packets.
299        ///
300        /// This fails if the format is PCM or if the format has variable bytes per packet (format.streamDescription->mBytesPerPacket == 0).
301        #[unsafe(method(initWithFormat:packetCapacity:))]
302        #[unsafe(method_family = init)]
303        pub unsafe fn initWithFormat_packetCapacity(
304            this: Allocated<Self>,
305            format: &AVAudioFormat,
306            packet_capacity: AVAudioPacketCount,
307        ) -> Retained<Self>;
308
309        #[cfg(feature = "AVAudioTypes")]
310        /// The number of compressed packets the buffer can contain.
311        #[unsafe(method(packetCapacity))]
312        #[unsafe(method_family = none)]
313        pub unsafe fn packetCapacity(&self) -> AVAudioPacketCount;
314
315        #[cfg(feature = "AVAudioTypes")]
316        /// The current number of compressed packets in the buffer.
317        ///
318        /// You may modify the packetCount as part of an operation that modifies its contents.
319        /// The packetCount must be less than or equal to the packetCapacity.
320        #[unsafe(method(packetCount))]
321        #[unsafe(method_family = none)]
322        pub unsafe fn packetCount(&self) -> AVAudioPacketCount;
323
324        #[cfg(feature = "AVAudioTypes")]
325        /// Setter for [`packetCount`][Self::packetCount].
326        #[unsafe(method(setPacketCount:))]
327        #[unsafe(method_family = none)]
328        pub unsafe fn setPacketCount(&self, packet_count: AVAudioPacketCount);
329
330        /// The maximum size of a compressed packet in bytes.
331        #[unsafe(method(maximumPacketSize))]
332        #[unsafe(method_family = none)]
333        pub unsafe fn maximumPacketSize(&self) -> NSInteger;
334
335        /// Access the buffer's data bytes.
336        #[unsafe(method(data))]
337        #[unsafe(method_family = none)]
338        pub unsafe fn data(&self) -> NonNull<c_void>;
339
340        /// The buffer's capacity in bytes
341        #[unsafe(method(byteCapacity))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn byteCapacity(&self) -> u32;
344
345        /// The current number of valid bytes in the buffer.
346        ///
347        /// Can be changed as part of an operation that modifies the contents.
348        #[unsafe(method(byteLength))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn byteLength(&self) -> u32;
351
352        /// Setter for [`byteLength`][Self::byteLength].
353        #[unsafe(method(setByteLength:))]
354        #[unsafe(method_family = none)]
355        pub unsafe fn setByteLength(&self, byte_length: u32);
356
357        #[cfg(feature = "objc2-core-audio-types")]
358        /// Access the buffer's array of packet descriptions, if any.
359        ///
360        /// If the format has constant bytes per packet (format.streamDescription->mBytesPerPacket != 0), then this will return nil.
361        #[unsafe(method(packetDescriptions))]
362        #[unsafe(method_family = none)]
363        pub unsafe fn packetDescriptions(&self) -> *mut AudioStreamPacketDescription;
364    );
365}
366
367/// Methods declared on superclass `NSObject`.
368impl AVAudioCompressedBuffer {
369    extern_methods!(
370        #[unsafe(method(init))]
371        #[unsafe(method_family = init)]
372        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
373
374        #[unsafe(method(new))]
375        #[unsafe(method_family = new)]
376        pub unsafe fn new() -> Retained<Self>;
377    );
378}