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 NSObjectProtocol for AVAudioFile {}
28
29impl AVAudioFile {
30 extern_methods!(
31 /// Open a file for reading.
32 ///
33 /// Parameter `fileURL`: the file to open
34 ///
35 /// Parameter `outError`: on exit, if an error occurs, a description of the error
36 ///
37 /// This opens the file for reading using the standard format (deinterleaved floating point).
38 #[unsafe(method(initForReading:error:_))]
39 #[unsafe(method_family = init)]
40 pub unsafe fn initForReading_error(
41 this: Allocated<Self>,
42 file_url: &NSURL,
43 ) -> Result<Retained<Self>, Retained<NSError>>;
44
45 #[cfg(feature = "AVAudioFormat")]
46 /// Open a file for reading, using a specified processing format.
47 ///
48 /// Parameter `fileURL`: the file to open
49 ///
50 /// Parameter `format`: the processing format to use when reading from the file
51 ///
52 /// Parameter `interleaved`: whether to use an interleaved processing format
53 ///
54 /// Parameter `outError`: on exit, if an error occurs, a description of the error
55 #[unsafe(method(initForReading:commonFormat:interleaved:error:_))]
56 #[unsafe(method_family = init)]
57 pub unsafe fn initForReading_commonFormat_interleaved_error(
58 this: Allocated<Self>,
59 file_url: &NSURL,
60 format: AVAudioCommonFormat,
61 interleaved: bool,
62 ) -> Result<Retained<Self>, Retained<NSError>>;
63
64 /// Open a file for writing.
65 ///
66 /// Parameter `fileURL`: the path at which to create the file
67 ///
68 /// Parameter `settings`: the format of the file to create (See `AVAudioRecorder`.) For linear PCM,
69 /// only interleaved formats are supported for the saved file, non interleaved setting will be
70 /// ignored and a warning is shown.
71 ///
72 /// Parameter `outError`: on exit, if an error occurs, a description of the error
73 ///
74 /// The file type to create can be set through the corresponding settings key. If not set, it will be
75 /// inferred from the file extension. Will overwrite a file at the specified URL if a file exists.
76 ///
77 /// This opens the file for writing using the standard format (deinterleaved floating point).
78 #[unsafe(method(initForWriting:settings:error:_))]
79 #[unsafe(method_family = init)]
80 pub unsafe fn initForWriting_settings_error(
81 this: Allocated<Self>,
82 file_url: &NSURL,
83 settings: &NSDictionary<NSString, AnyObject>,
84 ) -> Result<Retained<Self>, Retained<NSError>>;
85
86 #[cfg(feature = "AVAudioFormat")]
87 /// Open a file for writing.
88 ///
89 /// Parameter `fileURL`: the path at which to create the file
90 ///
91 /// Parameter `settings`: the format of the file to create (See `AVAudioRecorder`.) For linear PCM,
92 /// only interleaved formats are supported for the saved file, non interleaved setting will be
93 /// ignored and a warning is shown.
94 ///
95 /// Parameter `format`: the processing format to use when writing to the file.
96 ///
97 /// Parameter `interleaved`: whether to use an interleaved processing format
98 ///
99 /// Parameter `outError`: on exit, if an error occurs, a description of the error
100 ///
101 /// The file type to create can be set through the corresponding settings key. If not set, it will be
102 /// inferred from the file extension. Will overwrite a file at the specified URL if a file exists.
103 #[unsafe(method(initForWriting:settings:commonFormat:interleaved:error:_))]
104 #[unsafe(method_family = init)]
105 pub unsafe fn initForWriting_settings_commonFormat_interleaved_error(
106 this: Allocated<Self>,
107 file_url: &NSURL,
108 settings: &NSDictionary<NSString, AnyObject>,
109 format: AVAudioCommonFormat,
110 interleaved: bool,
111 ) -> Result<Retained<Self>, Retained<NSError>>;
112
113 /// Close the audio file.
114 ///
115 /// The underlying file will be closed if open.
116 ///
117 /// - It is normally unnecessary to close a file opened for reading (it will be automatically closed
118 /// when the object is released)
119 /// - It is only necessary to close a file opened for writing in order to achieve specific control over
120 /// when the file's header is updated.
121 ///
122 /// Note: Once closed, further file read or write operations will fail with kAudio_FileNotFoundError.
123 #[unsafe(method(close))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn close(&self);
126
127 #[cfg(feature = "AVAudioBuffer")]
128 /// Read an entire buffer.
129 ///
130 /// Parameter `buffer`: The buffer into which to read from the file. Its format must match the file's
131 /// processing format.
132 ///
133 /// Parameter `outError`: on exit, if an error occurs, a description of the error
134 ///
135 /// Returns: YES for success.
136 ///
137 /// Reading sequentially from framePosition, attempts to fill the buffer to its capacity. On
138 /// return, the buffer's length indicates the number of sample frames successfully read.
139 #[unsafe(method(readIntoBuffer:error:_))]
140 #[unsafe(method_family = none)]
141 pub unsafe fn readIntoBuffer_error(
142 &self,
143 buffer: &AVAudioPCMBuffer,
144 ) -> Result<(), Retained<NSError>>;
145
146 #[cfg(all(feature = "AVAudioBuffer", feature = "AVAudioTypes"))]
147 /// Read a portion of a buffer.
148 ///
149 /// Parameter `frames`: The number of frames to read.
150 ///
151 /// Parameter `buffer`: The buffer into which to read from the file. Its format must match the file's
152 /// processing format.
153 ///
154 /// Parameter `outError`: on exit, if an error occurs, a description of the error
155 ///
156 /// Returns: YES for success.
157 ///
158 /// Like `readIntoBuffer:error:`, but can be used to read fewer frames than buffer.frameCapacity.
159 #[unsafe(method(readIntoBuffer:frameCount:error:_))]
160 #[unsafe(method_family = none)]
161 pub unsafe fn readIntoBuffer_frameCount_error(
162 &self,
163 buffer: &AVAudioPCMBuffer,
164 frames: AVAudioFrameCount,
165 ) -> Result<(), Retained<NSError>>;
166
167 #[cfg(feature = "AVAudioBuffer")]
168 /// Write a buffer.
169 ///
170 /// Parameter `buffer`: The buffer from which to write to 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 /// Writes sequentially. The buffer's frameLength signifies how much of the buffer is to be written.
178 #[unsafe(method(writeFromBuffer:error:_))]
179 #[unsafe(method_family = none)]
180 pub unsafe fn writeFromBuffer_error(
181 &self,
182 buffer: &AVAudioPCMBuffer,
183 ) -> Result<(), Retained<NSError>>;
184
185 /// Whether the file is open or not.
186 #[unsafe(method(isOpen))]
187 #[unsafe(method_family = none)]
188 pub unsafe fn isOpen(&self) -> bool;
189
190 /// The URL the file is reading or writing.
191 #[unsafe(method(url))]
192 #[unsafe(method_family = none)]
193 pub unsafe fn url(&self) -> Retained<NSURL>;
194
195 #[cfg(feature = "AVAudioFormat")]
196 /// The on-disk format of the file.
197 #[unsafe(method(fileFormat))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn fileFormat(&self) -> Retained<AVAudioFormat>;
200
201 #[cfg(feature = "AVAudioFormat")]
202 /// The processing format of the file.
203 #[unsafe(method(processingFormat))]
204 #[unsafe(method_family = none)]
205 pub unsafe fn processingFormat(&self) -> Retained<AVAudioFormat>;
206
207 #[cfg(feature = "AVAudioTypes")]
208 /// The number of sample frames in the file.
209 ///
210 /// Note: this can be expensive to compute for the first time.
211 #[unsafe(method(length))]
212 #[unsafe(method_family = none)]
213 pub unsafe fn length(&self) -> AVAudioFramePosition;
214
215 #[cfg(feature = "AVAudioTypes")]
216 /// The position in the file at which the next read or write will occur.
217 ///
218 /// 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.
219 #[unsafe(method(framePosition))]
220 #[unsafe(method_family = none)]
221 pub unsafe fn framePosition(&self) -> AVAudioFramePosition;
222
223 #[cfg(feature = "AVAudioTypes")]
224 /// Setter for [`framePosition`][Self::framePosition].
225 #[unsafe(method(setFramePosition:))]
226 #[unsafe(method_family = none)]
227 pub unsafe fn setFramePosition(&self, frame_position: AVAudioFramePosition);
228 );
229}
230
231/// Methods declared on superclass `NSObject`.
232impl AVAudioFile {
233 extern_methods!(
234 #[unsafe(method(init))]
235 #[unsafe(method_family = init)]
236 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
237
238 #[unsafe(method(new))]
239 #[unsafe(method_family = new)]
240 pub unsafe fn new() -> Retained<Self>;
241 );
242}