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 ///
159 /// # Safety
160 ///
161 /// `buffer_list` must be a valid pointer.
162 #[unsafe(method(initWithPCMFormat:bufferListNoCopy:deallocator:))]
163 #[unsafe(method_family = init)]
164 pub unsafe fn initWithPCMFormat_bufferListNoCopy_deallocator(
165 this: Allocated<Self>,
166 format: &AVAudioFormat,
167 buffer_list: NonNull<AudioBufferList>,
168 deallocator: Option<&block2::DynBlock<dyn Fn(NonNull<AudioBufferList>)>>,
169 ) -> Option<Retained<Self>>;
170
171 #[cfg(feature = "AVAudioTypes")]
172 /// The buffer's capacity, in audio sample frames.
173 #[unsafe(method(frameCapacity))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn frameCapacity(&self) -> AVAudioFrameCount;
176
177 #[cfg(feature = "AVAudioTypes")]
178 /// The current number of valid sample frames in the buffer.
179 ///
180 /// You may modify the length of the buffer as part of an operation that modifies its contents.
181 /// The length must be less than or equal to the frameCapacity. Modifying frameLength will update
182 /// the mDataByteSize in each of the underlying AudioBufferList's AudioBuffer's correspondingly,
183 /// and vice versa. Note that in the case of deinterleaved formats, mDataByteSize will refers
184 /// the size of one channel's worth of audio samples.
185 #[unsafe(method(frameLength))]
186 #[unsafe(method_family = none)]
187 pub unsafe fn frameLength(&self) -> AVAudioFrameCount;
188
189 #[cfg(feature = "AVAudioTypes")]
190 /// Setter for [`frameLength`][Self::frameLength].
191 #[unsafe(method(setFrameLength:))]
192 #[unsafe(method_family = none)]
193 pub unsafe fn setFrameLength(&self, frame_length: AVAudioFrameCount);
194
195 /// The buffer's number of interleaved channels.
196 ///
197 /// Useful in conjunction with floatChannelData etc.
198 #[unsafe(method(stride))]
199 #[unsafe(method_family = none)]
200 pub unsafe fn stride(&self) -> NSUInteger;
201
202 /// Access the buffer's float audio samples.
203 ///
204 /// floatChannelData returns pointers to the buffer's audio samples if the buffer's format is
205 /// 32-bit float, or nil if it is another format.
206 ///
207 /// The returned pointer is to format.channelCount pointers to float. Each of these pointers
208 /// is to "frameLength" valid samples, which are spaced by "stride" samples.
209 ///
210 /// If format.interleaved is false (as with the standard deinterleaved float format), then
211 /// the pointers will be to separate chunks of memory. "stride" is 1.
212 ///
213 /// If format.interleaved is true, then the pointers will refer into the same chunk of interleaved
214 /// samples, each offset by 1 frame. "stride" is the number of interleaved channels.
215 #[unsafe(method(floatChannelData))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn floatChannelData(&self) -> *mut NonNull<c_float>;
218
219 /// Access the buffer's int16_t audio samples.
220 ///
221 /// int16ChannelData returns the buffer's audio samples if the buffer's format has 2-byte
222 /// integer samples, or nil if it is another format.
223 ///
224 /// See the discussion of floatChannelData.
225 #[unsafe(method(int16ChannelData))]
226 #[unsafe(method_family = none)]
227 pub unsafe fn int16ChannelData(&self) -> *mut NonNull<i16>;
228
229 /// Access the buffer's int32_t audio samples.
230 ///
231 /// int32ChannelData returns the buffer's audio samples if the buffer's format has 4-byte
232 /// integer samples, or nil if it is another format.
233 ///
234 /// See the discussion of floatChannelData.
235 #[unsafe(method(int32ChannelData))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn int32ChannelData(&self) -> *mut NonNull<i32>;
238 );
239}
240
241/// Methods declared on superclass `NSObject`.
242impl AVAudioPCMBuffer {
243 extern_methods!(
244 #[unsafe(method(init))]
245 #[unsafe(method_family = init)]
246 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
247
248 #[unsafe(method(new))]
249 #[unsafe(method_family = new)]
250 pub unsafe fn new() -> Retained<Self>;
251 );
252}
253
254extern_class!(
255 /// A subclass of AVAudioBuffer for use with compressed audio formats.
256 ///
257 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiocompressedbuffer?language=objc)
258 #[unsafe(super(AVAudioBuffer, NSObject))]
259 #[derive(Debug, PartialEq, Eq, Hash)]
260 pub struct AVAudioCompressedBuffer;
261);
262
263extern_conformance!(
264 unsafe impl NSCopying for AVAudioCompressedBuffer {}
265);
266
267unsafe impl CopyingHelper for AVAudioCompressedBuffer {
268 type Result = Self;
269}
270
271extern_conformance!(
272 unsafe impl NSObjectProtocol for AVAudioCompressedBuffer {}
273);
274
275impl AVAudioCompressedBuffer {
276 extern_methods!(
277 #[cfg(all(feature = "AVAudioFormat", feature = "AVAudioTypes"))]
278 /// Initialize a buffer that is to contain compressed audio data.
279 ///
280 /// Parameter `format`: The format of the audio to be contained in the buffer.
281 ///
282 /// Parameter `packetCapacity`: The capacity of the buffer in packets.
283 ///
284 /// Parameter `maximumPacketSize`: The maximum size in bytes of a compressed packet.
285 /// The maximum packet size can be obtained from the maximumOutputPacketSize property of an AVAudioConverter configured for encoding this format.
286 ///
287 /// An exception is raised if the format is PCM.
288 #[unsafe(method(initWithFormat:packetCapacity:maximumPacketSize:))]
289 #[unsafe(method_family = init)]
290 pub unsafe fn initWithFormat_packetCapacity_maximumPacketSize(
291 this: Allocated<Self>,
292 format: &AVAudioFormat,
293 packet_capacity: AVAudioPacketCount,
294 maximum_packet_size: NSInteger,
295 ) -> Retained<Self>;
296
297 #[cfg(all(feature = "AVAudioFormat", feature = "AVAudioTypes"))]
298 /// Initialize a buffer that is to contain constant bytes per packet compressed audio data.
299 ///
300 /// Parameter `format`: The format of the audio to be contained in the buffer.
301 ///
302 /// Parameter `packetCapacity`: The capacity of the buffer in packets.
303 ///
304 /// This fails if the format is PCM or if the format has variable bytes per packet (format.streamDescription->mBytesPerPacket == 0).
305 #[unsafe(method(initWithFormat:packetCapacity:))]
306 #[unsafe(method_family = init)]
307 pub unsafe fn initWithFormat_packetCapacity(
308 this: Allocated<Self>,
309 format: &AVAudioFormat,
310 packet_capacity: AVAudioPacketCount,
311 ) -> Retained<Self>;
312
313 #[cfg(feature = "AVAudioTypes")]
314 /// The number of compressed packets the buffer can contain.
315 #[unsafe(method(packetCapacity))]
316 #[unsafe(method_family = none)]
317 pub unsafe fn packetCapacity(&self) -> AVAudioPacketCount;
318
319 #[cfg(feature = "AVAudioTypes")]
320 /// The current number of compressed packets in the buffer.
321 ///
322 /// You may modify the packetCount as part of an operation that modifies its contents.
323 /// The packetCount must be less than or equal to the packetCapacity.
324 #[unsafe(method(packetCount))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn packetCount(&self) -> AVAudioPacketCount;
327
328 #[cfg(feature = "AVAudioTypes")]
329 /// Setter for [`packetCount`][Self::packetCount].
330 #[unsafe(method(setPacketCount:))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn setPacketCount(&self, packet_count: AVAudioPacketCount);
333
334 /// The maximum size of a compressed packet in bytes.
335 #[unsafe(method(maximumPacketSize))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn maximumPacketSize(&self) -> NSInteger;
338
339 /// Access the buffer's data bytes.
340 #[unsafe(method(data))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn data(&self) -> NonNull<c_void>;
343
344 /// The buffer's capacity in bytes
345 #[unsafe(method(byteCapacity))]
346 #[unsafe(method_family = none)]
347 pub unsafe fn byteCapacity(&self) -> u32;
348
349 /// The current number of valid bytes in the buffer.
350 ///
351 /// Can be changed as part of an operation that modifies the contents.
352 #[unsafe(method(byteLength))]
353 #[unsafe(method_family = none)]
354 pub unsafe fn byteLength(&self) -> u32;
355
356 /// Setter for [`byteLength`][Self::byteLength].
357 #[unsafe(method(setByteLength:))]
358 #[unsafe(method_family = none)]
359 pub unsafe fn setByteLength(&self, byte_length: u32);
360
361 #[cfg(feature = "objc2-core-audio-types")]
362 /// Access the buffer's array of packet descriptions, if any.
363 ///
364 /// If the format has constant bytes per packet (format.streamDescription->mBytesPerPacket != 0), then this will return nil.
365 #[unsafe(method(packetDescriptions))]
366 #[unsafe(method_family = none)]
367 pub unsafe fn packetDescriptions(&self) -> *mut AudioStreamPacketDescription;
368
369 #[cfg(feature = "objc2-core-audio-types")]
370 /// Access the buffer's array of packet dependencies, if any.
371 ///
372 /// If the format doesn't employ packet dependencies, this will be nil.
373 #[unsafe(method(packetDependencies))]
374 #[unsafe(method_family = none)]
375 pub unsafe fn packetDependencies(&self) -> *mut AudioStreamPacketDependencyDescription;
376 );
377}
378
379/// Methods declared on superclass `NSObject`.
380impl AVAudioCompressedBuffer {
381 extern_methods!(
382 #[unsafe(method(init))]
383 #[unsafe(method_family = init)]
384 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
385
386 #[unsafe(method(new))]
387 #[unsafe(method_family = new)]
388 pub unsafe fn new() -> Retained<Self>;
389 );
390}