Large-angle production of charged pions by 3-12.9 GeV/c protons on beryllium, aluminium and lead targets