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
41unsafe impl NSObjectProtocol for AVAudioTime {}
42
43impl AVAudioTime {
44    extern_methods!(
45        #[cfg(feature = "objc2-core-audio-types")]
46        #[unsafe(method(initWithAudioTimeStamp:sampleRate:))]
47        #[unsafe(method_family = init)]
48        pub unsafe fn initWithAudioTimeStamp_sampleRate(
49            this: Allocated<Self>,
50            ts: NonNull<AudioTimeStamp>,
51            sample_rate: c_double,
52        ) -> Retained<Self>;
53
54        #[unsafe(method(initWithHostTime:))]
55        #[unsafe(method_family = init)]
56        pub unsafe fn initWithHostTime(this: Allocated<Self>, host_time: u64) -> Retained<Self>;
57
58        #[cfg(feature = "AVAudioTypes")]
59        #[unsafe(method(initWithSampleTime:atRate:))]
60        #[unsafe(method_family = init)]
61        pub unsafe fn initWithSampleTime_atRate(
62            this: Allocated<Self>,
63            sample_time: AVAudioFramePosition,
64            sample_rate: c_double,
65        ) -> Retained<Self>;
66
67        #[cfg(feature = "AVAudioTypes")]
68        #[unsafe(method(initWithHostTime:sampleTime:atRate:))]
69        #[unsafe(method_family = init)]
70        pub unsafe fn initWithHostTime_sampleTime_atRate(
71            this: Allocated<Self>,
72            host_time: u64,
73            sample_time: AVAudioFramePosition,
74            sample_rate: c_double,
75        ) -> Retained<Self>;
76
77        #[cfg(feature = "objc2-core-audio-types")]
78        #[unsafe(method(timeWithAudioTimeStamp:sampleRate:))]
79        #[unsafe(method_family = none)]
80        pub unsafe fn timeWithAudioTimeStamp_sampleRate(
81            ts: NonNull<AudioTimeStamp>,
82            sample_rate: c_double,
83        ) -> Retained<Self>;
84
85        #[unsafe(method(timeWithHostTime:))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn timeWithHostTime(host_time: u64) -> Retained<Self>;
88
89        #[cfg(feature = "AVAudioTypes")]
90        #[unsafe(method(timeWithSampleTime:atRate:))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn timeWithSampleTime_atRate(
93            sample_time: AVAudioFramePosition,
94            sample_rate: c_double,
95        ) -> Retained<Self>;
96
97        #[cfg(feature = "AVAudioTypes")]
98        #[unsafe(method(timeWithHostTime:sampleTime:atRate:))]
99        #[unsafe(method_family = none)]
100        pub unsafe fn timeWithHostTime_sampleTime_atRate(
101            host_time: u64,
102            sample_time: AVAudioFramePosition,
103            sample_rate: c_double,
104        ) -> Retained<Self>;
105
106        /// Convert seconds to host time.
107        #[unsafe(method(hostTimeForSeconds:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn hostTimeForSeconds(seconds: NSTimeInterval) -> u64;
110
111        /// Convert host time to seconds.
112        #[unsafe(method(secondsForHostTime:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn secondsForHostTime(host_time: u64) -> NSTimeInterval;
115
116        /// Converts between host and sample time.
117        ///
118        /// Parameter `anchorTime`: An AVAudioTime with a more complete AudioTimeStamp than that of the receiver (self).
119        ///
120        /// Returns: the extrapolated time
121        ///
122        /// If anchorTime is an AVAudioTime where both host time and sample time are valid,
123        /// and self is another timestamp where only one of the two is valid, this method
124        /// returns a new AVAudioTime copied from self and where any additional valid fields provided by
125        /// the anchor are also valid.
126        ///
127        /// Note that the anchorTime must have both host and sample time valid, and self must have
128        /// sample rate and at least one of host or sample time valid. Otherwise this method returns nil.
129        ///
130        /// <pre>
131        /// // time0 has a valid audio sample representation, but no host time representation.
132        /// AVAudioTime *time0 = [AVAudioTime timeWithSampleTime: 0.0 atRate: 44100.0];
133        /// // anchor has a valid host time representation and sample time representation.
134        /// AVAudioTime *anchor = [player playerTimeForNodeTime: player.lastRenderTime];
135        /// // fill in valid host time representation
136        /// AVAudioTime *fullTime0 = [time0 extrapolateTimeFromAnchor: anchor];
137        /// </pre>
138        #[unsafe(method(extrapolateTimeFromAnchor:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn extrapolateTimeFromAnchor(
141            &self,
142            anchor_time: &AVAudioTime,
143        ) -> Option<Retained<AVAudioTime>>;
144
145        /// Whether the hostTime property is valid.
146        #[unsafe(method(isHostTimeValid))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn isHostTimeValid(&self) -> bool;
149
150        /// The host time.
151        #[unsafe(method(hostTime))]
152        #[unsafe(method_family = none)]
153        pub unsafe fn hostTime(&self) -> u64;
154
155        /// Whether the sampleTime and sampleRate properties are valid.
156        #[unsafe(method(isSampleTimeValid))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn isSampleTimeValid(&self) -> bool;
159
160        #[cfg(feature = "AVAudioTypes")]
161        /// The time as a number of audio samples, as tracked by the current audio device.
162        #[unsafe(method(sampleTime))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn sampleTime(&self) -> AVAudioFramePosition;
165
166        /// The sample rate at which sampleTime is being expressed.
167        #[unsafe(method(sampleRate))]
168        #[unsafe(method_family = none)]
169        pub unsafe fn sampleRate(&self) -> c_double;
170
171        #[cfg(feature = "objc2-core-audio-types")]
172        /// The time expressed as an AudioTimeStamp structure.
173        ///
174        /// This may be useful for compatibility with lower-level CoreAudio and AudioToolbox API's.
175        #[unsafe(method(audioTimeStamp))]
176        #[unsafe(method_family = none)]
177        pub unsafe fn audioTimeStamp(&self) -> AudioTimeStamp;
178    );
179}
180
181/// Methods declared on superclass `NSObject`.
182impl AVAudioTime {
183    extern_methods!(
184        #[unsafe(method(init))]
185        #[unsafe(method_family = init)]
186        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
187
188        #[unsafe(method(new))]
189        #[unsafe(method_family = new)]
190        pub unsafe fn new() -> Retained<Self>;
191    );
192}