So if I enable the audio expander cape, does that mean the samplerate of the main audio output also is lowered to 22050hz?

I replaced audioWrite() with analogWrite() in my code and found the audio output to be completely messed up. After diving into some example sketches I found that they use context->audioFrames when writing using audioWrite() and context->analogFrames when using analogWrite().

Now I didn't think this would be an issue as I assumed when using the audio expander the main output samplerate would also be lowered to match the audio expander output samplerate but I guess this is not the case?

After fixing this is the audio is working as to be expected.

    Ward So if I enable the audio expander cape, does that mean the samplerate of the main audio output also is lowered to 22050hz?

    No. You will still have 2 channels of audio at 44100 sample rate. The analog sample rate will depend on the number of channels, the usual way. If you inspect the content of context->audioSampleRate, context->analogSampleRate, that should rule out any doubts.

    What the audio expander settings do (if you enable them and tick the appropriate boxes in the IDE) is they enable digital DC-blocking filtering on the selected analog inputs and outputs so that they are AC-coupled and scaled between -1 and 1, just like the audio channels. See here for more details.

    Last, be aware that when writing sample-by-sample, you should use analogWriteOnce() and not analogWrite(): see here