objc2_sound_analysis/generated/SNAnalyzer.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-avf-audio")]
7use objc2_avf_audio::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13 /// Analyzes a stream of audio data and provides analysis results to the client
14 ///
15 /// SNAudioStreamAnalyzer should be used to analyze a stream of audio, represented by a sequence of audio buffers over time.
16 ///
17 /// See also [Apple's documentation](https://developer.apple.com/documentation/soundanalysis/snaudiostreamanalyzer?language=objc)
18 #[unsafe(super(NSObject))]
19 #[derive(Debug, PartialEq, Eq, Hash)]
20 pub struct SNAudioStreamAnalyzer;
21);
22
23extern_conformance!(
24 unsafe impl NSObjectProtocol for SNAudioStreamAnalyzer {}
25);
26
27impl SNAudioStreamAnalyzer {
28 extern_methods!(
29 #[cfg(feature = "objc2-avf-audio")]
30 /// Creates a new analyzer
31 ///
32 /// - Parameter format: The format of the audio stream to be analyzed. Only PCM formats are supported.
33 #[unsafe(method(initWithFormat:))]
34 #[unsafe(method_family = init)]
35 pub unsafe fn initWithFormat(
36 this: Allocated<Self>,
37 format: &AVAudioFormat,
38 ) -> Retained<Self>;
39
40 #[unsafe(method(init))]
41 #[unsafe(method_family = init)]
42 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
43
44 #[cfg(all(feature = "SNRequest", feature = "SNResult"))]
45 /// Adds a new analysis request to the analyzer
46 ///
47 /// - Parameters:
48 ///
49 /// - request: An audio analysis request to be performed on the audio stream
50 ///
51 /// - observer: The object that will receive the analysis results for the supplied request. The observer is weakly retained by the analyzer.
52 ///
53 /// - error: On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
54 ///
55 /// - Returns: YES if the request was successfully added, and NO otherwise.
56 ///
57 /// Requests can be added while analysis is in progress. If the analyzer cannot perform the requested analysis, an error will be returned. For example, an error could be returned if the request requires a stream format that doesn't match the analyzer's stream format.
58 #[unsafe(method(addRequest:withObserver:error:_))]
59 #[unsafe(method_family = none)]
60 pub unsafe fn addRequest_withObserver_error(
61 &self,
62 request: &ProtocolObject<dyn SNRequest>,
63 observer: &ProtocolObject<dyn SNResultsObserving>,
64 ) -> Result<(), Retained<NSError>>;
65
66 #[cfg(feature = "SNRequest")]
67 /// Removes an existing analysis request from the analyzer
68 /// - Parameter request: An audio analysis request to be removed
69 /// Requests can be removed while analysis is in progress. Once the removeRequest method returns, the previously registered observer will not receive any more callbacks.
70 #[unsafe(method(removeRequest:))]
71 #[unsafe(method_family = none)]
72 pub unsafe fn removeRequest(&self, request: &ProtocolObject<dyn SNRequest>);
73
74 /// Removes all requests from the analyzer
75 #[unsafe(method(removeAllRequests))]
76 #[unsafe(method_family = none)]
77 pub unsafe fn removeAllRequests(&self);
78
79 #[cfg(feature = "objc2-avf-audio")]
80 /// Provides the next buffer for analysis
81 ///
82 /// - Parameters:
83 ///
84 /// - audioBuffer: The buffer containing the audio to be processed
85 ///
86 /// - audioFramePosition: The frame position of the data in the buffer
87 ///
88 /// The framePosition should be a monotonically increasing sample timestamp. If the sample timeline is detected to be non-continuous, the analyzer's internal state may reset to account for the jump. Some types of audio analysis are performed at a fixed block size, which may differ from the buffer sizes provided for analysis. For this reason, an invocation of analyzeAudioBuffer may cause an analysis request observer to be called zero times, one time, or many times, depending on the relationship between the input buffer size, current analyzer state, and native analysis block size. Any errors produced during analysis will be provided through the request observers. This method may block as a means of indicating backpressure to the caller. These methods are not safe to call from a realtime audio context but may be called from lower priority threads (i.e. AVAudioEngine tap callback or AudioQueue callback).
89 #[unsafe(method(analyzeAudioBuffer:atAudioFramePosition:))]
90 #[unsafe(method_family = none)]
91 pub unsafe fn analyzeAudioBuffer_atAudioFramePosition(
92 &self,
93 audio_buffer: &AVAudioBuffer,
94 audio_frame_position: AVAudioFramePosition,
95 );
96
97 /// Indicates that the audio stream has ended, and no more audio buffers will be analyzed
98 ///
99 /// After this method has been called, it is invalid to provide any more audio data for analysis, and any provided buffers will be ignored. This method is useful for types of analysis that may have final results to provide upon the completion of the stream.
100 #[unsafe(method(completeAnalysis))]
101 #[unsafe(method_family = none)]
102 pub unsafe fn completeAnalysis(&self);
103 );
104}
105
106/// Methods declared on superclass `NSObject`.
107impl SNAudioStreamAnalyzer {
108 extern_methods!(
109 #[unsafe(method(new))]
110 #[unsafe(method_family = new)]
111 pub unsafe fn new() -> Retained<Self>;
112 );
113}
114
115extern_class!(
116 /// Analyzes an audio file and provides analysis results to the client
117 ///
118 /// See also [Apple's documentation](https://developer.apple.com/documentation/soundanalysis/snaudiofileanalyzer?language=objc)
119 #[unsafe(super(NSObject))]
120 #[derive(Debug, PartialEq, Eq, Hash)]
121 pub struct SNAudioFileAnalyzer;
122);
123
124extern_conformance!(
125 unsafe impl NSObjectProtocol for SNAudioFileAnalyzer {}
126);
127
128impl SNAudioFileAnalyzer {
129 extern_methods!(
130 /// Creates a new analyzer
131 ///
132 /// - Parameters:
133 ///
134 /// - url: The url for the audio file to be analyzed
135 ///
136 /// - error: On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
137 #[unsafe(method(initWithURL:error:_))]
138 #[unsafe(method_family = init)]
139 pub unsafe fn initWithURL_error(
140 this: Allocated<Self>,
141 url: &NSURL,
142 ) -> Result<Retained<Self>, Retained<NSError>>;
143
144 #[unsafe(method(init))]
145 #[unsafe(method_family = init)]
146 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
147
148 #[cfg(all(feature = "SNRequest", feature = "SNResult"))]
149 /// Adds a new analysis request to the analyzer
150 ///
151 /// - Parameters:
152 ///
153 /// - request: An audio analysis request to be performed on the audio stream
154 ///
155 /// - observer: The object that will receive the analysis results for the supplied request. The observer is weakly retained by the analyzer.
156 ///
157 /// - error On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
158 ///
159 /// - Returns: YES if the request was successfully added, and NO otherwise.
160 ///
161 /// If addRequest is called while the file is being processed, an error will be returned.
162 #[unsafe(method(addRequest:withObserver:error:_))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn addRequest_withObserver_error(
165 &self,
166 request: &ProtocolObject<dyn SNRequest>,
167 observer: &ProtocolObject<dyn SNResultsObserving>,
168 ) -> Result<(), Retained<NSError>>;
169
170 #[cfg(feature = "SNRequest")]
171 /// Removes an existing analysis request from the analyzer
172 ///
173 /// - Parameter request: An audio analysis request to be removed
174 ///
175 /// Requests can be removed while analysis is in progress. Once the removeRequest method returns, the previously registered observer will not receive any more callbacks.
176 #[unsafe(method(removeRequest:))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn removeRequest(&self, request: &ProtocolObject<dyn SNRequest>);
179
180 /// Removes all requests from the analyzer
181 #[unsafe(method(removeAllRequests))]
182 #[unsafe(method_family = none)]
183 pub unsafe fn removeAllRequests(&self);
184
185 /// Analyzes the audio file synchronously
186 ///
187 /// This function executes synchronously. Any errors produced during analysis will flow downstream to the request observers. This method may block for a long period of time, so be careful to ensure this call does not block UI or other important tasks.
188 #[unsafe(method(analyze))]
189 #[unsafe(method_family = none)]
190 pub unsafe fn analyze(&self);
191
192 #[cfg(feature = "block2")]
193 /// Analyzes the audio file asynchronously
194 ///
195 /// This function executes asynchronously, calling the completion after the entire file has completed analysis. Any errors produced during analysis will flow downstream to the request observers. If the cancelAnalysis method is called, the completionHandler will still be called, but with didReachEndOfFile set to NO.
196 #[unsafe(method(analyzeWithCompletionHandler:))]
197 #[unsafe(method_family = none)]
198 pub unsafe fn analyzeWithCompletionHandler(
199 &self,
200 completion_handler: &block2::DynBlock<dyn Fn(Bool)>,
201 );
202
203 /// Cancels any in-progress analysis of the audio file
204 ///
205 /// This function executes asynchronously, and will trigger the completion handler provided in the analyzeWithCompletionHandler method after the cancellation is complete.
206 #[unsafe(method(cancelAnalysis))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn cancelAnalysis(&self);
209 );
210}
211
212/// Methods declared on superclass `NSObject`.
213impl SNAudioFileAnalyzer {
214 extern_methods!(
215 #[unsafe(method(new))]
216 #[unsafe(method_family = new)]
217 pub unsafe fn new() -> Retained<Self>;
218 );
219}