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