@@ -10,7 +10,6 @@ use coreaudio::audio_unit::audio_format::LinearPcmFlags;
1010use coreaudio:: audio_unit:: render_callback:: { self , data} ;
1111use coreaudio:: sys:: * ;
1212
13- const SAMPLE_RATE : f64 = 44100.0 ;
1413
1514type S = f32 ; const SAMPLE_FORMAT : SampleFormat = SampleFormat :: F32 ;
1615// type S = i32; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I32;
@@ -21,6 +20,12 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
2120 let mut input_audio_unit = AudioUnit :: new ( coreaudio:: audio_unit:: IOType :: RemoteIO ) ?;
2221 let mut output_audio_unit = AudioUnit :: new ( coreaudio:: audio_unit:: IOType :: RemoteIO ) ?;
2322
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+
2429 // iOS doesn't let you reconfigure an "initialized" audio unit, so uninitialize them
2530 input_audio_unit. uninitialize ( ) ?;
2631 output_audio_unit. uninitialize ( ) ?;
@@ -34,7 +39,7 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
3439
3540 // Using IS_NON_INTERLEAVED everywhere because data::Interleaved is commented out / not implemented
3641 let in_stream_format = StreamFormat {
37- sample_rate : SAMPLE_RATE ,
42+ sample_rate : sample_rate ,
3843 sample_format : SAMPLE_FORMAT ,
3944 flags : format_flag | LinearPcmFlags :: IS_PACKED | LinearPcmFlags :: IS_NON_INTERLEAVED ,
4045 // 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> {
4348 } ;
4449
4550 let out_stream_format = StreamFormat {
46- sample_rate : SAMPLE_RATE ,
51+ sample_rate : sample_rate ,
4752 sample_format : SAMPLE_FORMAT ,
4853 flags : format_flag | LinearPcmFlags :: IS_PACKED | LinearPcmFlags :: IS_NON_INTERLEAVED ,
4954 // you can change this to 1
0 commit comments