@@ -10,7 +10,6 @@ use coreaudio::audio_unit::audio_format::LinearPcmFlags;
10
10
use coreaudio:: audio_unit:: render_callback:: { self , data} ;
11
11
use coreaudio:: sys:: * ;
12
12
13
- const SAMPLE_RATE : f64 = 44100.0 ;
14
13
15
14
type S = f32 ; const SAMPLE_FORMAT : SampleFormat = SampleFormat :: F32 ;
16
15
// type S = i32; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I32;
@@ -21,6 +20,12 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
21
20
let mut input_audio_unit = AudioUnit :: new ( coreaudio:: audio_unit:: IOType :: RemoteIO ) ?;
22
21
let mut output_audio_unit = AudioUnit :: new ( coreaudio:: audio_unit:: IOType :: RemoteIO ) ?;
23
22
23
+ // Read device sample rate off the output stream
24
+ let id = kAudioUnitProperty_StreamFormat;
25
+ let asbd: AudioStreamBasicDescription =
26
+ output_audio_unit. get_property ( id, Scope :: Output , Element :: Output ) ?;
27
+ let sample_rate = asbd. mSampleRate ;
28
+
24
29
// iOS doesn't let you reconfigure an "initialized" audio unit, so uninitialize them
25
30
input_audio_unit. uninitialize ( ) ?;
26
31
output_audio_unit. uninitialize ( ) ?;
@@ -34,7 +39,7 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
34
39
35
40
// Using IS_NON_INTERLEAVED everywhere because data::Interleaved is commented out / not implemented
36
41
let in_stream_format = StreamFormat {
37
- sample_rate : SAMPLE_RATE ,
42
+ sample_rate : sample_rate ,
38
43
sample_format : SAMPLE_FORMAT ,
39
44
flags : format_flag | LinearPcmFlags :: IS_PACKED | LinearPcmFlags :: IS_NON_INTERLEAVED ,
40
45
// audio_unit.set_input_callback is hardcoded to 1 buffer, and when using non_interleaved
@@ -43,7 +48,7 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
43
48
} ;
44
49
45
50
let out_stream_format = StreamFormat {
46
- sample_rate : SAMPLE_RATE ,
51
+ sample_rate : sample_rate ,
47
52
sample_format : SAMPLE_FORMAT ,
48
53
flags : format_flag | LinearPcmFlags :: IS_PACKED | LinearPcmFlags :: IS_NON_INTERLEAVED ,
49
54
// you can change this to 1
0 commit comments