It keeps me awake:
I have an OS X audio application that should respond if the user changes the current sample rate of the device.
To do this, I register a callback for both input and output devices on 'kAudioDevicePropertyNominalSampleRate.
So, if one of the devices changes the sampling rate I get a callback and set a new sampling rate on devices with "AudioObjectSetPropertyData" and "kAudioDevicePropertyNominalSampleRate" as a selector.
The following steps were mentioned on the Apple mailing list, and I followed them:
- stop AudioUnit and AUGraph input, which consists of a mixer and AudioUnit output
- uninitalize them both.
- check the number of nodes, go over them and use AUGraphDisconnectNodeInput to disconnect the mixer from the output
- now set a new sampling rate in the output area of ββthe input block
- and in the input and output area on the mixing console
- connect the node mixer to the output
- update schedule
- input and schedule
- start of input and schedule
The Render and Output callbacks start again, but now the sound is distorted. I believe the input callback handler is responsible for the signal, but I'm not sure.
What did I forget? As far as I know, the sampling rate does not affect the size of the buffer. If I start my application with a different sampling rate, everything will be fine, this change will lead to a distortion of the signal.
I am viewing the stream format (kAudioUnitProperty_StreamFormat) before and after. Everything remains unchanged, except for the sampling rate, which, of course, changes to a new value.
As I said, I think this is an input callback that needs to be changed. Should I notify the callback that more samples are required? I checked the callbacks and buffer sizes with 44k and 48k, and nothing changed.
I wrote a small test application, so if you want me to provide the code, I can show you.
Edit: I recorded a distorted sound (sine) and looked at it in Audacity.
I found that after every 495 samples, the sound drops another 17 samples. I think you see where this happens: 495 samples + 17 samples = 512 samples. What is the buffer size for my devices.
But I still don't know what I can do with this finding. I checked my input and output handlers and their access to RingBuffer (I use a fixed version of CARingBuffer)
Both save and retrieve 512 frames, so nothing is missing here ...
source share