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