An algorithm underlying directional hearing in fish