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