Functions on the commuting stack via Langlands duality