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