objc2_avf_audio/generated/
AVAudioTime.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-core-audio-types")]
7use objc2_core_audio_types::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13    /// Represent a moment in time.
14    ///
15    /// AVAudioTime is used in AVAudioEngine to represent time. Instances are immutable.
16    ///
17    /// A single moment in time may be represented in two different ways:
18    /// 1. mach_absolute_time(), the system's basic clock. Commonly referred to as "host time."
19    /// 2. audio samples at a particular sample rate
20    ///
21    /// A single AVAudioTime instance may contain either or both representations; it might
22    /// represent only a sample time, only a host time, or both.
23    ///
24    /// Rationale for using host time:
25    /// [a] internally we are using AudioTimeStamp, which uses host time, and it seems silly to divide
26    /// [b] it is consistent with a standard system timing service
27    /// [c] we do provide conveniences to convert between host ticks and seconds (host time divided by
28    /// frequency) so client code wanting to do what should be straightforward time computations can at
29    /// least not be cluttered by ugly multiplications and divisions by the host clock frequency.
30    ///
31    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiotime?language=objc)
32    #[unsafe(super(NSObject))]
33    #[derive(Debug, PartialEq, Eq, Hash)]
34    pub struct AVAudioTime;
35);
36
37unsafe impl Send for AVAudioTime {}
38
39unsafe impl Sync for AVAudioTime {}
40
41extern_conformance!(
42    unsafe impl NSObjectProtocol for AVAudioTime {}
43);
44
45impl AVAudioTime {
46    extern_methods!(
47        #[cfg(feature = "objc2-core-audio-types")]
48        /// # Safety
49        ///
50        /// `ts` must be a valid pointer.
51        #[unsafe(method(initWithAudioTimeStamp:sampleRate:))]
52        #[unsafe(method_family = init)]
53        pub unsafe fn initWithAudioTimeStamp_sampleRate(
54            this: Allocated<Self>,
55            ts: NonNull<AudioTimeStamp>,
56            sample_rate: c_double,
57        ) -> Retained<Self>;
58
59        #[unsafe(method(initWithHostTime:))]
60        #[unsafe(method_family = init)]
61        pub unsafe fn initWithHostTime(this: Allocated<Self>, host_time: u64) -> Retained<Self>;
62
63        #[cfg(feature = "AVAudioTypes")]
64        #[unsafe(method(initWithSampleTime:atRate:))]
65        #[unsafe(method_family = init)]
66        pub unsafe fn initWithSampleTime_atRate(
67            this: Allocated<Self>,
68            sample_time: AVAudioFramePosition,
69            sample_rate: c_double,
70        ) -> Retained<Self>;
71
72        #[cfg(feature = "AVAudioTypes")]
73        #[unsafe(method(initWithHostTime:sampleTime:atRate:))]
74        #[unsafe(method_family = init)]
75        pub unsafe fn initWithHostTime_sampleTime_atRate(
76            this: Allocated<Self>,
77            host_time: u64,
78            sample_time: AVAudioFramePosition,
79            sample_rate: c_double,
80        ) -> Retained<Self>;
81
82        #[cfg(feature = "objc2-core-audio-types")]
83        /// # Safety
84        ///
85        /// `ts` must be a valid pointer.
86        #[unsafe(method(timeWithAudioTimeStamp:sampleRate:))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn timeWithAudioTimeStamp_sampleRate(
89            ts: NonNull<AudioTimeStamp>,
90            sample_rate: c_double,
91        ) -> Retained<Self>;
92
93        #[unsafe(method(timeWithHostTime:))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn timeWithHostTime(host_time: u64) -> Retained<Self>;
96
97        #[cfg(feature = "AVAudioTypes")]
98        #[unsafe(method(timeWithSampleTime:atRate:))]
99        #[unsafe(method_family = none)]
100        pub unsafe fn timeWithSampleTime_atRate(
101            sample_time: AVAudioFramePosition,
102            sample_rate: c_double,
103        ) -> Retained<Self>;
104
105        #[cfg(feature = "AVAudioTypes")]
106        #[unsafe(method(timeWithHostTime:sampleTime:atRate:))]
107        #[unsafe(method_family = none)]
108        pub unsafe fn timeWithHostTime_sampleTime_atRate(
109            host_time: u64,
110            sample_time: AVAudioFramePosition,
111            sample_rate: c_double,
112        ) -> Retained<Self>;
113
114        /// Convert seconds to host time.
115        #[unsafe(method(hostTimeForSeconds:))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn hostTimeForSeconds(seconds: NSTimeInterval) -> u64;
118
119        /// Convert host time to seconds.
120        #[unsafe(method(secondsForHostTime:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn secondsForHostTime(host_time: u64) -> NSTimeInterval;
123
124        /// Converts between host and sample time.
125        ///
126        /// Parameter `anchorTime`: An AVAudioTime with a more complete AudioTimeStamp than that of the receiver (self).
127        ///
128        /// Returns: the extrapolated time
129        ///
130        /// If anchorTime is an AVAudioTime where both host time and sample time are valid,
131        /// and self is another timestamp where only one of the two is valid, this method
132        /// returns a new AVAudioTime copied from self and where any additional valid fields provided by
133        /// the anchor are also valid.
134        ///
135        /// Note that the anchorTime must have both host and sample time valid, and self must have
136        /// sample rate and at least one of host or sample time valid. Otherwise this method returns nil.
137        ///
138        /// <pre>
139        /// // time0 has a valid audio sample representation, but no host time representation.
140        /// AVAudioTime *time0 = [AVAudioTime timeWithSampleTime: 0.0 atRate: 44100.0];
141        /// // anchor has a valid host time representation and sample time representation.
142        /// AVAudioTime *anchor = [player playerTimeForNodeTime: player.lastRenderTime];
143        /// // fill in valid host time representation
144        /// AVAudioTime *fullTime0 = [time0 extrapolateTimeFromAnchor: anchor];
145        /// </pre>
146        #[unsafe(method(extrapolateTimeFromAnchor:))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn extrapolateTimeFromAnchor(
149            &self,
150            anchor_time: &AVAudioTime,
151        ) -> Option<Retained<AVAudioTime>>;
152
153        /// Whether the hostTime property is valid.
154        ///
155        /// This property is not atomic.
156        ///
157        /// # Safety
158        ///
159        /// This might not be thread-safe.
160        #[unsafe(method(isHostTimeValid))]
161        #[unsafe(method_family = none)]
162        pub unsafe fn isHostTimeValid(&self) -> bool;
163
164        /// The host time.
165        ///
166        /// This property is not atomic.
167        ///
168        /// # Safety
169        ///
170        /// This might not be thread-safe.
171        #[unsafe(method(hostTime))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn hostTime(&self) -> u64;
174
175        /// Whether the sampleTime and sampleRate properties are valid.
176        ///
177        /// This property is not atomic.
178        ///
179        /// # Safety
180        ///
181        /// This might not be thread-safe.
182        #[unsafe(method(isSampleTimeValid))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn isSampleTimeValid(&self) -> bool;
185
186        #[cfg(feature = "AVAudioTypes")]
187        /// The time as a number of audio samples, as tracked by the current audio device.
188        ///
189        /// This property is not atomic.
190        ///
191        /// # Safety
192        ///
193        /// This might not be thread-safe.
194        #[unsafe(method(sampleTime))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn sampleTime(&self) -> AVAudioFramePosition;
197
198        /// The sample rate at which sampleTime is being expressed.
199        ///
200        /// This property is not atomic.
201        ///
202        /// # Safety
203        ///
204        /// This might not be thread-safe.
205        #[unsafe(method(sampleRate))]
206        #[unsafe(method_family = none)]
207        pub unsafe fn sampleRate(&self) -> c_double;
208
209        #[cfg(feature = "objc2-core-audio-types")]
210        /// The time expressed as an AudioTimeStamp structure.
211        ///
212        /// This may be useful for compatibility with lower-level CoreAudio and AudioToolbox API's.
213        ///
214        /// This property is not atomic.
215        ///
216        /// # Safety
217        ///
218        /// This might not be thread-safe.
219        #[unsafe(method(audioTimeStamp))]
220        #[unsafe(method_family = none)]
221        pub unsafe fn audioTimeStamp(&self) -> AudioTimeStamp;
222    );
223}
224
225/// Methods declared on superclass `NSObject`.
226impl AVAudioTime {
227    extern_methods!(
228        #[unsafe(method(init))]
229        #[unsafe(method_family = init)]
230        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
231
232        #[unsafe(method(new))]
233        #[unsafe(method_family = new)]
234        pub unsafe fn new() -> Retained<Self>;
235    );
236}