Detection of connection of loudspeakers or headphones to amplifiers