objc2_avf_audio/generated/AVAudioFile.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// An audio file opened for reading or writing.
12 ///
13 /// Regardless of the file's actual format, reading and writing the file is done via
14 /// `AVAudioPCMBuffer` objects, containing samples in an `AVAudioCommonFormat`,
15 /// referred to as the file's "processing format." Conversions are performed to and from
16 /// the file's actual format.
17 ///
18 /// Reads and writes are always sequential, but random access is possible by setting the
19 /// framePosition property.
20 ///
21 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiofile?language=objc)
22 #[unsafe(super(NSObject))]
23 #[derive(Debug, PartialEq, Eq, Hash)]
24 pub struct AVAudioFile;
25);
26
27unsafe impl Send for AVAudioFile {}
28
29unsafe impl Sync for AVAudioFile {}
30
31extern_conformance!(
32 unsafe impl NSObjectProtocol for AVAudioFile {}
33);
34
35impl AVAudioFile {
36 extern_methods!(
37 #[deprecated = "Deprecated - use initForReading or initForWriting"]
38 #[unsafe(method(init))]
39 #[unsafe(method_family = init)]
40 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
41
42 /// Open a file for reading.
43 ///
44 /// Parameter `fileURL`: the file to open
45 ///
46 /// Parameter `outError`: on exit, if an error occurs, a description of the error
47 ///
48 /// This opens the file for reading using the standard format (deinterleaved floating point).
49 #[unsafe(method(initForReading:error:_))]
50 #[unsafe(method_family = init)]
51 pub unsafe fn initForReading_error(
52 this: Allocated<Self>,
53 file_url: &NSURL,
54 ) -> Result<Retained<Self>, Retained<NSError>>;
55
56 #[cfg(feature = "AVAudioFormat")]
57 /// Open a file for reading, using a specified processing format.
58 ///
59 /// Parameter `fileURL`: the file to open
60 ///
61 /// Parameter `format`: the processing format to use when reading from the file
62 ///
63 /// Parameter `interleaved`: whether to use an interleaved processing format
64 ///
65 /// Parameter `outError`: on exit, if an error occurs, a description of the error
66 #[unsafe(method(initForReading:commonFormat:interleaved:error:_))]
67 #[unsafe(method_family = init)]
68 pub unsafe fn initForReading_commonFormat_interleaved_error(
69 this: Allocated<Self>,
70 file_url: &NSURL,
71 format: AVAudioCommonFormat,
72 interleaved: bool,
73 ) -> Result<Retained<Self>, Retained<NSError>>;
74
75 /// Open a file for writing.
76 ///
77 /// Parameter `fileURL`: the path at which to create the file
78 ///
79 /// Parameter `settings`: the format of the file to create (See `AVAudioRecorder`.) For linear PCM,
80 /// only interleaved formats are supported for the saved file, non interleaved setting will be
81 /// ignored and a warning is shown.
82 ///
83 /// Parameter `outError`: on exit, if an error occurs, a description of the error
84 ///
85 /// The file type to create can be set through the corresponding settings key. If not set, it will be
86 /// inferred from the file extension. Will overwrite a file at the specified URL if a file exists.
87 ///
88 /// This opens the file for writing using the standard format (deinterleaved floating point).
89 ///
90 /// # Safety
91 ///
92 /// `settings` generic should be of the correct type.
93 #[unsafe(method(initForWriting:settings:error:_))]
94 #[unsafe(method_family = init)]
95 pub unsafe fn initForWriting_settings_error(
96 this: Allocated<Self>,
97 file_url: &NSURL,
98 settings: &NSDictionary<NSString, AnyObject>,
99 ) -> Result<Retained<Self>, Retained<NSError>>;
100
101 #[cfg(feature = "AVAudioFormat")]
102 /// Open a file for writing.
103 ///
104 /// Parameter `fileURL`: the path at which to create the file
105 ///
106 /// Parameter `settings`: the format of the file to create (See `AVAudioRecorder`.) For linear PCM,
107 /// only interleaved formats are supported for the saved file, non interleaved setting will be
108 /// ignored and a warning is shown.
109 ///
110 /// Parameter `format`: the processing format to use when writing to the file.
111 ///
112 /// Parameter `interleaved`: whether to use an interleaved processing format
113 ///
114 /// Parameter `outError`: on exit, if an error occurs, a description of the error
115 ///
116 /// The file type to create can be set through the corresponding settings key. If not set, it will be
117 /// inferred from the file extension. Will overwrite a file at the specified URL if a file exists.
118 ///
119 /// # Safety
120 ///
121 /// `settings` generic should be of the correct type.
122 #[unsafe(method(initForWriting:settings:commonFormat:interleaved:error:_))]
123 #[unsafe(method_family = init)]
124 pub unsafe fn initForWriting_settings_commonFormat_interleaved_error(
125 this: Allocated<Self>,
126 file_url: &NSURL,
127 settings: &NSDictionary<NSString, AnyObject>,
128 format: AVAudioCommonFormat,
129 interleaved: bool,
130 ) -> Result<Retained<Self>, Retained<NSError>>;
131
132 /// Close the audio file.
133 ///
134 /// The underlying file will be closed if open.
135 ///
136 /// - It is normally unnecessary to close a file opened for reading (it will be automatically closed
137 /// when the object is released)
138 /// - It is only necessary to close a file opened for writing in order to achieve specific control over
139 /// when the file's header is updated.
140 ///
141 /// Note: Once closed, further file read or write operations will fail with kAudio_FileNotFoundError.
142 #[unsafe(method(close))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn close(&self);
145
146 #[cfg(feature = "AVAudioBuffer")]
147 /// Read an entire buffer.
148 ///
149 /// Parameter `buffer`: The buffer into which to read from the file. Its format must match the file's
150 /// processing format.
151 ///
152 /// Parameter `outError`: on exit, if an error occurs, a description of the error
153 ///
154 /// Returns: YES for success.
155 ///
156 /// Reading sequentially from framePosition, attempts to fill the buffer to its capacity. On
157 /// return, the buffer's length indicates the number of sample frames successfully read.
158 #[unsafe(method(readIntoBuffer:error:_))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn readIntoBuffer_error(
161 &self,
162 buffer: &AVAudioPCMBuffer,
163 ) -> Result<(), Retained<NSError>>;
164
165 #[cfg(all(feature = "AVAudioBuffer", feature = "AVAudioTypes"))]
166 /// Read a portion of a buffer.
167 ///
168 /// Parameter `frames`: The number of frames to read.
169 ///
170 /// Parameter `buffer`: The buffer into which to read from the file. Its format must match the file's
171 /// processing format.
172 ///
173 /// Parameter `outError`: on exit, if an error occurs, a description of the error
174 ///
175 /// Returns: YES for success.
176 ///
177 /// Like `readIntoBuffer:error:`, but can be used to read fewer frames than buffer.frameCapacity.
178 #[unsafe(method(readIntoBuffer:frameCount:error:_))]
179 #[unsafe(method_family = none)]
180 pub unsafe fn readIntoBuffer_frameCount_error(
181 &self,
182 buffer: &AVAudioPCMBuffer,
183 frames: AVAudioFrameCount,
184 ) -> Result<(), Retained<NSError>>;
185
186 #[cfg(feature = "AVAudioBuffer")]
187 /// Write a buffer.
188 ///
189 /// Parameter `buffer`: The buffer from which to write to the file. Its format must match the file's
190 /// processing format.
191 ///
192 /// Parameter `outError`: on exit, if an error occurs, a description of the error
193 ///
194 /// Returns: YES for success.
195 ///
196 /// Writes sequentially. The buffer's frameLength signifies how much of the buffer is to be written.
197 #[unsafe(method(writeFromBuffer:error:_))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn writeFromBuffer_error(
200 &self,
201 buffer: &AVAudioPCMBuffer,
202 ) -> Result<(), Retained<NSError>>;
203
204 /// Whether the file is open or not.
205 ///
206 /// This property is not atomic.
207 ///
208 /// # Safety
209 ///
210 /// This might not be thread-safe.
211 #[unsafe(method(isOpen))]
212 #[unsafe(method_family = none)]
213 pub unsafe fn isOpen(&self) -> bool;
214
215 /// The URL the file is reading or writing.
216 ///
217 /// This property is not atomic.
218 ///
219 /// # Safety
220 ///
221 /// This might not be thread-safe.
222 #[unsafe(method(url))]
223 #[unsafe(method_family = none)]
224 pub unsafe fn url(&self) -> Retained<NSURL>;
225
226 #[cfg(feature = "AVAudioFormat")]
227 /// The on-disk format of the file.
228 ///
229 /// This property is not atomic.
230 ///
231 /// # Safety
232 ///
233 /// This might not be thread-safe.
234 #[unsafe(method(fileFormat))]
235 #[unsafe(method_family = none)]
236 pub unsafe fn fileFormat(&self) -> Retained<AVAudioFormat>;
237
238 #[cfg(feature = "AVAudioFormat")]
239 /// The processing format of the file.
240 ///
241 /// This property is not atomic.
242 ///
243 /// # Safety
244 ///
245 /// This might not be thread-safe.
246 #[unsafe(method(processingFormat))]
247 #[unsafe(method_family = none)]
248 pub unsafe fn processingFormat(&self) -> Retained<AVAudioFormat>;
249
250 #[cfg(feature = "AVAudioTypes")]
251 /// The number of sample frames in the file.
252 ///
253 /// Note: this can be expensive to compute for the first time.
254 ///
255 /// This property is not atomic.
256 ///
257 /// # Safety
258 ///
259 /// This might not be thread-safe.
260 #[unsafe(method(length))]
261 #[unsafe(method_family = none)]
262 pub unsafe fn length(&self) -> AVAudioFramePosition;
263
264 #[cfg(feature = "AVAudioTypes")]
265 /// The position in the file at which the next read or write will occur.
266 ///
267 /// Set framePosition to perform a seek before a read or write. A read or write operation advances the frame position by the number of frames read or written.
268 ///
269 /// This property is not atomic.
270 ///
271 /// # Safety
272 ///
273 /// This might not be thread-safe.
274 #[unsafe(method(framePosition))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn framePosition(&self) -> AVAudioFramePosition;
277
278 #[cfg(feature = "AVAudioTypes")]
279 /// Setter for [`framePosition`][Self::framePosition].
280 ///
281 /// # Safety
282 ///
283 /// This might not be thread-safe.
284 #[unsafe(method(setFramePosition:))]
285 #[unsafe(method_family = none)]
286 pub unsafe fn setFramePosition(&self, frame_position: AVAudioFramePosition);
287 );
288}
289
290/// Methods declared on superclass `NSObject`.
291impl AVAudioFile {
292 extern_methods!(
293 #[unsafe(method(new))]
294 #[unsafe(method_family = new)]
295 pub unsafe fn new() -> Retained<Self>;
296 );
297}